view 1wire-config.h @ 85:18b154c447bb

Add note about 1-wire wiring
author Daniel O'Connor <darius@dons.net.au>
date Thu, 12 Mar 2015 23:22:11 +1030
parents 38869c474104
children 345a42f6151b
line wrap: on
line source

/*
 * Example configuration header for 1-wire bus code.
 *
 * This is the user servicable stuff - how to do delays and how to
 * frob the IO pins.
 *
 * Copyright (c) 2009
 *      Daniel O'Connor <darius@dons.net.au>.  All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED.  IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 */

/*
 * The configuration described here has the 1-wire IO on GPIOE3,
 * with no pull down, nor VPP
 */

#include "stm32f10x.h" /* GPIO* */
#include "delay.h"

/* Fudge AVR stuff for ARM */
#define PROGMEM
#define PSTR(x)			x
#define pgm_read_byte(x)	*(x)

/* Init bus */
#define OWBUSINIT()

/* Set the port up to allow reading from the 1 wire bus */
#define OWSETREAD() 		do {			\
    GPIO_InitTypeDef GPIO_InitStructure;		\
    							\
    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3;		\
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;	\
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; \
    GPIO_Init(GPIOE, &GPIO_InitStructure);		\
} while (0)


/* Read the 1-wire bus, non-inverting logic */
#define OWREADBUS()		(GPIO_ReadInputDataBit(GPIOE, GPIO_Pin_3) ? 1 : 0)

/* Set the 1-wire bus to 0
 */
#define OWSETBUSLOW()		do {			\
    GPIO_InitTypeDef GPIO_InitStructure;		\
    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3;		\
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;	\
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;	\
    GPIO_Init(GPIOE, &GPIO_InitStructure);		\
    GPIO_ResetBits(GPIOE, GPIO_Pin_3);			\
} while (0)

/* Set the 1-wire bus to 1
 * Change to input and let the pull up do its job
 */
#define OWSETBUSHIGH()		do {			\
    GPIO_InitTypeDef GPIO_InitStructure;		\
    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3;		\
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;	\
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; \
    GPIO_Init(GPIOE, &GPIO_InitStructure);		\
} while (0)

#define OWDELAY_A delay(6)					/* 6 usec */
#define OWDELAY_B delay(65)					/* 64 usec */
#define OWDELAY_C delay(60)					/* 60 usec */
#define OWDELAY_D delay(10)					/* 10 usec */
#define OWDELAY_E delay(9)					/* 9 usec */
#define OWDELAY_F delay(55)					/* 55 usec */
#define OWDELAY_G						/* 0 usec */
#define OWDELAY_H delay(480)					/* 480 usec */
#define OWDELAY_I delay(70)					/* 70 usec */
#define OWDELAY_J delay(410)					/* 410 usec */

//#define OW_DEBUG
#ifdef OW_DEBUG
#define OWPUTS(x)		puts(x)
#define OWPUTSP(x)		puts(x)
#define OWPRINTFP(fmt, ...)	printf(fmt, ## __VA_ARGS__)
#else
#define OWPUTS(x)
#define OWPUTSP(x)
#define OWPRINTFP(fmt, ...)
#endif