<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://devzone.nordicsemi.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Technical question regarding UART baud rate generator (BAUDRATE register, offset 0x524)</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/43280/technical-question-regarding-uart-baud-rate-generator-baudrate-register-offset-0x524</link><description>nRF52832 Product Specification V1.4, page 344 lists predefined baud rates only. 
 Is it possible to use other values for custom baud rate, and if so, what is the relationship between the Value and the actual generated baud rate?</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Sat, 20 Dec 2025 03:03:14 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/43280/technical-question-regarding-uart-baud-rate-generator-baudrate-register-offset-0x524" /><item><title>RE: Technical question regarding UART baud rate generator (BAUDRATE register, offset 0x524)</title><link>https://devzone.nordicsemi.com/thread/557477?ContentTypeID=1</link><pubDate>Sat, 20 Dec 2025 03:03:14 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:2096b6ef-90c7-4d18-a112-e03bc7158494</guid><dc:creator>haoren1101</dc:creator><description>&lt;p&gt;Hi, Tim. In the &amp;quot;nrf52832_uarte_baud_rates.txt&amp;quot;, could you please explain how the corresponding table was calculated or from which technical document it was obtained?&lt;/p&gt;
&lt;p&gt;Thank you!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Technical question regarding UART baud rate generator (BAUDRATE register, offset 0x524)</title><link>https://devzone.nordicsemi.com/thread/557461?ContentTypeID=1</link><pubDate>Fri, 19 Dec 2025 16:07:11 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:ba81fcb4-d80e-4a83-90e9-2be929825b4e</guid><dc:creator>hmolesworth</dc:creator><description>&lt;p&gt;That I don&amp;#39;t know; maybe ask Tim directly. The code I provide can be used to generate a similar table if you want to check for differences.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Technical question regarding UART baud rate generator (BAUDRATE register, offset 0x524)</title><link>https://devzone.nordicsemi.com/thread/557400?ContentTypeID=1</link><pubDate>Fri, 19 Dec 2025 07:46:22 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:5be5d778-ce5f-4bcc-a2b7-f8339d4ab457</guid><dc:creator>haoren1101</dc:creator><description>&lt;p&gt;Thank you for your reply. I&amp;#39;m not sure if we are referring to the same table. What I&amp;#39;m referring to is how the data in the &amp;quot;nrf52832_uarte_baud_rates.txt&amp;quot; document was generated. The file &amp;quot;nrf52832_uarte_baud_rates.txt&amp;quot; was previously provided by Tim Schuerewegen in this post.&lt;/p&gt;
&lt;p&gt;Thank you!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Technical question regarding UART baud rate generator (BAUDRATE register, offset 0x524)</title><link>https://devzone.nordicsemi.com/thread/557388?ContentTypeID=1</link><pubDate>Fri, 19 Dec 2025 02:21:04 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b5992d86-68f1-4eb0-8fb1-2e28069d7114</guid><dc:creator>hmolesworth</dc:creator><description>&lt;p&gt;No document, I&amp;#39;m afraid, but here is the code I wrote to generate the table.&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;#define RESULT_STRING_LENGTH 3   // &amp;quot;Yes&amp;quot; or &amp;quot;  -&amp;quot;

typedef struct {
   uint32_t QuotedRegisterValue;
   uint32_t RequiredBaudRate;
   uint32_t QuotedActualBaudRate;
   uint32_t CalculatedRegisterValue;
   uint32_t CalculatedActualBaudRate;
   char     DoesRegisterMatch[RESULT_STRING_LENGTH];
} BaudCheck_t;

// Quoted values from nRF52832 v1.4 datasheet - 16 correct, 10 incorrect
static BaudCheck_t BaudCheck[] = {
//  -------Documentation---------   -------Calculated---------
//  Register    Required   Actual    Register    Actual    Ok?      Index
//  ==========  ========   ======   ==========   ======   ====      =====
   {0x0004F000,     1200,    1205,  0x0004F000,    1205, &amp;quot; Ok&amp;quot;},  //  0
   {0x0009D000,     2400,    2396,  0x0009D000,    2395, &amp;quot; Ok&amp;quot;},  //  1
   {0x0013B000,     4800,    4808,  0x0013B000,    4806, &amp;quot; Ok&amp;quot;},  //  2
   {0x00275000,     9600,    9598,  0x00275000,    9597, &amp;quot; Ok&amp;quot;},  //  3
   {0x003AF000,    14400,   14401,  0x003B0000,   14404, &amp;quot;  -&amp;quot;},  //  4
   {0x004EA000,    19200,   19208,  0x004EA000,   19195, &amp;quot; Ok&amp;quot;},  //  5
   {0x0075C000,    28800,   28777,  0x0075F000,   28793, &amp;quot;  -&amp;quot;},  //  6
   {0x009D0000,    38400,   38369,  0x009D5000,   38406, &amp;quot;  -&amp;quot;},  //  7
   {0x00EB0000,    57600,   57554,  0x00EBF000,   57601, &amp;quot;  -&amp;quot;},  //  8
   {0x013A9000,    76800,   76923,  0x013A9000,   76797, &amp;quot; Ok&amp;quot;},  //  9
   {0x01D60000,   115200,  115108,  0x01D7E000,  115203, &amp;quot;  -&amp;quot;},  // 10
   {0x03B00000,   230400,  231884,  0x03AFB000,  230392, &amp;quot;  -&amp;quot;},  // 11
   {0x04000000,   250000,  250000,  0x04000000,  250000, &amp;quot; Ok&amp;quot;},  // 12
   {0x07400000,   460800,  457143,  0x075F7000,  460800, &amp;quot;  -&amp;quot;},  // 13
   {0x0F000000,   921600,  941176,  0x0EBEE000,  921600, &amp;quot;  -&amp;quot;},  // 14
   {0x10000000,  1000000, 1000000,  0x10000000, 1000000, &amp;quot; Ok&amp;quot;},  // 15
// Extra and changed values from nRF52840 Product Specification
   {0x003B0000,    14400,   14414,  0x003B0000,   14404, &amp;quot; Ok&amp;quot;},  // 16
   {0x0075F000,    28800,   28829,  0x0075F000,   28793, &amp;quot; Ok&amp;quot;},  // 17
   {0x00800000,    31250,   31250,  0x00800000,   31250, &amp;quot; Ok&amp;quot;},  // 18
   {0x009D5000,    38400,   38462,  0x003B0000,   38406, &amp;quot; Ok&amp;quot;},  // 19
   {0x00E50000,    56000,   55944,  0x00E56000,   55999, &amp;quot;  -&amp;quot;},  // 20
   {0x00EBF000,    57600,   57762,  0x00EBF000,   57601, &amp;quot; Ok&amp;quot;},  // 21
   {0x01D7E000,   115200,  115942,  0x01D7E000,  115203, &amp;quot; Ok&amp;quot;},  // 22
   {0x03AFB000,   230400,  231884,  0x03AFB000,  230392, &amp;quot; Ok&amp;quot;},  // 23
   {0x075F7000,   460800,  470588,  0x075F7000,  460800, &amp;quot; Ok&amp;quot;},  // 24
   {0x0EBED000,   921600,  941176,  0x0EBEE000,  921600, &amp;quot;  -&amp;quot;}}; // 25
#define NUM_BAUD_TESTS (sizeof(BaudCheck)/sizeof(BaudCheck[0]))

static void BaudRateDivisorTest(void)
{
   // Baud rate calculation on nRF51 and nRF52832
   // ===========================================
   //
   // Calculate BAUDRATE value settings for the black-magic 20-bit baud rate generator

   uint32_t OkCountRegister = 0, FailCountRegister = 0, CalculatedRegisterValue;
   uint32_t OkCountActualBaud = 0, FailCountActualBaud = 0;
   uint32_t BaudIndex, ActualBaudRate;
   uint64_t SystemClock = 16000000ULL;    // Typically 16MHz
   uint64_t MagicScaler = 32; // Preserves bits on divisions, shift 32 bits

   for (BaudIndex = 0; BaudIndex &amp;lt; NUM_BAUD_TESTS; BaudIndex++)
   {
      // Baudrate generator for the UART is the top 20 bits of a 32-bit field; add in rounding 0.5 ls bit
      CalculatedRegisterValue = (uint32_t)(((((uint64_t)BaudCheck[BaudIndex].RequiredBaudRate &amp;lt;&amp;lt; MagicScaler) + (SystemClock&amp;gt;&amp;gt;1)) / SystemClock) + 0x800) &amp;amp; 0xFFFFF000;
      BaudCheck[BaudIndex].CalculatedRegisterValue = CalculatedRegisterValue;
      if ( BaudCheck[BaudIndex].QuotedRegisterValue == CalculatedRegisterValue)
      {
         OkCountRegister++;
         memcpy(BaudCheck[BaudIndex].DoesRegisterMatch, &amp;quot; Ok&amp;quot;, RESULT_STRING_LENGTH);
      }
      else
      {
         FailCountRegister++;
      }
      ActualBaudRate = (uint32_t)(((uint64_t)CalculatedRegisterValue * SystemClock) &amp;gt;&amp;gt; MagicScaler);
      BaudCheck[BaudIndex].CalculatedActualBaudRate = ActualBaudRate;
      if ( BaudCheck[BaudIndex].QuotedActualBaudRate == ActualBaudRate)
      {
         OkCountActualBaud++;
      }
      else
      {
         FailCountActualBaud++;
      }
   }
   while(1) ;
}

static void SetupUART(const uint32_t BaudRate);
static void StartUART_Transmit(const uint8_t * const pMsg, const uint16_t MsgLength);
static void DisableUART(void);
static uint16_t SetupUART_Receive(uint8_t * const pMsg, const uint16_t MaxMsgLength);
static uint16_t WaitUART_Receive(void);

static NRF_UARTE_Type *pUART = NRF_UARTE0;

#define PIN_UART_TX         PIN_FEATHER_TXD // P0.25
#define PIN_UART_RX         PIN_FEATHER_RXD // P0.24
#define MAX_TX_PACKET_SIZE  128 //2048  nRF52832 8-bit, nRF52840 16-bit

static uint8_t TxMsg[MAX_TX_PACKET_SIZE] = &amp;quot;Baudrate generator for the UART is the top 20 bits of a 32-bit field; add in rounding 0.5 ls bit&amp;quot;;
#define TX_PACKET_SIZE sizeof(TxMsg)
#define RX_PACKET_SIZE (TX_PACKET_SIZE - 1)
static uint8_t RxMsg[RX_PACKET_SIZE] = &amp;quot;&amp;quot;;
uint32_t RequiredBaudRate = 1000000UL;
uint32_t MaxOkdBaudRate = 0UL;
uint32_t CalculatedRegisterValue;
uint32_t RegisterValueAtMaxBaud = 0;
uint64_t SystemClock = 16000000ULL;    // Typically 16MHz
uint64_t MagicScaler = 32;             // Preserves bits on divisions, shift 32 bits

void UART_BaudTest(void)
{
   // Enable crystal osc
   for (RequiredBaudRate = 1000000; RequiredBaudRate &amp;lt; 2000000; )
   {
      //  Baudrate generator for the UART is the top 20 bits of a 32-bit field; add in rounding 0.5 ls bit
      CalculatedRegisterValue = (uint32_t)(((((uint64_t)RequiredBaudRate &amp;lt;&amp;lt; MagicScaler) + (SystemClock &amp;gt;&amp;gt; 1)) / SystemClock) + 0x800) &amp;amp; 0xFFFFF000;
      // Setup UART from scratch for each baud rate test
      SetupUART(CalculatedRegisterValue); // NRF_UART_BAUDRATE_230400);
      SetupUART_Receive(RxMsg, sizeof(RxMsg));
      StartUART_Transmit(TxMsg, TX_PACKET_SIZE);
      WaitUART_Receive();
      DisableUART();
      if ((memcmp(TxMsg, RxMsg, RX_PACKET_SIZE) == 0) &amp;amp;&amp;amp; (pUART-&amp;gt;EVENTS_ERROR == 0) &amp;amp;&amp;amp; (pUART-&amp;gt;ERRORSRC == 0x0000))
      {
         MaxOkdBaudRate = RequiredBaudRate;
         RegisterValueAtMaxBaud = CalculatedRegisterValue;
         //break;
      }
      RequiredBaudRate += 20;
   }
   while (1)
      ;
}

static void SetupUART(const uint32_t BaudRate)
{
   // Disable the UARTE
   pUART-&amp;gt;ENABLE = 0;
   // Configure UARTE with no flow control, no parity bit and selected baud rate
   pUART-&amp;gt;CONFIG = 0;
   pUART-&amp;gt;BAUDRATE = BaudRate;
   // Select TX and RX pin default disconnected mode to avoid sending break indication on disabling uart ie NRF_GPIO_PIN_INPUT_DISCONNECT on Rx
   nrf_gpio_cfg(PIN_UART_RX, NRF_GPIO_PIN_DIR_INPUT,  NRF_GPIO_PIN_INPUT_CONNECT, NRF_GPIO_PIN_PULLUP, NRF_GPIO_PIN_S0S1, NRF_GPIO_PIN_NOSENSE);
   nrf_gpio_cfg(PIN_UART_TX, NRF_GPIO_PIN_DIR_OUTPUT, NRF_GPIO_PIN_INPUT_CONNECT, NRF_GPIO_PIN_PULLUP, NRF_GPIO_PIN_H0H1, NRF_GPIO_PIN_NOSENSE);
   // Select TX and RX pins; not for Loopback testing or 1-wire or RS485 a single pin can be used for both Rx and Tx
   pUART-&amp;gt;PSEL.TXD = PIN_UART_TX;
   pUART-&amp;gt;PSEL.RXD = PIN_UART_RX;  // For single pin loopback use PIN_UART_TX here, normal uart use PIN_UART_RX
   // Disable all interrupts and clear events
   pUART-&amp;gt;INTENCLR = 0xFFFFFFFFUL;
   pUART-&amp;gt;EVENTS_TXSTARTED = 0;
   pUART-&amp;gt;EVENTS_TXSTOPPED = 0;
   pUART-&amp;gt;EVENTS_RXSTARTED = 0;
   pUART-&amp;gt;EVENTS_ERROR = 0;
   pUART-&amp;gt;ERRORSRC = 0x000F;    // Write &amp;#39;1&amp;#39;s to clear any errors left set
   pUART-&amp;gt;EVENTS_ENDTX = 0;
   pUART-&amp;gt;EVENTS_ENDRX = 0;
   // Enable the UART, note 0x04 for UART and 0x08 for UARTE with DMA
   pUART-&amp;gt;ENABLE = 0x08;
}
STATIC_ASSERT (UARTE_ENABLE_ENABLE_Enabled == 0x08, &amp;quot;UARTE_ENABLE_ENABLE_Enabled == 0x08 Failed&amp;quot;);

static void StartUART_Transmit(const uint8_t * const pMsg, const uint16_t MsgLength)
{
   // Configure transmit buffer and start the transfer
   pUART-&amp;gt;TXD.MAXCNT = MsgLength;
   pUART-&amp;gt;TXD.PTR    = (uint32_t)pMsg;
   pUART-&amp;gt;TASKS_STARTTX = 1;
   __DSB();
   // Wait until the transfer start event is indicated
   while (pUART-&amp;gt;EVENTS_TXSTARTED == 0) ;
   // Wait until the transfer is complete
   while (pUART-&amp;gt;EVENTS_ENDTX == 0) ; //add timeout here also add LEDs blinking during tests

   // Stop the UART TX
   pUART-&amp;gt;TASKS_STOPTX = 1;
   __DSB();
   // Wait until we receive the stopped event
   while (pUART-&amp;gt;EVENTS_TXSTOPPED == 0) ;
}

static void DisableUART(void)
{
   // De-Select TX and RX pins
   pUART-&amp;gt;PSEL.TXD = 0x80000000;
   pUART-&amp;gt;PSEL.RXD = 0x80000000;
   // Disable the UARTE
   pUART-&amp;gt;ENABLE = 0;
}

static uint16_t SetupUART_Receive(uint8_t * const pMsg, const uint16_t MaxMsgLength)
{
   volatile uint32_t Timeout;
   // Clear receive buffer
   memcpy(pMsg, &amp;quot;-----------------&amp;quot;, MaxMsgLength);
   // Configure receive buffer and start reception
   pUART-&amp;gt;RXD.MAXCNT = MaxMsgLength;
   pUART-&amp;gt;RXD.PTR    = (uint32_t)pMsg;
   pUART-&amp;gt;EVENTS_ENDRX = 0;
   pUART-&amp;gt;TASKS_STARTRX = 1;
   __DSB();
   // Wait until the transfer start event is indicated
   while (pUART-&amp;gt;EVENTS_RXSTARTED == 0) ;
   return 0;
}

static uint16_t WaitUART_Receive(void)
{
   // Wait until the transfer is complete
   //while (pUART-&amp;gt;EVENTS_ENDRX == 0) ; //add timeout here also add LEDs blinking during tests
   // or just delay ..
   nrf_delay_ms(1);
   // Stop the UART RX
   pUART-&amp;gt;TASKS_STOPRX = 1;
   __DSB();
   // Return packet when postLastRxByteTime indicates end-of-packet timeout
   return 0;
}
&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Technical question regarding UART baud rate generator (BAUDRATE register, offset 0x524)</title><link>https://devzone.nordicsemi.com/thread/557385?ContentTypeID=1</link><pubDate>Fri, 19 Dec 2025 01:44:58 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a4df05dc-49d8-4c60-8b57-34674652f82c</guid><dc:creator>haoren1101</dc:creator><description>&lt;p&gt;Hello, may I ask how this corresponding table was calculated or from which document you obtained it? Thank you!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Technical question regarding UART baud rate generator (BAUDRATE register, offset 0x524)</title><link>https://devzone.nordicsemi.com/thread/458641?ContentTypeID=1</link><pubDate>Mon, 04 Dec 2023 03:29:57 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:9ce296ff-8258-42b2-9029-bcb7a84d62dd</guid><dc:creator>Peter Luo</dc:creator><description>&lt;p&gt;Good&amp;nbsp;Job!&amp;nbsp; The&amp;nbsp;&lt;span&gt;mechanism for receiver to identify the first byte seems more complicated, need more efforts to understand it, w&lt;/span&gt;e&amp;#39;ll do more test in future.&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Technical question regarding UART baud rate generator (BAUDRATE register, offset 0x524)</title><link>https://devzone.nordicsemi.com/thread/458624?ContentTypeID=1</link><pubDate>Sun, 03 Dec 2023 17:36:25 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d0a65468-7eea-47f7-aa13-bfb6ed763587</guid><dc:creator>hmolesworth</dc:creator><description>&lt;p&gt;I spent a while longer on this, and have some helpful information.&lt;/p&gt;
&lt;p&gt;First the single UART/E on the nRF52832 and both the UART/Es on the nRF52840 can be used in loopback mode (with or without DMA) with a single pin and no jumper wires; this is useful for testing, 1-wire applications and RS485. Second the max value for large packets seems to be 1,777,760 baud register 1C71&amp;#39;B000 which I verified by loopback testing of 2048-byte packets on the nRF52840 and 128-byte packets on the nRF52832 and checking for framing and other errors.&lt;/p&gt;
&lt;p&gt;This is the bare-metal code in case it is useful to others:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;static void SetupUART(const uint32_t BaudRate);
static void StartUART_Transmit(const uint8_t * const pMsg, const uint16_t MsgLength);
static void DisableUART(void);
static uint16_t SetupUART_Receive(uint8_t * const pMsg, const uint16_t MaxMsgLength);
static uint16_t WaitUART_Receive(void);

static NRF_UARTE_Type *pUART = NRF_UARTE0;

#define PIN_UART_TX         PIN_FEATHER_TXD
#define PIN_UART_RX         PIN_FEATHER_RXD
#define MAX_TX_PACKET_SIZE  2048 // 16-bit on nRF52840, only 8-bit on nRF52832

static uint8_t TxMsg[MAX_TX_PACKET_SIZE] = &amp;quot;Baudrate generator for the UART is the top 20 bits of a 32-bit field; add in rounding 0.5 ls bit&amp;quot;;
#define TX_PACKET_SIZE sizeof(TxMsg)
#define RX_PACKET_SIZE (TX_PACKET_SIZE - 1)
static uint8_t RxMsg[RX_PACKET_SIZE] = &amp;quot;&amp;quot;;
uint32_t RequiredBaudRate = 1000000UL;
uint32_t MaxOkdBaudRate = 0UL;
uint32_t CalculatedRegisterValue;
uint32_t RegisterValueAtMaxBaud = 0;
uint64_t SystemClock = 16000000ULL;    // Typically 16MHz
uint64_t MagicScaler = 32;             // Preserves bits on divisions, shift 32 bits

void UART_BaudTest(void)
{
   // Enable crystal osc
   for (RequiredBaudRate = 1000000; RequiredBaudRate &amp;lt; 8000000; )
   {
      //  Baudrate generator for the UART is the top 20 bits of a 32-bit field; add in rounding 0.5 ls bit
      CalculatedRegisterValue = (uint32_t)(((((uint64_t)RequiredBaudRate &amp;lt;&amp;lt; MagicScaler) + (SystemClock &amp;gt;&amp;gt; 1)) / SystemClock) + 0x800) &amp;amp; 0xFFFFF000;
      // Setup UART from scratch for each baud rate test
      SetupUART(CalculatedRegisterValue);
      SetupUART_Receive(RxMsg, sizeof(RxMsg));
      StartUART_Transmit(TxMsg, TX_PACKET_SIZE);
      WaitUART_Receive();
      DisableUART();
      if ((memcmp(TxMsg, RxMsg, RX_PACKET_SIZE) == 0) &amp;amp;&amp;amp; (pUART-&amp;gt;EVENTS_ERROR == 0) &amp;amp;&amp;amp; (pUART-&amp;gt;ERRORSRC == 0x0000))
      {
         MaxOkdBaudRate = RequiredBaudRate;
         RegisterValueAtMaxBaud = CalculatedRegisterValue;
      }
      RequiredBaudRate += 20;
   }
   while (1)
      ;
}

static void SetupUART(const uint32_t BaudRate)
{
   // Disable the UARTE
   pUART-&amp;gt;ENABLE = 0;
   // Configure UARTE with no flow control, no parity bit and selected baud rate
   pUART-&amp;gt;CONFIG = 0;
   pUART-&amp;gt;BAUDRATE = BaudRate;
   // Select TX and RX pin default disconnected mode to avoid sending break indication on disabling uart
   nrf_gpio_cfg(PIN_UART_RX, NRF_GPIO_PIN_DIR_INPUT,  NRF_GPIO_PIN_INPUT_CONNECT, NRF_GPIO_PIN_PULLUP, NRF_GPIO_PIN_S0S1, NRF_GPIO_PIN_NOSENSE);
   nrf_gpio_cfg(PIN_UART_TX, NRF_GPIO_PIN_DIR_OUTPUT, NRF_GPIO_PIN_INPUT_CONNECT, NRF_GPIO_PIN_PULLUP, NRF_GPIO_PIN_H0H1, NRF_GPIO_PIN_NOSENSE);
   // Select TX and RX pins; note for Loopback testing or 1-wire or RS485 a single pin can be used for both Rx and Tx
   pUART-&amp;gt;PSEL.TXD = PIN_UART_TX;
   pUART-&amp;gt;PSEL.RXD = PIN_UART_RX;  // For single pin loopback use PIN_UART_TX here
   // Disable all interrupts and clear events
   pUART-&amp;gt;INTENCLR = 0xFFFFFFFFUL;
   pUART-&amp;gt;EVENTS_TXSTARTED = 0;
   pUART-&amp;gt;EVENTS_TXSTOPPED = 0;
   pUART-&amp;gt;EVENTS_RXSTARTED = 0;
   pUART-&amp;gt;EVENTS_ERROR = 0;
   pUART-&amp;gt;ERRORSRC = 0x000F;    // Write &amp;#39;1&amp;#39;s to clear any errors left set
   pUART-&amp;gt;EVENTS_ENDTX = 0;
   pUART-&amp;gt;EVENTS_ENDRX = 0;
   // Enable the UART, note 0x04 for UART and 0x08 for UARTE with DMA
   pUART-&amp;gt;ENABLE = 0x08;
}
STATIC_ASSERT (UARTE_ENABLE_ENABLE_Enabled == 0x08, &amp;quot;UARTE_ENABLE_ENABLE_Enabled == 0x08 Failed&amp;quot;);

static void StartUART_Transmit(const uint8_t * const pMsg, const uint16_t MsgLength)
{
   // Configure transmit buffer and start the transfer
   pUART-&amp;gt;TXD.MAXCNT = MsgLength;
   pUART-&amp;gt;TXD.PTR    = (uint32_t)pMsg;
   pUART-&amp;gt;TASKS_STARTTX = 1;
   __DSB();
   // Wait until the transfer start event is indicated
   while (pUART-&amp;gt;EVENTS_TXSTARTED == 0) ;
   // Wait until the transfer is complete
   while (pUART-&amp;gt;EVENTS_ENDTX == 0) ;
   // Stop the UART TX
   pUART-&amp;gt;TASKS_STOPTX = 1;
   __DSB();
   // Wait until we receive the stopped event
   while (pUART-&amp;gt;EVENTS_TXSTOPPED == 0) ;
}

static void DisableUART(void)
{
   // Disable the UARTE
   pUART-&amp;gt;ENABLE = 0;
   // De-Select TX and RX pins
   pUART-&amp;gt;PSEL.TXD = 0x80000000;
   pUART-&amp;gt;PSEL.RXD = 0x80000000;
}

static uint16_t SetupUART_Receive(uint8_t * const pMsg, const uint16_t MaxMsgLength)
{
   volatile uint32_t Timeout;
   // Clear receive buffer
   memcpy(pMsg, &amp;quot;-----------------&amp;quot;, MaxMsgLength);
   // Configure receive buffer and start reception
   pUART-&amp;gt;RXD.MAXCNT = MaxMsgLength;
   pUART-&amp;gt;RXD.PTR    = (uint32_t)pMsg;
   pUART-&amp;gt;EVENTS_ENDRX = 0;
   pUART-&amp;gt;TASKS_STARTRX = 1;
   __DSB();
   // Wait until the transfer start event is indicated
   while (pUART-&amp;gt;EVENTS_RXSTARTED == 0) ;
   return 0;
}

static uint16_t WaitUART_Receive(void)
{
   // Wait until the transfer is complete
   //while (pUART-&amp;gt;EVENTS_ENDRX == 0) ; //add timeout here if using this during tests
   // just delay .. not actually required but helps with testing
   nrf_delay_ms(1);
   // Stop the UART RX
   pUART-&amp;gt;TASKS_STOPRX = 1;
   __DSB();
   // Wait until we receive the stopped event
   //while (pUART-&amp;gt;EVENTS_ENDRX == 0) ;
   // Flush fifo
   //pUART-&amp;gt;TASKS_FLUSHRX = 1;
   // Return packet when postLastRxByteTime indicates end-of-packet timeout
   return 0;
}&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Technical question regarding UART baud rate generator (BAUDRATE register, offset 0x524)</title><link>https://devzone.nordicsemi.com/thread/458618?ContentTypeID=1</link><pubDate>Sun, 03 Dec 2023 02:08:53 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:792e5557-6ddc-49ca-93ac-14b437c5acff</guid><dc:creator>hmolesworth</dc:creator><description>&lt;p&gt;Helpful feedback, and I verified 1.5MHz. Following on, it looks like the receiver is using a 9-sample mechanism for voting on each received bit. MSP430 uses 3 samples, older uarts use 16 samples. For 9 samples, at least 5 high samples are required for deciding a &amp;#39;1&amp;#39;, ditto 5 or more low for a &amp;#39;0&amp;#39;.&amp;nbsp; 16MHz / 9 =&amp;gt; 1.777778 MHz. Setting this value as the baud rate gives&amp;nbsp;zero errors in 256-byte packets (8N1). I&amp;#39;ll run a test with (say) 4 k packet sizes, but this is good news.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Technical question regarding UART baud rate generator (BAUDRATE register, offset 0x524)</title><link>https://devzone.nordicsemi.com/thread/458602?ContentTypeID=1</link><pubDate>Sat, 02 Dec 2023 02:03:23 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:2be03e3c-4850-4c43-87ac-f3bf2bb1d245</guid><dc:creator>Peter Luo</dc:creator><description>&lt;p&gt;We&amp;#39;ve finished more loopback tests. It shows 2.5Mbps with RX buffer length=1(&amp;gt;1 can&amp;#39;t) can work well, 1.5Mbps(1.6Mbps can&amp;#39;t) with RX buffer length=64(&amp;gt;64 should OK too) can work well.&amp;nbsp; We guest there is some unknown factor causing the strange results. For our application,&amp;nbsp;&lt;span&gt;2.5Mbps with RX buffer length=1 is OK. Thank you for your great contribution!&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Technical question regarding UART baud rate generator (BAUDRATE register, offset 0x524)</title><link>https://devzone.nordicsemi.com/thread/458592?ContentTypeID=1</link><pubDate>Fri, 01 Dec 2023 21:33:17 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a84d1a55-f9e0-46a1-9841-f1ca0f0a9e48</guid><dc:creator>hmolesworth</dc:creator><description>&lt;p&gt;I tested Tx up to a tad less than 8MHz (7.99999MHz) and Tx works fine, but the Rx probably uses /16 or /3 for voting on high/low for each bit; I posted the baud rates I tested on Tx here some years ago&amp;nbsp;&lt;a href="https://devzone.nordicsemi.com/f/nordic-q-a/84204/framing-error-and-noisy-data-when-using-uarte-at-high-baud-rate/352787"&gt;framing-error-and-noisy-data-when-using-uarte-at-high-baud-rate&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Might be worth us doing a loopback test at all baud rates, maybe run overnight ..&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Technical question regarding UART baud rate generator (BAUDRATE register, offset 0x524)</title><link>https://devzone.nordicsemi.com/thread/458462?ContentTypeID=1</link><pubDate>Fri, 01 Dec 2023 08:56:59 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:da69f162-9af8-48fa-b5d2-72de6d4d4834</guid><dc:creator>Peter Luo</dc:creator><description>&lt;p&gt;FYI: We&amp;#39;ve finished some loopback test, when buadrate is set to 2Mbps, no data can be received and no events can be triggered, however when baudrate is set to 2.5Mbps, some events can be triggered according to TX data, maybe we can use it to build a special full-duplex system.&lt;span class="emoticon" data-url="https://devzone.nordicsemi.com/cfs-file/__key/system/emoji/1f604.svg" title="Smile"&gt;&amp;#x1f604;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Technical question regarding UART baud rate generator (BAUDRATE register, offset 0x524)</title><link>https://devzone.nordicsemi.com/thread/458424?ContentTypeID=1</link><pubDate>Fri, 01 Dec 2023 02:54:08 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b8135f14-1b68-41c6-81f2-81817ae91b75</guid><dc:creator>hmolesworth</dc:creator><description>&lt;p&gt;Good catch!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Technical question regarding UART baud rate generator (BAUDRATE register, offset 0x524)</title><link>https://devzone.nordicsemi.com/thread/458422?ContentTypeID=1</link><pubDate>Fri, 01 Dec 2023 02:30:46 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:e2654318-bbae-4765-9a87-44623768d3b8</guid><dc:creator>Peter Luo</dc:creator><description>&lt;p&gt;Hi&amp;nbsp;hmolesworth,&lt;/p&gt;
&lt;p&gt;Thank you so much!&lt;/p&gt;
&lt;p&gt;The &lt;span&gt;equation :&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;CalculatedRegisterValue = (uint32_t)((((uint64_t)RequiredBaudRate &amp;lt;&amp;lt; MagicScaler) + (SystemClock&amp;gt;&amp;gt;1) / SystemClock) + 0x800) &amp;amp; 0xFFFFF000;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;should be modified&amp;nbsp; as following in my SES IDE :&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;CalculatedRegisterValue = (uint32_t)(( &lt;strong&gt;&lt;span style="color:#008000;"&gt;(&lt;/span&gt;&lt;/strong&gt; ((uint64_t)RequiredBaudRate &amp;lt;&amp;lt; MagicScaler) + (SystemClock&amp;gt;&amp;gt;1)&amp;nbsp;&amp;nbsp;&lt;strong&gt;&lt;span style="color:#008000;"&gt;)&lt;/span&gt;&lt;/strong&gt;/ SystemClock) + 0x800) &amp;amp; 0xFFFFF000;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Technical question regarding UART baud rate generator (BAUDRATE register, offset 0x524)</title><link>https://devzone.nordicsemi.com/thread/382073?ContentTypeID=1</link><pubDate>Wed, 17 Aug 2022 13:59:32 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c13b01a0-6206-4cd9-a758-9d82516be57d</guid><dc:creator>Tim Schuerewegen</dc:creator><description>&lt;p&gt;nRF52832 (rev 2) NRF_UARTE0-&amp;gt;BAUDRATE values and corresponding baud rates.&lt;br /&gt;&lt;br /&gt;Bits 11-0 are not used.&lt;br /&gt;&lt;br /&gt;&lt;a href="https://devzone.nordicsemi.com/cfs-file/__key/communityserver-discussions-components-files/4/nrf52832_5F00_uarte_5F00_baud_5F00_rates.txt"&gt;devzone.nordicsemi.com/.../nrf52832_5F00_uarte_5F00_baud_5F00_rates.txt&lt;/a&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Technical question regarding UART baud rate generator (BAUDRATE register, offset 0x524)</title><link>https://devzone.nordicsemi.com/thread/169356?ContentTypeID=1</link><pubDate>Mon, 04 Feb 2019 15:52:12 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b7560d57-5863-4819-845d-6f23945865d7</guid><dc:creator>hmolesworth</dc:creator><description>&lt;p&gt;I checked the nRF52840 Product Specification, and interestingly there have been some additions and corrections, but 10 of the 26 quoted values still seem incorrect, although now not by much. I&amp;#39;m also curious as to whether the baud rate generator is indeed only 20 bits, given that all 32 bits are writable .. I may test this if I get time.&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;// Quoted values from nRF52832 v1.4 datasheet - 16 correct, 10 incorrect
static BaudCheck_t BaudCheck[] = {
//  -------Documentation---------   -------Calculated---------
//  Register    Required   Actual    Register    Actual    Ok?      Index
//  ==========  ========   ======   ==========   ======   ====      =====
   {0x0004F000,     1200,    1205,  0x0004F000,    1205, &amp;quot; Ok&amp;quot;},  //  0
   {0x0009D000,     2400,    2396,  0x0009D000,    2395, &amp;quot; Ok&amp;quot;},  //  1
   {0x0013B000,     4800,    4808,  0x0013B000,    4806, &amp;quot; Ok&amp;quot;},  //  2
   {0x00275000,     9600,    9598,  0x00275000,    9597, &amp;quot; Ok&amp;quot;},  //  3
   {0x003AF000,    14400,   14401,  0x003B0000,   14404, &amp;quot;  -&amp;quot;},  //  4
   {0x004EA000,    19200,   19208,  0x004EA000,   19195, &amp;quot; Ok&amp;quot;},  //  5
   {0x0075C000,    28800,   28777,  0x0075F000,   28793, &amp;quot;  -&amp;quot;},  //  6
   {0x009D0000,    38400,   38369,  0x009D5000,   38406, &amp;quot;  -&amp;quot;},  //  7
   {0x00EB0000,    57600,   57554,  0x00EBF000,   57601, &amp;quot;  -&amp;quot;},  //  8
   {0x013A9000,    76800,   76923,  0x013A9000,   76797, &amp;quot; Ok&amp;quot;},  //  9
   {0x01D60000,   115200,  115108,  0x01D7E000,  115203, &amp;quot;  -&amp;quot;},  // 10
   {0x03B00000,   230400,  231884,  0x03AFB000,  230392, &amp;quot;  -&amp;quot;},  // 11
   {0x04000000,   250000,  250000,  0x04000000,  250000, &amp;quot; Ok&amp;quot;},  // 12
   {0x07400000,   460800,  457143,  0x075F7000,  460800, &amp;quot;  -&amp;quot;},  // 13
   {0x0F000000,   921600,  941176,  0x0EBEE000,  921600, &amp;quot;  -&amp;quot;},  // 14
   {0x10000000,  1000000, 1000000,  0x10000000, 1000000, &amp;quot; Ok&amp;quot;},  // 15
// Extra and changed values from nRF52840 Product Specification
   {0x003B0000,    14400,   14414,  0x003B0000,   14404, &amp;quot; Ok&amp;quot;},  // 16
   {0x0075F000,    28800,   28829,  0x0075F000,   28793, &amp;quot; Ok&amp;quot;},  // 17
   {0x00800000,    31250,   31250,  0x00800000,   31250, &amp;quot; Ok&amp;quot;},  // 18
   {0x009D5000,    38400,   38462,  0x003B0000,   38406, &amp;quot; Ok&amp;quot;},  // 19
   {0x00E50000,    56000,   55944,  0x00E56000,   55999, &amp;quot;  -&amp;quot;},  // 20
   {0x00EBF000,    57600,   57762,  0x00EBF000,   57601, &amp;quot; Ok&amp;quot;},  // 21
   {0x01D7E000,   115200,  115942,  0x01D7E000,  115203, &amp;quot; Ok&amp;quot;},  // 22
   {0x03AFB000,   230400,  231884,  0x03AFB000,  230392, &amp;quot; Ok&amp;quot;},  // 23
   {0x075F7000,   460800,  470588,  0x075F7000,  460800, &amp;quot; Ok&amp;quot;},  // 24
   {0x0EBED000,   921600,  941176,  0x0EBEE000,  921600, &amp;quot;  -&amp;quot;}}; // 25
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;I added rounding on the system clock, but that doesn&amp;#39;t affect results:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;// Baudrate generator for the UART is the top 20 bits of a 32-bit field; add in rounding 0.5 ls bit
CalculatedRegisterValue = (uint32_t)(((((uint64_t)RequiredBaudRate &amp;lt;&amp;lt; MagicScaler) + (SystemClock &amp;gt;&amp;gt; 1)) / SystemClock) + 0x800) &amp;amp; 0xFFFFF000;&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Technical question regarding UART baud rate generator (BAUDRATE register, offset 0x524)</title><link>https://devzone.nordicsemi.com/thread/169193?ContentTypeID=1</link><pubDate>Sun, 03 Feb 2019 19:12:09 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:3d81906a-6fcf-40d2-a78d-bc5ba2f2db60</guid><dc:creator>hmolesworth</dc:creator><description>&lt;p&gt;You are welcome .. but in passing this has now become something of an issue as it turns out we have shipped product using incorrect values based on the manual; some of the differences are significant:&lt;/p&gt;
&lt;p&gt;&lt;em&gt; {0x0F000000, 921600, 941176, 0x0EBEE000, 921600, &amp;quot; -&amp;quot;}, // 14&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;All the quoted values are here:&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;#define RESULT_STRING_LENGTH 3   // &amp;quot;Yes&amp;quot; or &amp;quot;  -&amp;quot;

typedef struct {
   uint32_t QuotedRegisterValue;
   uint32_t RequiredBaudRate;
   uint32_t QuotedActualBaudRate;
   uint32_t CalculatedRegisterValue;
   uint32_t CalculatedActualBaudRate;
   char     DoesRegisterMatch[RESULT_STRING_LENGTH];
} BaudCheck_t;

// Quoted values from nRF52832 v1.4 datasheet
static BaudCheck_t BaudCheck[] = {
//  -------Documentation---------   -------Calculated---------
//  Register    Required   Actual    Register    Actual    Ok?      Index
//  ==========  ========   ======   ==========   ======   ====      =====
   {0x0004F000,     1200,    1205,  0x0004F000,    1205, &amp;quot; Ok&amp;quot;},  //  0
   {0x0009D000,     2400,    2396,  0x0009D000,    2395, &amp;quot; Ok&amp;quot;},  //  1
   {0x0013B000,     4800,    4808,  0x0013B000,    4806, &amp;quot; Ok&amp;quot;},  //  2
   {0x00275000,     9600,    9598,  0x00275000,    9597, &amp;quot; Ok&amp;quot;},  //  3
   {0x003AF000,    14400,   14401,  0x003B0000,   14404, &amp;quot;  -&amp;quot;},  //  4
   {0x004EA000,    19200,   19208,  0x004EA000,   19195, &amp;quot; Ok&amp;quot;},  //  5
   {0x0075C000,    28800,   28777,  0x0075F000,   28793, &amp;quot;  -&amp;quot;},  //  6
   {0x009D0000,    38400,   38369,  0x009D5000,   38406, &amp;quot;  -&amp;quot;},  //  7
   {0x00EB0000,    57600,   57554,  0x00EBF000,   57601, &amp;quot;  -&amp;quot;},  //  8
   {0x013A9000,    76800,   76923,  0x013A9000,   76797, &amp;quot; Ok&amp;quot;},  //  9
   {0x01D60000,   115200,  115108,  0x01D7E000,  115203, &amp;quot;  -&amp;quot;},  // 10
   {0x03B00000,   230400,  231884,  0x03AFB000,  230392, &amp;quot;  -&amp;quot;},  // 11
   {0x04000000,   250000,  250000,  0x04000000,  250000, &amp;quot; Ok&amp;quot;},  // 12
   {0x07400000,   460800,  457143,  0x075F7000,  460800, &amp;quot;  -&amp;quot;},  // 13
   {0x0F000000,   921600,  941176,  0x0EBEE000,  921600, &amp;quot;  -&amp;quot;},  // 14
   {0x10000000,  1000000, 1000000,  0x10000000, 1000000, &amp;quot; Ok&amp;quot;}}; // 15
#define NUM_BAUD_TESTS (sizeof(BaudCheck)/sizeof(BaudCheck[0]))
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;I am hoping someone might critique this and reassure us that is not the case. This is the test code which backfills the table above:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;static void BaudRateDivisorTest(void)
{
   // Baud rate calculation on nRF51 and nRF52832
   // ===========================================
   //
   // Calculate BAUDRATE value settings for the black-magic 20-bit baud rate generator

   uint32_t OkCountRegister = 0, FailCountRegister = 0, CalculatedRegisterValue;
   uint32_t OkCountActualBaud = 0, FailCountActualBaud = 0;
   uint32_t BaudIndex, ActualBaudRate;
   uint64_t SystemClock = 16000000ULL;    // Typically 16MHz
   uint64_t MagicScaler = 32; // Preserves bits on divisions, shift 32 bits

   for (BaudIndex = 0; BaudIndex &amp;lt; NUM_BAUD_TESTS; BaudIndex++)
   {
      // Baudrate generator for the UART is the top 20 bits of a 32-bit field; add in rounding 0.5 ls bit
      CalculatedRegisterValue = (uint32_t)((((uint64_t)BaudCheck[BaudIndex].RequiredBaudRate &amp;lt;&amp;lt; MagicScaler) / SystemClock) + 0x800) &amp;amp; 0xFFFFF000;
      BaudCheck[BaudIndex].CalculatedRegisterValue = CalculatedRegisterValue;
      if ( BaudCheck[BaudIndex].QuotedRegisterValue == CalculatedRegisterValue)
      {
         OkCountRegister++;
         memcpy(BaudCheck[BaudIndex].DoesRegisterMatch, &amp;quot; Ok&amp;quot;, RESULT_STRING_LENGTH);
      }
      else
      {
         FailCountRegister++;
      }
      ActualBaudRate = (uint32_t)(((uint64_t)CalculatedRegisterValue * SystemClock) &amp;gt;&amp;gt; MagicScaler);
      BaudCheck[BaudIndex].CalculatedActualBaudRate = ActualBaudRate;
      if ( BaudCheck[BaudIndex].QuotedActualBaudRate == ActualBaudRate)
      {
         OkCountActualBaud++;
      }
      else
      {
         FailCountActualBaud++;
      }
   }
   while(1) ;
}
&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Technical question regarding UART baud rate generator (BAUDRATE register, offset 0x524)</title><link>https://devzone.nordicsemi.com/thread/169189?ContentTypeID=1</link><pubDate>Sun, 03 Feb 2019 17:38:19 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b97134d1-416c-4a61-995c-0e509b985cf5</guid><dc:creator>Bruce</dc:creator><description>&lt;p&gt;Thanks for the info. Very helpful!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Technical question regarding UART baud rate generator (BAUDRATE register, offset 0x524)</title><link>https://devzone.nordicsemi.com/thread/169171?ContentTypeID=1</link><pubDate>Sun, 03 Feb 2019 03:37:01 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:409d06f4-740c-4e85-8ec4-ac1f27a5ceb9</guid><dc:creator>hmolesworth</dc:creator><description>&lt;p&gt;Such a good question, and highlights the fun the hardware design engineer must have been having that day .. this is what I use, inclusive of the rounding&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;   // Baud rate calculation on nRF51 and nRF52832
   // ===========================================
   //
   // Calculate BAUDRATE value settings for the black-magic 20-bit baud rate generator

   uint32_t CalculatedRegisterValue;
   uint64_t SystemClock = 16000000ULL;    // Typically 16MHz
   uint64_t MagicScaler = 32; // Preserves bits on divisions, shift 32 bits

   // Baudrate generator for the UART is the top 20 bits of a 32-bit field; add in rounding 0.5 ls bit
   CalculatedRegisterValue = (uint32_t)((((uint64_t)RequiredBaudRate &amp;lt;&amp;lt; MagicScaler) / SystemClock) + 0x800) &amp;amp; 0xFFFFF000;&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;So does it work? Well it doesn&amp;#39;t exactly match the datasheet quoted values:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;typedef struct {
   uint32_t QuotedRegisterValue;
   uint32_t RequiredBaudRate;
   uint32_t QuotedActualBaudRate;
} BaudCheck_t;

// Quoted values from nRF52832 v1.4 datasheet
static BaudCheck_t BaudCheck[] = {
   {0x0004F000,    1200,    1205},
   {0x0009D000,    2400,    2396},
   {0x0013B000,    4800,    4808},
   {0x00275000,    9600,    9598},
   {0x003AF000,   14400,   14401},
   {0x004EA000,   19200,   19208},
   {0x0075C000,   28800,   28777},
   {0x009D0000,   38400,   38369},
   {0x00EB0000,   57600,   57554},
   {0x013A9000,   76800,   76923},
   {0x01D60000,  115200,  115108},
   {0x03B00000,  230400,  231884},
   {0x04000000,  250000,  250000},
   {0x07400000,  460800,  457143},
   {0x0F000000,  921600,  941176},
   {0x10000000, 1000000, 1000000}};
#define NUM_BAUD_TESTS (sizeof(BaudCheck)/sizeof(BaudCheck[0]))

static void BaudRateDivisorTest(void)
{
   // Baud rate calculation on nRF51 and nRF52832
   // ===========================================
   //
   // Calculate BAUDRATE value settings for the black-magic 20-bit baud rate generator

   uint32_t OkCountRegister = 0, FailCountRegister = 0, CalculatedRegisterValue;
   uint32_t OkCountActualBaud = 0, FailCountActualBaud = 0;
   uint32_t BaudIndex, ActualBaudRate;
   uint64_t SystemClock = 16000000ULL;    // Typically 16MHz
   uint64_t MagicScaler = 32; // Preserves bits on divisions, shift 32 bits

   for (BaudIndex = 0; BaudIndex &amp;lt; NUM_BAUD_TESTS; BaudIndex++)
   {
      // Baudrate generator for the UART is the top 20 bits of a 32-bit field; add in rounding 0.5 ls bit
      CalculatedRegisterValue = (uint32_t)((((uint64_t)BaudCheck[BaudIndex].RequiredBaudRate &amp;lt;&amp;lt; MagicScaler) / SystemClock) + 0x800) &amp;amp; 0xFFFFF000;
      if ( BaudCheck[BaudIndex].QuotedRegisterValue == CalculatedRegisterValue)
      {
         OkCountRegister++;
      }
      else
      {
         FailCountRegister++;
      }
      ActualBaudRate = (uint32_t)(((uint64_t)CalculatedRegisterValue * SystemClock) &amp;gt;&amp;gt; MagicScaler);
      if ( BaudCheck[BaudIndex].QuotedActualBaudRate == ActualBaudRate)
      {
         OkCountActualBaud++;
      }
      else
      {
         FailCountActualBaud++;
      }
   }
   while(1) ;
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;The values either exactly match the data sheet or are close; that may be a code issue or a datasheet issue, who knows but I think the h/w guy was teasing us..&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>