<?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>Can you not call sd_ble_gatts_hvx() in a loop?</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/25637/can-you-not-call-sd_ble_gatts_hvx-in-a-loop</link><description>I basically need clarification on the last point of this question , which seems to imply that:
the first time you call sd_ble_gatts_hvx() while the SoftDevice&amp;#39;s transmit buffer is full, it reliably returns NRF_ERROR_RESOURCES, but you should not call</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Mon, 16 Oct 2017 10:58:29 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/25637/can-you-not-call-sd_ble_gatts_hvx-in-a-loop" /><item><title>RE: Can you not call sd_ble_gatts_hvx() in a loop?</title><link>https://devzone.nordicsemi.com/thread/101022?ContentTypeID=1</link><pubDate>Mon, 16 Oct 2017 10:58:29 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a4aa3526-ff6c-4aa0-8b89-727ab2169898</guid><dc:creator>Sigurd</dc:creator><description>&lt;p&gt;Does it work fine when you only use 1 sd_ble_gatts_hvx in the event handler? How big it your &lt;code&gt;hvn_tx_queue_size&lt;/code&gt; ?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Can you not call sd_ble_gatts_hvx() in a loop?</title><link>https://devzone.nordicsemi.com/thread/101021?ContentTypeID=1</link><pubDate>Wed, 11 Oct 2017 16:13:26 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:bb50ecdf-865c-4513-858c-aebfca691310</guid><dc:creator>Elias</dc:creator><description>&lt;p&gt;I&amp;#39;m having a different problem with the same piece of code now: is there any reason that calling sd_ble_gatts_hvx() in a loop would prevent transmission? Usually, it works, but there&amp;#39;s one scenario in my application where the loop consistently gets stuck with sd_ble_gatts_hvx returning NRF_ERROR_RESOURCES. It looks like a transmission event never happens because I never see the last successful sd_ble_gatts_hvx packet at the peer, and this causes that loop to repeat indefinitely.&lt;/p&gt;
&lt;p&gt;I think the unique thing about the scenario is that it&amp;#39;s the first time I&amp;#39;m trying two sd_ble_gatts_hvx loops within the &lt;em&gt;same&lt;/em&gt; event handler, rather than looping until one packet is queued and then returning control to the SoftDevice before I try another loop.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Can you not call sd_ble_gatts_hvx() in a loop?</title><link>https://devzone.nordicsemi.com/thread/101020?ContentTypeID=1</link><pubDate>Tue, 03 Oct 2017 10:32:35 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:66264c84-42bd-4a70-a317-39e3ec26bf2d</guid><dc:creator>Sigurd</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;The number of Handle Value Notifications that can be queued is configured by &lt;a href="https://infocenter.nordicsemi.com/topic/com.nordic.infocenter.s132.api.v5.0.0/structble__gatts__conn__cfg__t.html?cp=2_3_0_1_0_2_4_4_0"&gt;ble_gatts_conn_cfg_t::hvn_tx_queue_size&lt;/a&gt;. When the queue is full, the function &lt;code&gt;sd_ble_gatts_hvx()&lt;/code&gt; will return &lt;code&gt;NRF_ERROR_RESOURCES&lt;/code&gt;. A &lt;code&gt;BLE_GATTS_EVT_HVN_TX_COMPLETE&lt;/code&gt; event will be issued as soon as the transmission of the notification is complete.&lt;/p&gt;
&lt;p&gt;You have 2 options, either call &lt;code&gt;sd_ble_gatts_hvx()&lt;/code&gt; in a loop until the function returns &lt;code&gt;NRF_SUCCESS&lt;/code&gt;, or wait for the &lt;code&gt;BLE_GATTS_EVT_HVN_TX_COMPLETE&lt;/code&gt; and then send the next packet. There is no race condition here.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>