Programming: Fixing the UART/USART Baud Rate Formula in the Library

The section of the UART/USART initialization for determining the baud rate had an error. The error pertained to first not containing the product of 16 and baud so the F_CPU is not divided by the 16 before the 16 is multiplied by the baud. The second problem was that the letter 'L' was not added after the 16. The L, in the C programming language informs the compiler that the 16 is a long integer.



uint16_t UBBRValue = lrint(( F_CPU / (16L * baud) ) - 1);
Back to blog

Leave a comment

Please note, comments need to be approved before they are published.