AVR Baud rate calculation is incorrect
Posted: Fri Feb 03, 2012 2:58 am
It needs to be done in floating point, and rounded, not truncated. Here's what it is currently (in os/hal/platforms/AVR/serial_lld.h):
and here's what I'm using:
Code: Select all
/**
* @brief Macro for baud rate computation.
* @note Make sure the final baud rate is within tolerance.
*/
#define UBRR(b) (((F_CPU / b) >> 4) - 1)
and here's what I'm using:
Code: Select all
/**
* @brief Macro for baud rate computation.
* @note Make sure the final baud rate is within tolerance.
*/
#define UBRR(b) ((((double) F_CPU / (double) b) / 16.0) - 0.5)
/**
* @brief Macro for baud rate computation when U2Xn == 1.
* @note Make sure the final baud rate is within tolerance.
*/
#define UBRR2(b) ((((double) F_CPU / (double) b) / 8.0) - 0.5)