From 820dd13d2170852441467fdf6d7f501fea7f0856 Mon Sep 17 00:00:00 2001 From: Jonas Gunz Date: Sat, 21 Feb 2015 13:35:30 +0100 Subject: UART Bug FIXED! Thanks to Luca :D --- Keithley179.c | 23 +++++++---------------- 1 file changed, 7 insertions(+), 16 deletions(-) diff --git a/Keithley179.c b/Keithley179.c index 4205c6f..79bc149 100644 --- a/Keithley179.c +++ b/Keithley179.c @@ -3,18 +3,12 @@ * Designed for the Keithley 179 True RMS Multimeter */ - -//#ifndef F_CPU #define F_CPU 4000000UL //4MHz -//#endif +#define USART_UART_BAUDRATE 9600 #include #include -#define UART_BAUDRATE 960 - -#define baudrate ((F_CPU / UART_BAUDRATE * 16) - 1) - //Locations of ADC Outups (ICL71c03) #define b1 PC0 #define b2 PC1 @@ -109,8 +103,8 @@ int main(void) //INIT UART Interface UART_Init(); - //UART_Send("Hello World!"); - UART_Putc('A'); + + UART_Send("Hello World!"); //main loop while(1) { @@ -148,7 +142,7 @@ int main(void) UART_Send(out); //Handle UART - //UART_Handle(); //Not Used + UART_Handle(); //Reset Buffer for(int i = 0; i < 5;i++) @@ -165,12 +159,10 @@ void UART_Init() { if(UART_isInit == 0) { - //Calculate Value for Register - //uint16_t baudrate = (F_CPU / (UART_BAUDRATE * 16)) - 1; + uint16_t baudrate = (((F_CPU / (USART_UART_BAUDRATE * 16UL))) - 1); - //Set Baudrate - UBRRL = baudrate; UBRRH = (baudrate >> 8); + UBRRL = (baudrate & 0xFF); UCSRB |= (1<