<?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>Unable to send more than 4 bytes of data over BLE</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/81506/unable-to-send-more-than-4-bytes-of-data-over-ble</link><description>Hi, I am trying to create a custom BLE service. 
 Following is the main code: 
 
 These are my BLE write functions: 
 
 
 My sdk_config file says MAX_MTU is defined 23 
 
 
 I am using nrf Connect to debug BLE, which gives me output like this: 
 0x A1</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Thu, 11 Nov 2021 11:46:48 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/81506/unable-to-send-more-than-4-bytes-of-data-over-ble" /><item><title>RE: Unable to send more than 4 bytes of data over BLE</title><link>https://devzone.nordicsemi.com/thread/338545?ContentTypeID=1</link><pubDate>Thu, 11 Nov 2021 11:46:48 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:01a77f2b-d799-45cd-8aac-fb68f42f1ef3</guid><dc:creator>_anurag</dc:creator><description>&lt;p&gt;Hi Einar,&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;
&lt;p&gt;Thanks for your response.&lt;br /&gt;I have fixed my issue and have been able to achieve a throughput of:&lt;/p&gt;
&lt;p&gt;200B at 20ms = 10kB/s&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;What solved the issue is Increasing:&lt;/p&gt;
&lt;div&gt;&lt;span style="color:#a91e1e;"&gt;NRF_SDH_BLE_GAP_DATA_LENGTH&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;div&gt;&lt;span style="color:#a91e1e;"&gt;NRF_SDH_BLE_GAP_EVENT_LENGTH&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;div&gt;&lt;span style="color:#a91e1e;"&gt;NRF_SDH_BLE_GATT_MAX_MTU_SIZE&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;pre style="text-align:left;"&gt;&lt;b style="color:#a91e1e;"&gt;hvn_tx_queue_size&lt;br /&gt;&lt;br /&gt;with little bit of tweaking&lt;/b&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;The following links were really helpful:&lt;br /&gt;&lt;a href="https://devzone.nordicsemi.com/f/nordic-q-a/35447/increase-hvn_tx_queue_size-to-maximize-throughput"&gt;increase-hvn_tx_queue_size-to-maximize-throughput&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href="https://devzone.nordicsemi.com/f/nordic-q-a/79875/nrf_error_resources-occurred-when-the-connection-is-disconnected/331070#331070"&gt;nrf_error_resources-occurred-when-the-connection-is-disconnected/331070#331070&lt;br /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Regards,&lt;/p&gt;
&lt;p&gt;Anurag&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Unable to send more than 4 bytes of data over BLE</title><link>https://devzone.nordicsemi.com/thread/338293?ContentTypeID=1</link><pubDate>Wed, 10 Nov 2021 07:25:40 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:97f0c591-6ee1-4dd7-ba68-8bf75fb4dba7</guid><dc:creator>Einar Thorsrud</dc:creator><description>[quote userid="110291" url="~/f/nordic-q-a/81506/unable-to-send-more-than-4-bytes-of-data-over-ble/338284#338284"]Can you suggest what might cause it?[/quote]
&lt;p&gt;You need to debug to understand what really happens. Is an error check hit? If so, which function is called and what error code does it return? Or if something else, what can you find from debugging? What state is your code in? Has any errors been detected, or could it be that it is stuck in an eternal loop somewhere (waiting for something that never happens), or some thing else?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Unable to send more than 4 bytes of data over BLE</title><link>https://devzone.nordicsemi.com/thread/338284?ContentTypeID=1</link><pubDate>Wed, 10 Nov 2021 05:47:22 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b0cb0b87-a530-413d-b629-220ab3c44eed</guid><dc:creator>_anurag</dc:creator><description>&lt;p&gt;Thanks,&lt;/p&gt;
&lt;p&gt;Right now, I am using nrfconnect to debug BLE.&lt;/p&gt;
&lt;p&gt;One issue is that I am able to fetch data when I am manually reading it by clicking on the download icon besides characteristics.&lt;/p&gt;
&lt;p&gt;But, when I am enabling notifications for auto-update, it crashes after a few reads.&lt;/p&gt;
&lt;p&gt;Can you suggest what might cause it?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Unable to send more than 4 bytes of data over BLE</title><link>https://devzone.nordicsemi.com/thread/338218?ContentTypeID=1</link><pubDate>Tue, 09 Nov 2021 14:35:04 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:4c32b5d5-af97-4378-8144-f8fba5699efb</guid><dc:creator>Einar Thorsrud</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
[quote user="_anurag"]&lt;p&gt;I will miss SPI data, because I am reading it every few ms.&lt;/p&gt;
&lt;p&gt;Isn&amp;#39;t there another way to take care of it?&lt;/p&gt;[/quote]
&lt;p&gt;That depends. You read data quite often, but not that much. You need to consider your connection parameters and event length etc. and configure that so that it is sensible for your use case. Then you need to consider if you should send each of these values as a single packet, or if yo should use data length extension (DLE) and concatenate this to fewer larger packets that you send less frequently.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Unable to send more than 4 bytes of data over BLE</title><link>https://devzone.nordicsemi.com/thread/338211?ContentTypeID=1</link><pubDate>Tue, 09 Nov 2021 14:22:55 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c0baccd7-f987-49f3-aa7e-3ceda4e23650</guid><dc:creator>_anurag</dc:creator><description>&lt;p&gt;Thanks, I will try to implement it.&lt;/p&gt;
&lt;p&gt;I am trying to read some 20 bytes on SPI (event-triggered from master device), if I wait for &amp;quot;BLE_GATTS_EVT_HVN_TX_COMPLETE&amp;quot;&lt;/p&gt;
&lt;p&gt;I will miss SPI data, because I am reading it every few ms.&lt;/p&gt;
&lt;p&gt;Isn&amp;#39;t there another way to take care of it?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Unable to send more than 4 bytes of data over BLE</title><link>https://devzone.nordicsemi.com/thread/338182?ContentTypeID=1</link><pubDate>Tue, 09 Nov 2021 13:23:23 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:4a7a5874-ee81-431c-be07-370e6e4cb7db</guid><dc:creator>Einar Thorsrud</dc:creator><description>&lt;p&gt;Hi&amp;nbsp;Anurag,&lt;/p&gt;
[quote user="_anurag"]&lt;p&gt;I am trying to implement BLE_ERROR_NO_TX_BUFFERS as described &lt;a href="https://devzone.nordicsemi.com/f/nordic-q-a/553/dealing-large-data-packet-s-through-ble"&gt;here&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;But, it gives me &amp;quot;undeclared error&amp;quot;, I have tried including &amp;quot;ble_err.h&amp;quot; with nomluck&lt;/p&gt;[/quote]
&lt;p&gt;That&amp;nbsp;thread is too old. There is no&amp;nbsp;BLE_ERROR_NO_TX_BUFFERS unless you are using an ancient SDK and SoftDevices version(?), which is why you get the error.&lt;/p&gt;
[quote user="_anurag"]Can you tell me which header contains &amp;quot;BLE_EVT_TX_COMPLETE &amp;quot;, I can try to include and call it.[/quote]
&lt;p&gt;Sorry, I wrote the last post from memory, and that does not&amp;nbsp;serve me too well it seems. Assuming you use a recent SDK version (17.x.x for instance) you will get NRF_ERROR_RESOURCES if the queue is full. Then you should wait for BLE_GATTS_EVT_HVN_TX_COMPLETE before you try again. (This is from ble_gatts.h. You get this as a BLE event in your BLE event handler.)&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Unable to send more than 4 bytes of data over BLE</title><link>https://devzone.nordicsemi.com/thread/338148?ContentTypeID=1</link><pubDate>Tue, 09 Nov 2021 11:57:19 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:dc671208-4e5e-4e44-bcb7-cfb2a4506238</guid><dc:creator>_anurag</dc:creator><description>&lt;p&gt;Hi Einar,&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;I am trying to implement BLE_ERROR_NO_TX_BUFFERS as described &lt;a href="https://devzone.nordicsemi.com/f/nordic-q-a/553/dealing-large-data-packet-s-through-ble"&gt;here&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;But, it gives me &amp;quot;undeclared error&amp;quot;, I have tried including &amp;quot;ble_err.h&amp;quot; with nomluck.&lt;br /&gt;Can you tell me which header contains &amp;quot;BLE_EVT_TX_COMPLETE &amp;quot;, I can try to include and call it.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Regards,&lt;/p&gt;
&lt;p&gt;Anurag&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Unable to send more than 4 bytes of data over BLE</title><link>https://devzone.nordicsemi.com/thread/338141?ContentTypeID=1</link><pubDate>Tue, 09 Nov 2021 11:45:02 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f0e3fed1-709c-4ca9-87b6-30bb0bdbef6a</guid><dc:creator>Einar Thorsrud</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;There is no fixed limit on how often you can call&amp;nbsp;sd_ble_gatts_hvx(), but if you call it too frequently so that there are no more buffers available it will return&amp;nbsp;NRF_ERROR_NO_MEM. In that case the best is normally to wait for a&amp;nbsp;BLE_EVT_TX_COMPLETE event before you try again.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Unable to send more than 4 bytes of data over BLE</title><link>https://devzone.nordicsemi.com/thread/338109?ContentTypeID=1</link><pubDate>Tue, 09 Nov 2021 10:16:09 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:7b23f94b-63ce-4ec2-a0c7-ffb1b8d0805d</guid><dc:creator>_anurag</dc:creator><description>&lt;p&gt;Thanks,&lt;/p&gt;
&lt;p&gt;I will start a new thread for this question.&lt;/p&gt;
&lt;p&gt;Can you just tell me if there is a limitation as to how often we can call ble write functions, like every 1 or 2 ms?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Unable to send more than 4 bytes of data over BLE</title><link>https://devzone.nordicsemi.com/thread/338089?ContentTypeID=1</link><pubDate>Tue, 09 Nov 2021 09:43:27 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a2737242-cc83-4a91-a4a9-4175954a266a</guid><dc:creator>Einar Thorsrud</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;There is no information here about &lt;em&gt;what&lt;/em&gt; caused the error. However, the error handler is hit, so you can find more information by using a debug build. In that case, you will see which error code was detected at which line number in which file. If you are using SES, then simply select the &amp;quot;Debug&amp;quot; build target and test again. If using something else, define &amp;quot;DEBUG&amp;quot; for the project. See &lt;a href="https://devzone.nordicsemi.com/nordic/nordic-blog/b/blog/posts/an-introduction-to-error-handling-in-nrf5-projects"&gt;An introduction to error handling in nRF5 projects&lt;/a&gt;&amp;nbsp;for more about this.&lt;/p&gt;
&lt;p&gt;PS: This thread was automatically locked as you verified the answer to the original question, but I unlocked it in order to answer the second question. Please make new threads for new questions in the future.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Unable to send more than 4 bytes of data over BLE</title><link>https://devzone.nordicsemi.com/thread/338085?ContentTypeID=1</link><pubDate>Tue, 09 Nov 2021 09:23:47 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d5865c0e-9b93-4f65-8335-d495effdddc3</guid><dc:creator>_anurag</dc:creator><description>&lt;p&gt;Hi Einar,&lt;br /&gt;&lt;br /&gt;Thanks for the response, I have resolved the issue as following:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;uint32_t ble_cus_flash_update(ble_cus_t * p_cus, uint8_t * flash_data_byte, uint16_t len, uint16_t conn_handle)
{
    ble_gatts_hvx_params_t params;

    memset(&amp;amp;params, 0, sizeof(params));
    params.type   = BLE_GATT_HVX_NOTIFICATION;
    params.handle = p_cus-&amp;gt;flash_handles.value_handle;
    params.p_data = flash_data_byte;
    params.p_len  = &amp;amp;len;

    return sd_ble_gatts_hvx(conn_handle, &amp;amp;params);
}
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Though I am getting another Issue, when I am enabling notifications in the nrfGo app, my program crashes with a hard fault.&lt;/p&gt;
&lt;p&gt;I am sending 50 bytes of data at 100 ms intervals.&lt;/p&gt;
&lt;p&gt;This is the location of Hard fault:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;void app_error_handler_bare(ret_code_t error_code)
{
    error_info_t error_info =
    {
        .line_num    = 0,
        .p_file_name = NULL,
        .err_code    = error_code,
    };

    app_error_fault_handler(NRF_FAULT_ID_SDK_ERROR, 0, (uint32_t)(&amp;amp;error_info));

    UNUSED_VARIABLE(error_info);
}&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Unable to send more than 4 bytes of data over BLE</title><link>https://devzone.nordicsemi.com/thread/338075?ContentTypeID=1</link><pubDate>Tue, 09 Nov 2021 09:09:19 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:e49bdc26-6f17-40cb-8b81-8f38eb87ff1a</guid><dc:creator>Einar Thorsrud</dc:creator><description>&lt;p&gt;Hi&amp;nbsp;Anurag,&lt;/p&gt;
&lt;p&gt;The problem here is that the size you specify is always 4. See this part of your code:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;uint32_t ble_cus_flash_update(ble_cus_t * p_cus, uint8_t * flash_data_byte, uint16_t conn_handle)
{
    ble_gatts_hvx_params_t params;
    uint16_t len = sizeof(flash_data_byte);&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Here the len variable is set to the sizeof a pointer, which is always 4 byte. This is not what you want. There is no way to know the length of the input in this function, so you must&amp;nbsp;pass the length&amp;nbsp;as an additional parameter.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>