/* Giacomo Ortona This program is running on the ATMEL AT90CAN128 and does the following: -initialize the USART0 register allowing tx and rx of data -depending on input data received by the USART0 can: - read the ID and the the temperature from all the devices connected until a maximum number (defined as 40 rigth now) and send those data as string through USART -set the higher and lower temperature limit for the issuing of an alarm flag -read if there is any device which has an alarm flag condition */ /* $Id: tempsens2.c,v 1.33 2006/09/22 10:40:08 giacomo Exp $ $Source: /home/giacomo/cvsroot/hadtempsens/tempsens2.c,v $ $Header: /home/giacomo/cvsroot/hadtempsens/tempsens2.c,v 1.33 2006/09/22 10:40:08 giacomo Exp $ */ #include #include #include #include #include #include #include #include #include #include #include "OWIDeviceSpecific.h" #include "OWIHighLevelFunctions.h" #include "OWIBitFunctions.h" #include #define BV(x) (1< baud 64 error 0,2% * 9600 baud=> baud 32 error -1,4%, too high * 38400baud=> baud 7 working * 57600baud=> baud 4 not working *115200baud=> baud 2 */ int break_point(int error_code, uint8_t *s) { int i; uint8_t *str; i = error_code; str = s; _delay_ms(10); return 1; } /* *this function initialize the USART 0 register needed to allow the at90can128 *USART transmissions */ void USART0_Init (unsigned int baud){ //no tx are possible when the inizialization is going on. //if is possible, use TXC0 flag. //interruption should be disabled (cli()) uint8_t intstate = SREG; cli(); /*the TXC flag bit is set 1 when the entire frame in the Transmit Shift Register has been shifted out and there are no new data currently present in the transmit buffer*/ while(0<>8); UBRR0L = (uint8_t)(baud); /* set frame format: I wil set it now as 8 bits, no parity 1 stop bit*/ UCSR0C = (0<>8); UBRR1L = (uint8_t)(baud); /* set frame format: I wil set it now as 8 bits, no parity 1 stop bit*/ UCSR1C = (0<