/* This file has been prepared for Doxygen automatic documentation generation.*/ /*! \file ********************************************************************* * * \brief * This is the header file for the single-wire software UART. * * The file contains definitions and macros for the single-wire software * UART. If a different microcontroller than the ATmega32 is used, this * file needs to be changed. Port and baud rate settings may also be * changed in this file. * * \par Application note: * AVR274: Single-wire Software UART * * \par Documentation * For comprehensive code documentation, supported compilers, compiler * settings and supported devices see readme.html * * \author * Atmel Corporation: http://www.atmel.com \n * Support email: avr@atmel.com * * $Name: $ * $Revision: 1364 $ * $RCSfile: single_wire_UART.h,v $ * $Date: 2007-02-08 14:13:02 +0100 (to, 08 feb 2007) $ \n ******************************************************************************/ #include "stdint.h" //Integer types. #ifndef FALSE #define FALSE 0 #define TRUE !FALSE #endif // Baud rate settings (WAIT_ONE - PRESCALER): // Baud Rate 1MHz 2Mhz 4MHz 8MHz // 4800 207 - 1 51 - 8 103 - 8 (207 - 8) // 9600 103 - 1 207 - 1 51 - 8 103 - 8 // 19200 NA 103 - 1 207 - 1 51 - 8 // 28800 NA NA 138 - 1 34 - 8 // 38400 NA NA 103 - 1 207 - 1 // Please note that the UART consumes about all CPU resources when WAIT_ONE*PRESCALER<100. /* Communication parameters. The WAIT_ONE definiton has to be changed according to equation 2-1 in the application note. */ #define WAIT_ONE 103 //!< Half bit period compare setting. See the application note for calculation of this value. Make sure timer prescaler is set to the intended value. #define PRESCALER 1 //!< Prescaler setting. Must be set according to the baud rate setting. /* Port and pin settings. */ #define SW_UART_PIN_NUMBER 2 //!< Set pin number for communication. #define SW_UART_PORT PORTD //!< Set port for communication. #define SW_UART_PIN PIND //!< Set pin for communication. #define SW_UART_DDR DDRD //!< Data direction register. Not available for high voltage ports. #define TRANSMIT_DELAY 70 //!< Cycles from the start bit is sent (from UART_transmit) to the timer is started plus cycles in the timer interrupt before first data bit is sent. #define RECEIVE_DELAY 76 //!< Cycles from the start bit is detected to the timer is started plus cycles in timer interrupt before first data bit is received. #define WAIT_ONEHALF (WAIT_ONE + WAIT_ONE/2) #define TIMER_PRESCALER_CONTROL_REGISTER TCCR0 //!< Define the timer control register according to the timer used for the UART. #if (PRESCALER == 1) #define START_UART_TIMER() (TIMER_PRESCALER_CONTROL_REGISTER |= (1< 255) || ((WAIT_ONE) > 255)) #error WAIT_ONE is set too high. Try to increase prescaler or use a higher baud rate. #endif #if ( (WAIT_ONE) < (100/PRESCALER)) #error A too high baud rate is used. Please check the PRESCALER and WAIT_ONE setting. #endif /* Pin macros. */ #define INITIALIZE_UART_PIN() ( SW_UART_PORT &= ~(1<