Custom Uart baud rate 117600

Hello,

We are using UART channel to communicate with the other MCU, 

It has a specific clock to save power but its only option is 117600 baud rate which corresponds to 2% deviation of 115200.

Is there any way to configure 117600 and make it work?

Thanks

  • Just in case you didn't use rounding from my old post response you referenced, this works with rounding included on the nRF52840 (you may already be using this)

    // Baudrate generator for the UART is the top 20 bits of a 32-bit field; add in rounding 0.5 ls bit
     uint32_t CalculatedRegisterValue;
     uint64_t SystemClock = 16000000ULL;    // Typically 16MHz
     uint64_t MagicScaler = 32; // Preserves bits on divisions, shift 32 bits
     CalculatedRegisterValue = (uint32_t)((((((uint64_t)RequiredBaudRate << MagicScaler)) + (SystemClock>>1)) / SystemClock) + 0x800) & 0xFFFFF000;

    As an aside, should you need a really fast serial port transmit, the uart Tx works up to 8MHz although only 1MHz on uart receive. This is useful if using a high-speed external flash memory dump via the uart

  • Hi hmolesworth,

    Thank you for the extra tips. Do you mind sharing some brief background behind how you came up with the formula? It might be obvious to you, but perhaps readers with less IC/hardware knowledge like me can't understand it fully.

  • The background is actually similar to your case; a serial sensor was using 921600 baud but was unreliable when connected to a nRF52832 so I checked the bit rate with an accurate meter and found that it was indeed incorrect - by quite a lot. Changing the baud register indicated that altering some lower-order bits had no effect, although not easy to see on a 'scope or even an accurate meter at 921600 baud. The trick is to select a very low baud rate (less than 1200, actual value unimportant) and capture a single character transmission so that the lower order register bits make a discernable difference on a 'scope when the bits are changed. This allows finding all the bits in the baud register which have no effect, hence the baud register only has 20 useful bits. Mapping the setting at a low baud rate and knowing the peripheral uses the 16MHz clock allowed the determination of the formula. Some uarts use as few as 3 bits to determine start bit validity, others use 8 or 16 bits. That determines the Rx clock prescaler as each Rx bit has 3, 8 or 16 clock ticks respectively (not applicable to the Tx).

Related