I am working on a code for AT90CAN128 with USART functionality. XTAL frequency is 8MHz and the desired Baudrate is 9600 Baud.
I am just curious - if I write:
uint16_t ubrr = (uint16_t) ((uint32_t) F_CPU/(16*UART_BAUDRATE) - 1);
like found somewhere on the net, I get a Baudrate of 10.
If I simply write ubrr=51, i.e. the result from a calculator using the equation above, suddenly it starts working like it should with speed of around 9600 Baud.
What is wrong with the first definition?
In config.h it is written:
#define FOSC 8000 // 8.000 MHz External cristal #define F_CPU (FOSC*1000) // Need for AVR GCC #define USE_UART BOTH_UART #define UART_BAUDRATE 9600