<?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>Received indication data corrupt</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/35288/received-indication-data-corrupt</link><description>Hi! 
 I&amp;#39;m using an NRF51822 as a GATT client to write data to a characteristic. The peripheral responds with several 20 byte indications. When I receive the indications, the length is reported as 20 byte, but the data is incorrect. I logged the data I</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Tue, 12 Jun 2018 15:27:48 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/35288/received-indication-data-corrupt" /><item><title>RE: Received indication data corrupt</title><link>https://devzone.nordicsemi.com/thread/135786?ContentTypeID=1</link><pubDate>Tue, 12 Jun 2018 15:27:48 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:38fdbef8-697a-451a-9f5e-8fcb4e36a99a</guid><dc:creator>Martin Ziel</dc:creator><description>&lt;p&gt;Thank you very much, this solved my&amp;nbsp;issue!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Received indication data corrupt</title><link>https://devzone.nordicsemi.com/thread/135773?ContentTypeID=1</link><pubDate>Tue, 12 Jun 2018 14:41:32 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:7a12526f-a2e5-4f53-9b9e-84ae45ab1ee1</guid><dc:creator>tesc</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;You should not declare the variables for the ble_gap_evt_t pointer and the ble_gattc_evt_hvx_t event structure const. It looks like removing the const keywords on those two lines should make things work as intended.&lt;/p&gt;
&lt;p&gt;Regards,&lt;br /&gt;Terje&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Received indication data corrupt</title><link>https://devzone.nordicsemi.com/thread/135601?ContentTypeID=1</link><pubDate>Mon, 11 Jun 2018 13:25:26 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:1c561db4-d9b6-47b5-bea3-310ea37c08f9</guid><dc:creator>Martin Ziel</dc:creator><description>&lt;p&gt;Thank you for your answer. I excluded the sending side as the source of the error, because I have a working communication with a mobile and linux application. I&amp;#39;ve suspect it&amp;#39;s a memory layout problem or something with the interrupts of the softdevice, because the data is already corrupt when I read it from the hvx event.&lt;/p&gt;
&lt;p&gt;I&amp;#39;ve stripped the code down to the relevant bits:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;static uint32_t progress = 0;
static uint8_t received_data[80];

static void on_ble_evt(ble_evt_t * p_ble_evt)
{
    uint32_t              err_code = 0;
    const ble_gap_evt_t * p_gap_evt = &amp;amp;p_ble_evt-&amp;gt;evt.gap_evt;

    switch (p_ble_evt-&amp;gt;header.evt_id)
    {
        case BLE_GATTC_EVT_HVX:
            ;const ble_gattc_evt_hvx_t hvx_evt = p_ble_evt-&amp;gt;evt.gattc_evt.params.hvx;
            if(app_state == as_RECEIVE_DATA) {
                memcpy((void*)(&amp;amp;received_data[progress]), hvx_evt.data, hvx_evt.len);
                NRF_LOG_INFO(&amp;quot;Received indication data:\r\n&amp;quot;);
                    for(int i = 0; i &amp;lt; hvx_evt.len; i++) {
                        NRF_LOG_RAW_INFO(&amp;quot;%02x&amp;quot;, hvx_evt.data[i]);
                }
                NRF_LOG_INFO(&amp;quot;\r\n&amp;quot;);
                progress += hvx_evt.len;
            }
            if(hvx_evt.type == BLE_GATT_HVX_INDICATION) {
                err_code = sd_ble_gattc_hv_confirm(connection_handle, hvx_evt.handle);
                APP_ERROR_CHECK(err_code);
            }
            break;
    }
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Edit: I&amp;#39;ve written a small test case using another controller which sends out the string &amp;quot;Hello&amp;quot; via indication. On my receiving nRF51822, I only get He???, so I&amp;#39;m confident that the issue lies in the receiving end.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Received indication data corrupt</title><link>https://devzone.nordicsemi.com/thread/135586?ContentTypeID=1</link><pubDate>Mon, 11 Jun 2018 12:49:51 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:0b09cdfe-6ca7-4068-8f8c-0f7b3a0a9f52</guid><dc:creator>tesc</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;It is hard to tell without the source, but it sounds like something that could happen if the variable holding the data, either on the sending or receiving side, goes out of scope. Since the APIs work with pointers, it is important that the data is not placed somewhere in memory that gets popped off the stack once the function returns. That usually means the variable holding the data (in both ends) should be a &amp;quot;static uint8_t&amp;quot; array.&lt;/p&gt;
&lt;p&gt;Regards,&lt;br /&gt;Terje&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>