<?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>Passing Characteristic data to Function</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/46020/passing-characteristic-data-to-function</link><description>Hello, 
 I am having strange issue. I&amp;#39;m getting some data from custom service and characteristic. I can see the data being received is correct. However, if I try to pass the data to some other function in another file, the characteristic stops receiving</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Mon, 15 Apr 2019 11:01:42 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/46020/passing-characteristic-data-to-function" /><item><title>RE: Passing Characteristic data to Function</title><link>https://devzone.nordicsemi.com/thread/182074?ContentTypeID=1</link><pubDate>Mon, 15 Apr 2019 11:01:42 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:17dcf659-b317-4aa0-baea-906de3417435</guid><dc:creator>Aftab</dc:creator><description>&lt;p&gt;I have changed three things which corrected this error:&lt;/p&gt;
&lt;p&gt;1. defined the variable&amp;nbsp;&lt;strong&gt;global_flag&amp;nbsp;&lt;/strong&gt;as volatile&lt;/p&gt;
&lt;p&gt;2. Defined this variable in the service file and used it elsewhere&lt;/p&gt;
&lt;p&gt;3. Defined the arrays&amp;nbsp; which data from service is used to be fixed length. Like instead of defining char array[]=&amp;quot;&amp;quot;; I defined like char array[10];&lt;/p&gt;
&lt;p&gt;It&amp;#39;s strange but it&amp;nbsp;solved the issue.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Passing Characteristic data to Function</title><link>https://devzone.nordicsemi.com/thread/181622?ContentTypeID=1</link><pubDate>Thu, 11 Apr 2019 13:13:26 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d38b97fa-3521-4be2-9ac6-c468d0be90cd</guid><dc:creator>cbd</dc:creator><description>&lt;p&gt;It sounds to me that you&amp;#39;re encountering an access conflict.&lt;/p&gt;
&lt;p&gt;Below is a section of code for one of my services.&lt;/p&gt;
&lt;p&gt;lds_drive_data_t is a data structure that I transfer using one of the service characteristics.&lt;/p&gt;
&lt;p&gt;In the bottom of the code you can see that I set a global structure&amp;nbsp;&lt;pre class="ui-code" data-mode="c_cpp"&gt;volatile lds_uart_data_t m_lds_RX_data;&lt;/pre&gt;. Note that I have declared it &lt;strong&gt;volatile&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;Depending on what is received during the event data is passed to functions pointed to by lds_write_handler or lds_uart_rx_handler&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;static void lds_OnWrite(ble_lds_t * p_lds, ble_evt_t const * p_ble_evt)
{
    VERIFY_PARAM_NOT_NULL_VOID(p_lds);
    VERIFY_PARAM_NOT_NULL_VOID(p_ble_evt);

    /* get the write event data */
    ble_gatts_evt_write_t const * p_evt_write = &amp;amp;p_ble_evt-&amp;gt;evt.gatts_evt.params.write;
    lds_drive_data_t newData = {0};
    /* confirm that characteristic was written to, data length is correct and
    that an event handler has been set */
    if ((p_evt_write-&amp;gt;handle == p_lds-&amp;gt;lds_char_handles.value_handle) &amp;amp;&amp;amp;
        (sizeof(newData.command) &amp;lt;= p_evt_write-&amp;gt;len) &amp;amp;&amp;amp; (p_lds-&amp;gt;lds_write_handler != NULL))
    {
        memcpy(&amp;amp;newData.command, p_evt_write-&amp;gt;data, sizeof(newData.command));
        newData.dataLength = p_evt_write-&amp;gt;data[sizeof(newData.command)];
        if (newData.dataLength &amp;gt; 0)
        {
            memcpy(&amp;amp;newData.data,
                   p_evt_write-&amp;gt;data + sizeof(newData.command) + sizeof(newData.dataLength),
                   p_evt_write-&amp;gt;len - (sizeof(newData.command) + sizeof(newData.dataLength)));
        }
        /* pass write event data to the event handler */
        p_lds-&amp;gt;lds_write_handler(p_lds, newData);
    }
    else
    {
        if ((p_evt_write-&amp;gt;handle == p_lds-&amp;gt;lds_uart_rx_handles.value_handle) &amp;amp;&amp;amp;
        (0 &amp;lt;= p_evt_write-&amp;gt;len) &amp;amp;&amp;amp; (p_lds-&amp;gt;lds_uart_rx_handler != NULL))
        {
            m_lds_RX_data.length = p_evt_write-&amp;gt;len;
            m_lds_RX_data.p_data = p_evt_write-&amp;gt;data;
        
            /* pass write event data to the event handler */
            p_lds-&amp;gt;lds_uart_rx_handler(p_lds, m_lds_RX_data);
        }
    }
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;I don&amp;#39;t poll for data within the rest of my code at the moment, but if you can&amp;#39;t glean anything from my code then you may need to takes steps to prevent access conflicts on the basis that the SoftDevice should take priority over everything else and shouldn&amp;#39;t be held up in anyway otherwise it will suffer internal timeouts and the BLE will stop working.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Passing Characteristic data to Function</title><link>https://devzone.nordicsemi.com/thread/181553?ContentTypeID=1</link><pubDate>Thu, 11 Apr 2019 11:21:33 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:66d2fe92-c6a9-43e9-89a2-7a991a462062</guid><dc:creator>Aftab</dc:creator><description>&lt;p&gt;I have also tried to implement following code to read characteristic value.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;void get_script_start_flag(){
    uint8_t testStore;
    ble_gatts_value_t testStruct;

    testStruct.p_value = &amp;amp;testStore;
    testStruct.len = 2;
    testStruct.offset = 0;

    sd_ble_gatts_value_get(scr_service_instance-&amp;gt;conn_handle, scr_service_instance-&amp;gt;char_handles_1.value_handle, &amp;amp;testStruct);
    //NRF_LOG_INFO(&amp;quot;testStruc: %X,%X&amp;quot;, testStruct.p_value[0], testStruct.p_value[1]);
    //return testStruct.p_value[0];
    script_start_flag = testStruct.p_value[0];
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;I am reading the value in another function which scan through this value after every second. If I comment out this line:&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;script_start_flag = testStruct.p_value[0];&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Everything works fine. As soon as this line is un-commented (values is saved in local variable), and some value is sent from nRFConnect app, all services stop responding, the device comes into a sort of HALT condition. Very frustrating situation.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Passing Characteristic data to Function</title><link>https://devzone.nordicsemi.com/thread/181369?ContentTypeID=1</link><pubDate>Wed, 10 Apr 2019 15:01:42 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b9afb4c7-ed0e-4055-9ccd-333054204fe5</guid><dc:creator>Aftab</dc:creator><description>&lt;p&gt;Missing the data from NRF_LOG_INFO apart, when services stop responding? The device gets disconnected. I have also tried:&lt;/p&gt;
&lt;p&gt;attr_md_1.rd_auth = 1;&lt;br /&gt; attr_md_1.wr_auth = 1;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Passing Characteristic data to Function</title><link>https://devzone.nordicsemi.com/thread/181322?ContentTypeID=1</link><pubDate>Wed, 10 Apr 2019 12:18:19 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:99d07c0c-5a4e-49bb-8b53-e33bcca11043</guid><dc:creator>cbd</dc:creator><description>&lt;p&gt;Are you relying totally on&amp;nbsp; NRF_LOG_DEBUG output to determine whether you are handling the data?&lt;/p&gt;
&lt;p&gt;I&amp;#39;m using SES for coding and have found that due to the SoftDevice&amp;#39;s higher priority for BLE handling I&amp;#39;ll often lose NRF_LOG_DEBUG data even though code is obviously running e.g. BLE&amp;nbsp; data triggering formatted data on the UART.&lt;/p&gt;
&lt;p&gt;On a side note I&amp;#39;d recommend that you declare global_flag volatile.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>