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
Hi Bengt,
That specific value got me a bit puzzled. I had a quick chat with a HW-designer, and he assured me that the baudrate generator for the UART is actually 20 bits, so rounding procedure is required.
As far as I see, the 921K600 baud definition in nrf51_bitfields.h is incorrect. I will input a bug regarding this item. I see that this define is removed from our reference manual, so it's likely a glitch that it's still defined in the header file.
I will also push for the calculation to be inserted into our documentation.
BR Håkon
Hi Bengt,
That specific value got me a bit puzzled. I had a quick chat with a HW-designer, and he assured me that the baudrate generator for the UART is actually 20 bits, so rounding procedure is required.
As far as I see, the 921K600 baud definition in nrf51_bitfields.h is incorrect. I will input a bug regarding this item. I see that this define is removed from our reference manual, so it's likely a glitch that it's still defined in the header file.
I will also push for the calculation to be inserted into our documentation.
BR Håkon