<?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>Understanding BLE_EVT_TX_COMPLETE events</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/72007/understanding-ble_evt_tx_complete-events</link><description>I am sending a data packet by notification that spans many MTU sizes. So I do a loop over the sd_ble_gatts_hvx(m_connection_handle, &amp;amp;hvx_params) method until I get a BLE_ERROR_NO_TX_PACKETS error. Now I have to wait for the BLE_EVT_TX_COMPLETE event before</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Thu, 25 Feb 2021 12:39:18 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/72007/understanding-ble_evt_tx_complete-events" /><item><title>RE: Understanding BLE_EVT_TX_COMPLETE events</title><link>https://devzone.nordicsemi.com/thread/296250?ContentTypeID=1</link><pubDate>Thu, 25 Feb 2021 12:39:18 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:50b0ee4f-3952-4a75-97d4-7c67174cdb40</guid><dc:creator>Einar Thorsrud</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
[quote user="brianreinhold"]I did not realize that notifications were acknowledged at any layer, but I guess they have to be in some sense just to keep the &amp;#39;heartbeat&amp;#39; alive.[/quote]
&lt;p&gt;Not just that. BLE provide data integrity so all data packets are acknowledged (or retransmitted if necessary) on the link layer.&lt;/p&gt;
[quote user="brianreinhold"]You say above that I will get another&amp;nbsp;&lt;span&gt;BLE_ERROR_NO_TX_PACKETS if I send an indication before all my notifications have been evented (I realize that one&amp;nbsp;BLE_EVT_TX_COMPLETE&amp;nbsp;event may encompass more than one notification and I take that into account).&lt;/span&gt;[/quote]
&lt;p&gt;I didn&amp;#39;t mean to say that. But if the buffer is full, then one packet has to be successfully transmitted (meaning also acknowledged by the peer) before it can be freed so that another packet can be queued. The Tx buffer does not need to be emptied completely.&lt;/p&gt;
[quote user="brianreinhold"]However, I am confused about getting a&amp;nbsp;BLE_ERROR_NO_TX_PACKETS if I send an indication before all my notifications have been evented. My understanding from the documentation is that I can only get a&amp;nbsp;BLE_ERROR_NO_TX_PACKETS&amp;nbsp;from notifications. Indications will generate an NRF_ERROR_BUSY error only. Is that not true?[/quote]
&lt;p&gt;No, you are right.&amp;nbsp;I should have refreshed my memory there. That makes sense, as an indications needs to be acked by the peer&amp;#39;s app layer before another can be queued.&lt;/p&gt;
[quote user="brianreinhold"]&lt;strong&gt;Another thing I want to understand&lt;/strong&gt; - if I get more than one notification evented in the&amp;nbsp;BLE_EVT_TX_COMPLETE event does that means more than one notification went out in a single connection interval?[/quote]
&lt;p&gt;Yes. But it is not necessarily the other way around. You could get more&amp;nbsp;BLE_EVT_TX_COMPLETE events for the same connection event.&lt;/p&gt;
[quote user="brianreinhold"]&lt;span style="color:rgba(0, 0, 255, 1);"&gt;&lt;strong&gt;Yet another thing&lt;/strong&gt;&lt;/span&gt;: If I send notifications with 1 byte per notification versus 10 bytes per notification as fast as I can, in which case will I exhaust the buffers the fastest?[/quote]
&lt;p&gt;The buffer has a fixed number of elements (for old SoftDevices that is 1, 3 or 6 depending on bandwidth configuration), and those are scaled for the maximum size packets. But you cannot fit more than the specified number of packets, so 6 packets is max with high bandwidth configuration, even if the payload is only 1 byte.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Understanding BLE_EVT_TX_COMPLETE events</title><link>https://devzone.nordicsemi.com/thread/296201?ContentTypeID=1</link><pubDate>Thu, 25 Feb 2021 10:38:56 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:69088027-8ef2-42b5-a4f0-f9fdda0431d9</guid><dc:creator>brianreinhold</dc:creator><description>&lt;p&gt;I did not realize that notifications were acknowledged at any layer, but I guess they have to be in some sense just to keep the &amp;#39;heartbeat&amp;#39; alive.&lt;/p&gt;
&lt;p&gt;You say above that I will get another&amp;nbsp;&lt;span&gt;BLE_ERROR_NO_TX_PACKETS if I send an indication before all my notifications have been evented (I realize that one&amp;nbsp;BLE_EVT_TX_COMPLETE&amp;nbsp;event may encompass more than one notification and I take that into account).&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;However, I am confused about getting a&amp;nbsp;BLE_ERROR_NO_TX_PACKETS if I send an indication before all my notifications have been evented. My understanding from the documentation is that I can only get a&amp;nbsp;BLE_ERROR_NO_TX_PACKETS&amp;nbsp;from notifications. Indications will generate an NRF_ERROR_BUSY error only. Is that not true?&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;strong&gt;Another thing I want to understand&lt;/strong&gt; - if I get more than one notification evented in the&amp;nbsp;BLE_EVT_TX_COMPLETE event does that means more than one notification went out in a single connection interval? I note that 90% of my notifications generate a&amp;nbsp;BLE_EVT_TX_COMPLETE with only a single notification. That&amp;#39;s a little disappointing. I&amp;#39;m pushing only 20 bytes per notification in the characteristic value.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;span style="color:#0000ff;"&gt;&lt;strong&gt;Yet another thing&lt;/strong&gt;&lt;/span&gt;: If I send notifications with 1 byte per notification versus 10 bytes per notification as fast as I can, in which case will I exhaust the buffers the fastest? IN which case will&amp;nbsp; I have sent more bytes by the time the buffers are exhausted? Which is the fastest way to deliver data to the peer?&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Understanding BLE_EVT_TX_COMPLETE events</title><link>https://devzone.nordicsemi.com/thread/296197?ContentTypeID=1</link><pubDate>Thu, 25 Feb 2021 10:28:03 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f9d4fcc2-fb39-44cb-bfbe-852f40860f92</guid><dc:creator>Einar Thorsrud</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;The BLE_EVT_TX_COMPLETE is typically raised every time a packet has been transmitted.&amp;nbsp;However, sometimes when more packets are sent in the same connection event you may not get this event for each. Therefor you must also check the count field in the &lt;a href="https://infocenter.nordicsemi.com/topic/com.nordic.infocenter.s130.api.v2.0.1/structble__evt__tx__complete__t.html"&gt;ble_evt_tx_complete_t&lt;/a&gt;&amp;nbsp;struct you get with the event.&lt;/p&gt;
[quote user=""]The question is when can I start doing the indication? I finish doing all the notifications before all the&amp;nbsp;BLE_EVT_TX_COMPLETE events have been received; a good tenth of a second before all&amp;nbsp;BLE_EVT_TX_COMPLETE events have been received. Can I start sending indications BEFORE all the&amp;nbsp;BLE_EVT_TX_COMPLETE events have been received or will I just get an NRF_ERROR_BUSY error?[/quote]
&lt;p&gt;You need to wait for the&amp;nbsp;BLE_EVT_TX_COMPLETE event to be sure that a buffer has been freed. There is no way to know before this. You could of course try and just live with another BLE_ERROR_NO_TX_PACKETS error if spending a bit of extra CPU time is not problem.&lt;/p&gt;
[quote user=""]In other words, &lt;span style="color:rgba(0, 0, 255, 1);"&gt;&lt;strong&gt;if I send a notification and receive no error, is that packet out the door?&lt;/strong&gt;&lt;/span&gt;[/quote]
&lt;p&gt;No. The packet will remain buffered by the SoftDevice until it is acknowledged by the peer (or the link is disconnected due to supervision timeout).&lt;/p&gt;
[quote user=""]Additionally, if that happens to be the last notification I need to send for that data packet, can I immediately start sending an indication?[/quote]
&lt;p&gt;No. The same buffer is used for both notifications and indications.&lt;/p&gt;
[quote user=""]&lt;strong&gt;&lt;span style="color:rgba(0, 0, 255, 1);"&gt;Please explain the relation between sending a notification, having the notification successfully on its way to the peer, and the&amp;nbsp;BLE_EVT_TX_COMPLETE events&lt;/span&gt;&lt;/strong&gt;.[/quote]
&lt;p&gt;When you send a notification, you really just queue it. Then it is sent and potentially retransmitted several times before it is acknowledged by the peer. Once acknowledged the buffer is freed and you get a&amp;nbsp;BLE_EVT_TX_COMPLETE event. If it was a indication instead of a notification it would have to be acknowledged by the application layer as well, which takes more time (see &lt;a href="https://devzone.nordicsemi.com/f/nordic-q-a/99/notification-indication-difference/533#533"&gt;this old post&lt;/a&gt;).&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>