<?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>Adding Baud Rate Characteristic to UART example</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/71553/adding-baud-rate-characteristic-to-uart-example</link><description>Hello All, 
 I am implementing a simple UART bridge over BLE and want to add a Characteristic to update the baud rate being used. I thought I added code to support a new characteristic everywhere it needs to go, but when I scan for characteristics with</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Fri, 19 Feb 2021 10:38:20 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/71553/adding-baud-rate-characteristic-to-uart-example" /><item><title>RE: Adding Baud Rate Characteristic to UART example</title><link>https://devzone.nordicsemi.com/thread/295294?ContentTypeID=1</link><pubDate>Fri, 19 Feb 2021 10:38:20 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f4d03ff7-0d19-4a7e-baaa-172f37e2221b</guid><dc:creator>Susheel Nuguru</dc:creator><description>&lt;p&gt;nice that you got it worked out.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Adding Baud Rate Characteristic to UART example</title><link>https://devzone.nordicsemi.com/thread/295186?ContentTypeID=1</link><pubDate>Thu, 18 Feb 2021 15:49:16 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:49d35817-be4c-4191-bba9-51cf03e1a084</guid><dc:creator>aaron.mcneil</dc:creator><description>&lt;p&gt;The FDS library seems like a lot of involvement just to save 2 variables to flash. Is there any super simple ways of writing to/reading from the flash?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Adding Baud Rate Characteristic to UART example</title><link>https://devzone.nordicsemi.com/thread/295167?ContentTypeID=1</link><pubDate>Thu, 18 Feb 2021 15:09:46 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:ad96ba8e-4608-4cc7-bd41-f27abd4ad74a</guid><dc:creator>aaron.mcneil</dc:creator><description>&lt;p&gt;I figured out this issue. p_data is only a uint8_t. Have to combine all 4 bytes to get the baud rate.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Adding Baud Rate Characteristic to UART example</title><link>https://devzone.nordicsemi.com/thread/295157?ContentTypeID=1</link><pubDate>Thu, 18 Feb 2021 14:53:11 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:5a51f15c-abc0-416e-b77d-5b1652f3f25d</guid><dc:creator>aaron.mcneil</dc:creator><description>&lt;p&gt;I tried this code but my p_ble_nus_evt does have not a member named p_data. I can use&amp;nbsp;(uint32_t)*p_evt-&amp;gt;params.rx_data.p_data, but this doesnt seem to be getting the entire int 32 I set. I can see I&amp;#39;m getting a 2 digit hex value, and it is the proper last 2 digits of what im trying to set there but not the whole number. For example, when i set baud to 9600 this value is 0x80, while it should be 0x2580.&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;static void nus_data_handler(ble_nus_evt_t * p_evt)
{

    if (p_evt-&amp;gt;type == BLE_NUS_EVT_RX_DATA)
    {
        uint32_t err_code;

        NRF_LOG_DEBUG(&amp;quot;Received data from BLE NUS. Writing data on UART.&amp;quot;);
        NRF_LOG_HEXDUMP_DEBUG(p_evt-&amp;gt;params.rx_data.p_data, p_evt-&amp;gt;params.rx_data.length);

        for (uint32_t i = 0; i &amp;lt; p_evt-&amp;gt;params.rx_data.length; i++)
        {
            do
            {
                err_code = app_uart_put(p_evt-&amp;gt;params.rx_data.p_data[i]);
                if ((err_code != NRF_SUCCESS) &amp;amp;&amp;amp; (err_code != NRF_ERROR_BUSY))
                {
                    NRF_LOG_ERROR(&amp;quot;Failed receiving NUS message. Error 0x%x. &amp;quot;, err_code);
                    APP_ERROR_CHECK(err_code);
                }
            } while (err_code == NRF_ERROR_BUSY);
        }
//        if (p_evt-&amp;gt;params.rx_data.p_data[p_evt-&amp;gt;params.rx_data.length - 1] == &amp;#39;\r&amp;#39;)
//        {
//            while (app_uart_put(&amp;#39;\n&amp;#39;) == NRF_ERROR_BUSY);
//        }
    }else if(p_evt-&amp;gt;type == BLE_NUS_EVT_BAUD)
    {   
        uint32_t baud_rate;
        baud_rate = (uint32_t)*p_evt-&amp;gt;params.rx_data.p_data;
        
        if(baud_rate == 9600){
         NRF_UARTE0-&amp;gt;BAUDRATE = NRF_UART_BAUDRATE_9600;
        }else if(baud_rate == 57600){
          NRF_UARTE0-&amp;gt;BAUDRATE = NRF_UART_BAUDRATE_57600;
        }else if(baud_rate == 38400){
          NRF_UARTE0-&amp;gt;BAUDRATE = NRF_UART_BAUDRATE_38400;
        }else if(baud_rate == 115200){
          NRF_UARTE0-&amp;gt;BAUDRATE = NRF_UART_BAUDRATE_115200;
        }
        
        NRF_LOG_DEBUG(&amp;quot;BAUD Rate Char Written to&amp;quot;);
    }

}&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Adding Baud Rate Characteristic to UART example</title><link>https://devzone.nordicsemi.com/thread/295154?ContentTypeID=1</link><pubDate>Thu, 18 Feb 2021 14:40:49 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:fbb6de6c-0c55-4a19-8c56-a2806abeca11</guid><dc:creator>Susheel Nuguru</dc:creator><description>[quote user="aaron.mcneil"]A couple other questions for my application. How can I set the value of the characteristic to be read from the peer side on initialization? I would want the end user to be able to read what baud rate is set in the BLE device and then allow them to change it if needed.[/quote]
&lt;p&gt;&amp;nbsp;NRF_UARTE-&amp;gt;BAUDRATE is a read-write register. So after the uart is initialized and all services discovered, you can send a notification to the peer with a magic prefix(command) combined with a baudrate value. There are many ways to do it and you need to consider this properly to see which way first best to your application architecture.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
[quote user="aaron.mcneil"]Secondly, is there any memory available in this chip to be able to save settings such as device name and baud rate over a power cycle, and set them accordingly on the next power up?[/quote]
&lt;p&gt;&amp;nbsp;Save to flash (non-volatile memory) which will keep the data even after power cycles. &lt;a href="https://infocenter.nordicsemi.com/index.jsp?topic=%2Fsdk_nrf5_v17.0.2%2Ffds_example.html&amp;amp;cp=7_1_4_6_9"&gt;FDS library&lt;/a&gt; can help you with that.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Adding Baud Rate Characteristic to UART example</title><link>https://devzone.nordicsemi.com/thread/295138?ContentTypeID=1</link><pubDate>Thu, 18 Feb 2021 14:23:18 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:63b6ed5a-9093-4bc3-a380-598ca7c1360c</guid><dc:creator>aaron.mcneil</dc:creator><description>&lt;p&gt;Thank you.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;A couple other questions for my application. How can I set the value of the characteristic to be read from the peer side on initialization? I would want the end user to be able to read what baud rate is set in the BLE device and then allow them to change it if needed.&lt;/p&gt;
&lt;p&gt;Secondly, is there any memory available in this chip to be able to save settings such as device name and baud rate over a power cycle, and set them accordingly on the next power up?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Adding Baud Rate Characteristic to UART example</title><link>https://devzone.nordicsemi.com/thread/295101?ContentTypeID=1</link><pubDate>Thu, 18 Feb 2021 13:07:45 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:e9e66275-5800-4e21-aec1-a45ba2dc83fe</guid><dc:creator>Susheel Nuguru</dc:creator><description>&lt;p&gt;I see that there is no clean easy way to change the baudrate of the uart on the fly.&lt;/p&gt;
&lt;p&gt;So I am just showing you an option to use the registers directly (instead of using NRFX API) to come to an easy and short solution. Please do not take the below code as official suggested solution, but just as an implication to see how it can be done quickly as below&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;/**@brief Callback handling Nordic UART Service (NUS) client events.
 *
 * @details This function is called to notify the application of NUS client events.
 *
 * @param[in]   p_ble_nus_c   NUS client handle. This identifies the NUS client.
 * @param[in]   p_ble_nus_evt Pointer to the NUS client event.
 */

/**@snippet [Handling events from the ble_nus_c module] */
static void ble_nus_c_evt_handler(ble_nus_c_t * p_ble_nus_c, ble_nus_c_evt_t const * p_ble_nus_evt)
{
    ret_code_t err_code;

    switch (p_ble_nus_evt-&amp;gt;evt_type)
    {
        case BLE_NUS_C_EVT_DISCOVERY_COMPLETE:
            NRF_LOG_INFO(&amp;quot;Discovery complete.&amp;quot;);
            err_code = ble_nus_c_handles_assign(p_ble_nus_c, p_ble_nus_evt-&amp;gt;conn_handle, &amp;amp;p_ble_nus_evt-&amp;gt;handles);
            APP_ERROR_CHECK(err_code);

            err_code = ble_nus_c_tx_notif_enable(p_ble_nus_c);
            APP_ERROR_CHECK(err_code);
            NRF_LOG_INFO(&amp;quot;Connected to device with Nordic UART Service.&amp;quot;);
            break;

        case BLE_NUS_C_EVT_NUS_TX_EVT:
            ble_nus_chars_received_uart_print(p_ble_nus_evt-&amp;gt;p_data, p_ble_nus_evt-&amp;gt;data_len);
            break;

        case BLE_NUS_EVT_BAUD:
            // make sure that there are no ongoing transactions
            // APP_UART_DRIVER_INSTANCE is 0
            NRF_UARTE0-&amp;gt;BAUDRATE = (uint16_t)*p_ble_nus_evt-&amp;gt;p_data; //uint32_t if the len is different, depends on what you sent on the peer side
#if 0
            // APP_UART_DRIVER_INSTANCE is 1
            NRF_UARTE1-&amp;gt;BAUDRATE = (uint16_t)*p_ble_nus_evt-&amp;gt;p_data; //uint32_t if the len is different, depends on what you sent on the peer side
#endif
            break;

        case BLE_NUS_C_EVT_DISCONNECTED:
            NRF_LOG_INFO(&amp;quot;Disconnected.&amp;quot;);
            scan_start();
            break;
    }
}&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Adding Baud Rate Characteristic to UART example</title><link>https://devzone.nordicsemi.com/thread/294440?ContentTypeID=1</link><pubDate>Mon, 15 Feb 2021 15:44:26 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:140636ab-5ebe-4a87-8310-3cb65e9b83ac</guid><dc:creator>aaron.mcneil</dc:creator><description>&lt;p&gt;Thank you for your response. Once I had my PC forget the device and then ran the scanner the characteristic showed up as expected.&lt;/p&gt;
&lt;p&gt;Building on this, are there any examples of reading a characteristic value, as well as updating the value so the phone/windows side can read it back? I can successfully subscribe to the characteristic on the phone/windows side now. When I write to that characteristic I get the correct p_evt-&amp;gt;type in the nus_handler. But where do I go from there? I need to read what value was sent to me and update the buad rate in the uart and then update the characteristics value so it can be read back by the phone or windows app.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Adding Baud Rate Characteristic to UART example</title><link>https://devzone.nordicsemi.com/thread/294185?ContentTypeID=1</link><pubDate>Fri, 12 Feb 2021 14:16:42 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:1bb29a74-0f29-4180-b764-df713f0c069b</guid><dc:creator>Susheel Nuguru</dc:creator><description>&lt;p&gt;can you test this using nRF Connect for desktop instead of a phone. I think something in the phone is caching the services from the old connection based on device address&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Adding Baud Rate Characteristic to UART example</title><link>https://devzone.nordicsemi.com/thread/294183?ContentTypeID=1</link><pubDate>Fri, 12 Feb 2021 14:14:50 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:76dd9146-14cb-46fa-898b-1f076b0d1fc2</guid><dc:creator>aaron.mcneil</dc:creator><description>&lt;p&gt;Thats really strange. Here is the screenshot of mine running the same code:&lt;/p&gt;
&lt;p&gt;&lt;a class="aQy aZr e aZI" href="https://mail.google.com/mail/u/0?ui=2&amp;amp;ik=0f909f9792&amp;amp;attid=0.1&amp;amp;permmsgid=msg-f:1691498934228808750&amp;amp;th=1779695198a8f42e&amp;amp;view=att&amp;amp;disp=safe" rel="noopener noreferrer" target="_blank"&gt;&lt;span class="a3I" id=":ov"&gt;&lt;/span&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;img src="https://devzone.nordicsemi.com/resized-image/__size/320x240/__key/communityserver-discussions-components-files/4/pastedimage1613139174902v4.png" alt=" " /&gt;&lt;/p&gt;
&lt;p&gt;When I experiment and change the UUID of the Tx Char to a 4 instead of a 3, it still shows the Tx Char as 6E4000003 also. Really confusing. Is there another element I am not handling to the advertising portion?&lt;/p&gt;
&lt;div&gt;
&lt;div class="aSH"&gt;&lt;/div&gt;
&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Adding Baud Rate Characteristic to UART example</title><link>https://devzone.nordicsemi.com/thread/294146?ContentTypeID=1</link><pubDate>Fri, 12 Feb 2021 11:59:20 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:af98d6d6-83e3-4bf5-a449-f57a8c913c29</guid><dc:creator>Susheel Nuguru</dc:creator><description>&lt;p&gt;Hi Aaron,&lt;/p&gt;
&lt;p&gt;I can see your new BAUD characteristic when i used your code&lt;/p&gt;
&lt;p&gt;&lt;img alt=" " src="https://devzone.nordicsemi.com/resized-image/__size/340x516/__key/communityserver-discussions-components-files/4/pastedimage1613131091505v1.png" /&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>