Hello,

I have a question about the baud rate calculation on Arduino Leonardo.

In the data sheet, the formula for UBRR value in normal mode is:

UBRRn = ( Fosc / 16 / BAUD ) - 1

But in HardwareSerial.cpp, the formula is the following:

UBBRn = (( F_CPU / 8 / BAUD ) - 1) / 2

And it gave some (little) differences. For example, if the F_CPU is 16MHz, for 57600Bauds, first will gave 16.3666, so nearest value would be 16. The second formula would gave 16.86, nearest value would be 17.

So why the formula inside the code is not the formula from the datasheet? Is it because we want to round down the value all the time? And if yes, why? Is it not better to use the nearest value possible?

Thank you