<?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>nRF52: Set UART Break on Tx line</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/70315/nrf52-set-uart-break-on-tx-line</link><description>Hello, 
 I am using the nRF52832 Development Kit platform w/ nRF Connect SDK. 
 I have an application using UART which is configured to talk LIN to a SN65HVDA100 package https://www.ti.com/lit/ds/symlink/sn65hvda100-q1.pdf 
 Wanting to setup multiple</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Tue, 09 Feb 2021 02:44:05 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/70315/nrf52-set-uart-break-on-tx-line" /><item><title>RE: nRF52: Set UART Break on Tx line</title><link>https://devzone.nordicsemi.com/thread/293451?ContentTypeID=1</link><pubDate>Tue, 09 Feb 2021 02:44:05 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:7468fa8e-e9b2-4840-b4e0-7cdd5f4d1c00</guid><dc:creator>J Mapstone</dc:creator><description>&lt;p&gt;Thanks Dmitry.&lt;/p&gt;
&lt;p&gt;I was able to successfully toggle the baud rate at run time from 19200kbps to 9600kps back to 19200kbps again.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Attached working code snippet of re-configure and toggling UART at run-time.&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;#define LIN_BAUD_RATE_NORMAL       19200
#define LIN_BAUD_RATE_BREAK        9600

#ifdef LIN_MASTER
static void lin_driver_toggle_uart_enable_register(void)
{
    NRF_UART0-&amp;gt;ENABLE = (UART_ENABLE_ENABLE_Disabled &amp;lt;&amp;lt; UART_ENABLE_ENABLE_Pos);
    (void) (NRF_UART0-&amp;gt;ENABLE);
    NRF_UART0-&amp;gt;ENABLE = (UART_ENABLE_ENABLE_Enabled &amp;lt;&amp;lt; UART_ENABLE_ENABLE_Pos);
}
#endif

#ifdef LIN_MASTER
static void lin_driver_set_slow_baud_rate(void)
{
    int ret;

    uart_service.cfg.baudrate = LIN_BAUD_RATE_BREAK;
    ret = uart_configure(uart_service.dev, &amp;amp;uart_service.cfg);
    if (ret != 0)
    {
        //DEBUGGING:
        //DEBUG_PUSH_PRINT(&amp;quot;UART LIN&amp;gt; uart_configure() error = %d&amp;quot;, ret);
    }

    lin_driver_toggle_uart_enable_register();

    //DEBUGGING:
    //DEBUG_PUSH_PRINT(&amp;quot;REM Baud %ubps (Slow)&amp;quot;, LIN_BAUD_RATE_BREAK);
}
#endif  // LIN_MASTER

#ifdef LIN_MASTER
static void lin_driver_set_normal_baud_rate(void)
{
    int ret;

    uart_service.cfg.baudrate = LIN_BAUD_RATE_NORMAL;
    ret = uart_configure(uart_service.dev, &amp;amp;uart_service.cfg);
    if (ret != 0)
    {
        //DEBUGGING:
        //DEBUG_PUSH_PRINT(&amp;quot;UART LIN&amp;gt; uart_configure() error = %d&amp;quot;, ret);
    }

    lin_driver_toggle_uart_enable_register();

    //DEBUGGING:
    //DEBUG_PUSH_PRINT(&amp;quot;REM Baud %ubps (Normal)&amp;quot;, LIN_BAUD_RATE_NORMAL);
}
#endif

static int lin_driver_uart_setup(void)
{
    int ret;

    // Initialise
    uart_service.dev = device_get_binding(&amp;quot;UART_0&amp;quot;);
    if (uart_service.dev == NULL)
    {
        DEBUG_PUSH_PRINT(&amp;quot;UART LIN&amp;gt; Error device_get_binding() failed&amp;quot;);
        return -ENODEV; // Value = 19
    }

    // Configure
    uart_service.cfg.baudrate = LIN_BAUD_RATE_NORMAL;
    uart_service.cfg.parity = UART_CFG_PARITY_NONE;
    uart_service.cfg.stop_bits = UART_CFG_STOP_BITS_1;
    uart_service.cfg.data_bits = UART_CFG_DATA_BITS_8;
    uart_service.cfg.flow_ctrl = UART_CFG_FLOW_CTRL_NONE;
    ret = uart_configure(uart_service.dev, &amp;amp;uart_service.cfg);
    if (ret != 0)
    {
        DEBUG_PUSH_PRINT(&amp;quot;UART LIN&amp;gt; uart_configure() error = %d&amp;quot;, ret);
        return ret;
    }

    // Receive
    uart_irq_callback_set(uart_service.dev, lin_driver_uart_cb);
    uart_irq_rx_enable(uart_service.dev);

    return 0;
}&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF52: Set UART Break on Tx line</title><link>https://devzone.nordicsemi.com/thread/288612?ContentTypeID=1</link><pubDate>Tue, 12 Jan 2021 10:49:11 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f4e8e2a5-bf9d-4533-af9f-378f9b4045de</guid><dc:creator>Dmitry</dc:creator><description>&lt;p&gt;To actually change baudrate, the UART should be disabled and re-enabled again. If Zephyr doesn&amp;#39;t do this in uart_configure(), the baudrate will not be updated. You can check this by resetting port via&amp;nbsp;ENABLE&amp;nbsp;register directly after changing baudrate:&lt;/p&gt;
&lt;p&gt;NRF_UARTE0-&amp;gt;ENABLE = (UARTE_ENABLE_ENABLE_Disabled &amp;lt;&amp;lt; UARTE_ENABLE_ENABLE_Pos);&lt;br /&gt;(void) (NRF_UARTE0-&amp;gt;ENABLE);&lt;br /&gt;NRF_UARTE0-&amp;gt;ENABLE = (UARTE_ENABLE_ENABLE_Enabled &amp;lt;&amp;lt; UARTE_ENABLE_ENABLE_Pos);&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF52: Set UART Break on Tx line</title><link>https://devzone.nordicsemi.com/thread/288493?ContentTypeID=1</link><pubDate>Mon, 11 Jan 2021 21:56:35 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:cf245361-285c-4682-b5cc-9080f3085f10</guid><dc:creator>J Mapstone</dc:creator><description>&lt;p&gt;Thanks for the suggestion. It would be nice if it were that simple.&lt;/p&gt;
&lt;p&gt;However, I have an overlay file which declares the uart0 with current-speed as 19200.&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;arduino_serial: &amp;amp;uart0 {
    status = &amp;quot;okay&amp;quot;;
    compatible = &amp;quot;nordic,nrf-uart&amp;quot;;
    current-speed = &amp;lt;19200&amp;gt;;
    tx-pin = &amp;lt;17&amp;gt;;
    rx-pin = &amp;lt;16&amp;gt;;
};&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;When attempting to configure the baud rate at runtime, using the&amp;nbsp;uart_configure() function with&amp;nbsp;uart_config property baudrate set to say 4800 is accepted. Then writing a zero to the uart peripheral, the baud rate still looks to be 19200 when looking at the UART Tx with an oscilloscope, not the updated 4800.&lt;/p&gt;
&lt;p&gt;FWIW, I am using interrupt driven UART.&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;CONFIG_SERIAL=y
CONFIG_UART_INTERRUPT_DRIVEN=y
CONFIG_UART_LINE_CTRL=n&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;New question: Is it even possible to change the UART baud rate at run time for Zephyr / nRF Connect SDK?&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;The baud rate has been statically declared in the .overlay file with a set value, calling&amp;nbsp;&lt;span&gt;uart_configure()&amp;nbsp;with another baud rate seems to have no effect. Would using asynchronous UART implementation work?&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF52: Set UART Break on Tx line</title><link>https://devzone.nordicsemi.com/thread/288328?ContentTypeID=1</link><pubDate>Mon, 11 Jan 2021 10:01:45 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:5c195f2e-0da4-4625-ba38-136d4d16040f</guid><dc:creator>Dmitry</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;I can&amp;#39;t say about Zephyr API but the simple trick that works is to lower the baudrate for a short period and send a 0x00 character.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>