<?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>Dynamically change UART baud rate</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/103592/dynamically-change-uart-baud-rate</link><description>Hi, 
 nRF SDK 16.0, nrf52840 
 
 I&amp;#39;m trying to send dmx-512 frames, for that I need to send break and mark after break. For that I need to change baud rate dynamically but it&amp;#39;s not happening. The baud rate remains to the set value of 250k. attached is</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Thu, 14 Sep 2023 12:42:21 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/103592/dynamically-change-uart-baud-rate" /><item><title>RE: Dynamically change UART baud rate</title><link>https://devzone.nordicsemi.com/thread/446059?ContentTypeID=1</link><pubDate>Thu, 14 Sep 2023 12:42:21 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:98fe0066-17dd-42b8-b789-7e3ae5413637</guid><dc:creator>Aftab</dc:creator><description>&lt;p&gt;This solved the problem, thank you.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Dynamically change UART baud rate</title><link>https://devzone.nordicsemi.com/thread/445215?ContentTypeID=1</link><pubDate>Fri, 08 Sep 2023 19:14:09 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:db6f940f-5084-4a34-bbb8-acabe0356c32</guid><dc:creator>hmolesworth</dc:creator><description>&lt;p&gt;&lt;em&gt;app_uart_put()&lt;/em&gt; only places a character in the fifo queue which immediately start transmission of the byte, however bit-shifting of that byte out of the uart Tx port hasn&amp;#39;t completed and so the 2nd change to the baud rate takes place and affects the shifted bit timing immediately. Maybe try:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;    // Create start sequence with modified baud rate
    NRF_UART0-&amp;gt;BAUDRATE = (UART_BAUDRATE_BAUDRATE_Baud57600 &amp;lt;&amp;lt; UART_BAUDRATE_BAUDRATE_Pos);
    while (app_uart_put(0) != NRF_SUCCESS);
    // Wait for all 10 or 11 bits to get shifted out of Tx pin
    nrf_delay_us(191); // Minimum break duration but also 11 bits at 57600baud
    // Change the baud rate back to 250k
    NRF_UART0-&amp;gt;BAUDRATE = (UART_BAUDRATE_BAUDRATE_Baud250000 &amp;lt;&amp;lt; UART_BAUDRATE_BAUDRATE_Pos);&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Edit:&lt;br /&gt;Note at 57600 baud that&amp;#39;s more like 191uSec for 11 bits assuming 2 stop bits, which gives a 156 uSec&amp;nbsp;Break with 9-bits low. 88 uSec&amp;nbsp;Break would be approximately 5 bits low or 0xF0 at 57600 baud taking the start bit as the first low bit, but also a following Mark of at least 5 bits.&lt;/p&gt;
&lt;p&gt;You can tune the Break/Mark more accurately by selecting a baud rate which gives exact Break/Mark times required:&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
 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 &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></channel></rss>