<?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>BLE nus slow transmitting after being connected for a while</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/62099/ble-nus-slow-transmitting-after-being-connected-for-a-while</link><description>Hi, 
 I have implemented BLE nus uart on my device and am getting some weird problems with the transfer speed. 
 When I connect to the device and transfer data via BLE nus to the mobile phone the data is transferred very quickly, however, if I keep the</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Mon, 08 Jun 2020 09:46:44 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/62099/ble-nus-slow-transmitting-after-being-connected-for-a-while" /><item><title>RE: BLE nus slow transmitting after being connected for a while</title><link>https://devzone.nordicsemi.com/thread/253736?ContentTypeID=1</link><pubDate>Mon, 08 Jun 2020 09:46:44 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:187a8577-c70e-42bc-990d-577f1d94189c</guid><dc:creator>Edvin</dc:creator><description>&lt;p&gt;Hello,&lt;/p&gt;
&lt;p&gt;The app_uart and app_fifo get are open source, so you can check why it returns NRF_ERROR_NOT_FOUND:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;uint32_t app_fifo_get(app_fifo_t * p_fifo, uint8_t * p_byte)
{
    if (FIFO_LENGTH() != 0)
    {
        fifo_get(p_fifo, p_byte);
        return NRF_SUCCESS;
    }

    return NRF_ERROR_NOT_FOUND;

}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;And you can see that FIFO_LENGTH() is a macro:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;#define FIFO_LENGTH(F) fifo_length(&amp;amp;F)              /**&amp;lt; Macro to calculate length of a FIFO. */

//where fifo_length(&amp;amp;F):

static __INLINE uint32_t fifo_length(app_fifo_t * const fifo)
{
  uint32_t tmp = fifo-&amp;gt;read_pos;
  return fifo-&amp;gt;write_pos - tmp;
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;So I believe you are trying to read out the UART data, when you haven&amp;#39;t received any data yet (you have read out all you have received). You should wait for the&amp;nbsp;uart_event_handle() event before you read out the next byte.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;BR,&lt;/p&gt;
&lt;p&gt;Edvin&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: BLE nus slow transmitting after being connected for a while</title><link>https://devzone.nordicsemi.com/thread/253610?ContentTypeID=1</link><pubDate>Fri, 05 Jun 2020 19:48:01 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:9cc14c65-b503-412b-9f1d-9eec283281eb</guid><dc:creator>Hadi Deknache</dc:creator><description>&lt;p&gt;Ok, I seem to have traced the error where it seem to be stuck. When checking the prints it seem to be stuck in a while loop which is trying to do&amp;nbsp;app_uart_get() and is returning error 5 from&amp;nbsp;app_fifo_get(), I assume that this error is&amp;nbsp;NRF_ERROR_NOT_FOUND. Am I correct?&lt;/p&gt;
&lt;p&gt;app_uart_get is fetching uart from the second processor but is returning this error. What could be causing this problem? Why is it triggering this error?&lt;/p&gt;
&lt;p&gt;Also, sometimes I also receive APP_UART_COMMUNICATION_ERROR, what could cause this error? It seem like it is losing some packages which cause the data to be incomplete. Is there some way to fix this issue?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: BLE nus slow transmitting after being connected for a while</title><link>https://devzone.nordicsemi.com/thread/253278?ContentTypeID=1</link><pubDate>Thu, 04 Jun 2020 12:01:18 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:ce86b3f2-00d8-49ef-b519-28c6aea59b03</guid><dc:creator>Edvin</dc:creator><description>&lt;p&gt;Try some debugging. Check how fast you can usually queue packets when you connect, and how many you can queue &amp;quot;after a while&amp;quot;.&lt;/p&gt;
&lt;p&gt;Please note that the connection interval is decided by the central. You can ask for certain parameters on the peripheral, but it is the phone (iPhone) that decides. You may not use the connection interval that you think.&lt;/p&gt;
&lt;p&gt;It is very hard for me to say whats going on here. Try to print a message every time you successfully queue a packet, and print the length of the queued packet. What does it look like at first, and after a while? Does it look like it is slowing down?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: BLE nus slow transmitting after being connected for a while</title><link>https://devzone.nordicsemi.com/thread/253210?ContentTypeID=1</link><pubDate>Thu, 04 Jun 2020 09:02:35 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c4172fc0-772b-40e4-b405-d52c96013ede</guid><dc:creator>Hadi Deknache</dc:creator><description>&lt;p&gt;Yes, the other processor which is sending the data is still alive and waiting for the nrf ble module to send an ack when it has sent everything to the mobile phone. Since the processor doesn&amp;#39;t send any ack it times out after 20 seconds and restarts the ble as it seem to have been stuck/frozen.&lt;/p&gt;
&lt;p&gt;Exactly, my bad. The error is as you say NRF_ERRO_RESOURCES is what I get sometimes. However, the last thing I get when debugging and performing&amp;nbsp;&lt;span&gt;ble_nus_data_send()&lt;/span&gt; is this error:&lt;/p&gt;
&lt;p&gt;&amp;lt;info&amp;gt; app: Sending NUS data! 0x0&lt;br /&gt;&amp;lt;info&amp;gt; app: DONE!&lt;/p&gt;
&lt;p&gt;The connection intervals I change between are these:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;// Connection Interval and timeout for slow connection
#define SLOW_MIN_CONN_INTERVAL MSEC_TO_UNITS(180, UNIT_1_25_MS)
#define SLOW_MAX_CONN_INTERVAL MSEC_TO_UNITS(375, UNIT_1_25_MS) 
#define SLOW_CONN_SUP_TIMEOUT  MSEC_TO_UNITS(6000, UNIT_10_MS)
#define SLOW_SLAVE_LATENCY     4

// Connection Interval and timeout for fast connection
#define FAST_MIN_CONN_INTERVAL MSEC_TO_UNITS(7.5, UNIT_1_25_MS) 
#define FAST_MAX_CONN_INTERVAL MSEC_TO_UNITS(15, UNIT_1_25_MS)
#define FAST_CONN_SUP_TIMEOUT  MSEC_TO_UNITS(5000, UNIT_10_MS)
#define FAST_SLAVE_LATENCY     4

// Time from initiating event (connect or start of notification) to first time
// sd_ble_gap_conn_param_update is called (20 seconds).
#define FIRST_CONN_PARAMS_UPDATE_DELAY APP_TIMER_TICKS(20000)

// Time between each call to sd_ble_gap_conn_param_update after the first call
// (5 seconds).
#define NEXT_CONN_PARAMS_UPDATE_DELAY  APP_TIMER_TICKS(5000)

// Number of attemps before giving up connection parameter negotiation
#define MAX_CONN_PARAMS_UPDATE_COUNT   3&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;So normally I use slow, when there is a request from the mobile application, it switches to fast and wait for it to success and then start sending.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;When the nrf device freezes, I seem to not get any more prints in any of the other places. It seem like it just locked itself somehow or maybe hard faulted I don&amp;#39;t know what is actually happening, but seem like it just stops.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: BLE nus slow transmitting after being connected for a while</title><link>https://devzone.nordicsemi.com/thread/253206?ContentTypeID=1</link><pubDate>Thu, 04 Jun 2020 08:54:23 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:6061aa8c-8adf-4622-b01c-6a21b614233b</guid><dc:creator>Edvin</dc:creator><description>[quote user="Hadi Deknache"]I just want to mention that I have a second processor that is sending some&amp;nbsp;UART data with the nrf ble module. Could is somehow cause any trouble? The second processor is sending data to the nrf module which then transfers it to the mobile.[/quote]
&lt;p&gt;&amp;nbsp;I don&amp;#39;t know. You need to debug. When you &amp;quot;freeze&amp;quot;, is the processor running, or has your application crashed?&amp;nbsp;Have you tried to monitor the log from the nRF? Does it say anything when it freezes?&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Please check the return values for a given softdevice call. For&amp;nbsp;ble_nus_data_send(), that would be&amp;nbsp;sd_ble_gatts_hvx(). In ble_gatts.h you can see the possible return values.&lt;/p&gt;
&lt;p&gt;NRF_ERROR_TIMEOUT is 13 (0x0D), while NRF_ERROR_RESOURCES is 19 (0x13). You see the 19, right? So you get an NRF_ERROR_RESOURCES, meaning that the queue is full (which is a good thing if you try to send as much as possible because you have filled the queue.&lt;/p&gt;
&lt;p&gt;So let&amp;#39;s try another approach then. What is the connection interval changed to after a while?&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;To sum up.&lt;/p&gt;
&lt;p&gt;1: What happenes at the &amp;quot;freeze&amp;quot;?&lt;/p&gt;
&lt;p&gt;2: What is your connection interval &amp;quot;after a while&amp;quot;?&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;And what are the actual rates that you are seeing? What determines how fast you are trying to send? The incoming UART? And how fast is that?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: BLE nus slow transmitting after being connected for a while</title><link>https://devzone.nordicsemi.com/thread/253175?ContentTypeID=1</link><pubDate>Thu, 04 Jun 2020 07:24:45 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:8c841be6-6868-450a-874f-cdf634967b3d</guid><dc:creator>Hadi Deknache</dc:creator><description>&lt;p&gt;Hi Edvin,&lt;/p&gt;
&lt;p&gt;Yes it seem that the app still is waiting for the data to be sent and phone still appear as connected. To get the device out of the freeze i&amp;#39;ll have to restart the device. I have checked the return status and it seem that sometimes it give 0x13(timeout?) and then we keep retrying until it gives us 0x0(success). The problem is that when we first send it, the transmission is extremely fast but after a while or during the second send it is very slow and laggy.&lt;/p&gt;
&lt;p&gt;What I have observed before the board freeze is that it successfully sends and then it freezes afterwards. I just want to mention that I have a second processor that is sending some&amp;nbsp;UART data with the nrf ble module. Could is somehow cause any trouble? The second processor is sending data to the nrf module which then transfers it to the mobile.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: BLE nus slow transmitting after being connected for a while</title><link>https://devzone.nordicsemi.com/thread/253162?ContentTypeID=1</link><pubDate>Thu, 04 Jun 2020 06:39:05 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:4e2c7a0a-5dad-49ad-a8cf-cd2c8e6c80d4</guid><dc:creator>Edvin</dc:creator><description>[quote user="Hadi Deknache"]If I have waited like for more than 4-5 minutes the device even freezes and I&amp;#39;ll have to reset the device manually[/quote]
&lt;p&gt;&amp;nbsp;You need to do some debugging to figure out whats going on here. Are you still connected after the freeze? (does the phone say that they are connected?)&lt;/p&gt;
&lt;p&gt;What does the call to ble_nus_data_send() return?&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: BLE nus slow transmitting after being connected for a while</title><link>https://devzone.nordicsemi.com/thread/253069?ContentTypeID=1</link><pubDate>Wed, 03 Jun 2020 14:37:54 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:daeed6c3-c74a-4455-9d84-66298072b3d6</guid><dc:creator>Hadi Deknache</dc:creator><description>&lt;p&gt;Hello,&lt;/p&gt;
&lt;p&gt;Thank you for the immediate support!&lt;/p&gt;
&lt;p&gt;No, I haven&amp;#39;t tried nRF sniffer as I currently only have one dev board that is in used already. Will check if I might have an extra that I could setup as a sniffer.&lt;/p&gt;
&lt;p&gt;As I do it currently is that whenever I receive an init package from the mobile app, I update the connection interval to fast instead of slow. Afterwards I start packaging data available on the&amp;nbsp;nRF device and&amp;nbsp;send it to the mobile phone. The data could sometime be large chunks but also small. The problem I&amp;#39;ve observed is that when starting the sending directly after connecting to the device it is much more faster than when sending again or waiting for a few minutes and then sending the data. If I have waited like for more than 4-5 minutes the device even freezes and I&amp;#39;ll have to reset the device manually.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: BLE nus slow transmitting after being connected for a while</title><link>https://devzone.nordicsemi.com/thread/253045?ContentTypeID=1</link><pubDate>Wed, 03 Jun 2020 13:40:34 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:cd42de59-d7bf-43d9-8608-ffe83245c650</guid><dc:creator>Edvin</dc:creator><description>&lt;p&gt;Hello,&lt;/p&gt;
&lt;p&gt;Changing the connection interval may affect the tranfer rate, but this is a quite complex topic. Check out the&amp;nbsp;ble_app_att_mtu_throughput example to see how the connection parameters is affecting the transfer rate.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Have you tried sniffing the connection using &lt;a href="https://www.nordicsemi.com/Software-and-tools/Development-Tools/nRF-Sniffer-for-Bluetooth-LE" rel="noopener noreferrer" target="_blank"&gt;nRF Sniffer&lt;/a&gt;? Are there any connection parameter updates when the transfer rate is going slow? Is there anything changing from your application? Are you starting to send smaller packets? How do you queue the packets? Do you wait for one packet to be completed (TX COMPLETE) before queuing the next, or do you queue them as soon as you can, until it returns NRF_ERROR_RESOURCES?&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;BR,&lt;/p&gt;
&lt;p&gt;Edvin&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>