What is the formula for calculation of values for the UART BAUDRATE register from bit rates?
What is the formula for calculation of values for the UART BAUDRATE register from bit rates?
Hi Bengt,
note: this formula is simplified and may differ from the actual baudrate measurement
The formula is: Baudrate = desired baudrate * 2^32 / 16000000
Example: Baudrate of 31250 should then be 8388608 decimal = 0x800000.
Note that you will have to round the number afterwards: rounded_value = (value + 0x800) & 0xFFFFF000
Since the baudrate generator will be sourced by the 16 M (Either RC or XOSC, depending on your configuration), then your error rate will be ~equal to the overall drift of the system clock and the accuracy of the baudrate generator towards your target baudrate.
Other way around: Check out this define in nrf51_bitfields.h line 5702:
UART_BAUDRATE_BAUDRATE_Baud115200 (0x01D7E000UL) /*!< 115200 baud. */
The actual baudrate set with the above define is:
baudrate_reg_val * 16M / 2^32 = 115203.86 baud.
Best regards Håkon
BTW, why the heavy rounding? 'nrf51_bitfields.h' have a value for 921600bps that is 0x0EBEDFA4UL. By rounding this gets 0x0EBEE000. Does this imply the the baud rate counter is not 32-bit but mere 20-bit?
BTW, why the heavy rounding? 'nrf51_bitfields.h' have a value for 921600bps that is 0x0EBEDFA4UL. By rounding this gets 0x0EBEE000. Does this imply the the baud rate counter is not 32-bit but mere 20-bit?