> This is the code I have:
> UBRRL = (XTAL / (16L * BAUDRATE)) - 1; //set baud rate;
Does that work?
Not in all cases. I have found this to work in all cases that I've tried:
/*
* #define UART_BAUD_SELECT (F_CPU/(UART_BAUD_RATE*16L)-1)
*
* When doing integer divide it is usually better to round to the nearest
* integer, rather than to the lowest (which the above _expression_ does).
*
* Add 0.5 (i.e. half the value of the denominator)
* to the numerator before the division. This can be achieved in the
* following way:
*
* #define UART_BAUD_SELECT ((F_CPU + UART_BAUD_RATE * 8L) /\
* (UART_BAUD_RATE * 16L) - 1)
* - Neil Johnson AVR-GCC List
*/
#define UART_BAUD_CALCULATE(UART_BAUD_RATE) ((XTAL_FREQ + UART_BAUD_RATE * 8L) / (UART_BAUD_RATE * 16L) - 1)