<?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>Increasing bluetooth speed without blocking other peripherals</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/87339/increasing-bluetooth-speed-without-blocking-other-peripherals</link><description>Hi, 
 
 I&amp;#39;m putting together some firmware that takes packets received over SPI and then streams them over BLE. I&amp;#39;m trying to run the BLE at close to 1Mb/s (which is still within spec from my understanding) but I&amp;#39;m getting some inconsistent packet dropping</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Fri, 06 May 2022 21:04:50 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/87339/increasing-bluetooth-speed-without-blocking-other-peripherals" /><item><title>RE: Increasing bluetooth speed without blocking other peripherals</title><link>https://devzone.nordicsemi.com/thread/366786?ContentTypeID=1</link><pubDate>Fri, 06 May 2022 21:04:50 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:99d4e27f-d8a9-481e-8a35-890418a946f5</guid><dc:creator>ryerye120</dc:creator><description>&lt;p&gt;Hi Simon,&lt;/p&gt;
&lt;p&gt;In the end, I think I&amp;#39;ve figured it all out, let me summarize my issue and solution below for any other people who may come to this thread:&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;
&lt;p&gt;My main problem was that my bluetooth transfers were blocking my spi transfers from happening as often as I wanted to. This was because my bluetooth transfers were occurring in the spi_interrupt_handler with the following code:&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;while(ble_nus_data_send(&amp;amp;m_nus, ble_tx_buf, &amp;amp;ble_packet_length, m_conn_handle) != NRF_SUCCESS);&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;
&lt;p&gt;So I removed the while loop but then I ran into the problem that ble_nus_data_send() wouldn&amp;#39;t actually complete properly by the next spi transaction (meaning only 1/5 calls to ble_nus_data_send() were actually successful).&lt;br /&gt;&lt;br /&gt;In order to solve this I had to make&amp;nbsp;4 changes:&lt;br /&gt;&lt;br /&gt;1) enable data length extension (so that multiple packets could be sent during a single connection)&lt;br /&gt;2) Increase my HVN queue size to 400 (so that the notification system would queue any notifications that couldn&amp;#39;t be sent in time - this gives me a little leeway in case there are any flukes)&lt;br /&gt;3) Adjusting my ble stack settings to achieve a theoretical throughput of 1.2 Mbps (I figured these out by&amp;nbsp;testing different parameters&amp;nbsp;in the ble_app_mtu_throughput example)&lt;br /&gt;4) I began double buffering and adding a check in the CPU to retry sending the packet if ble_nus_data_send doesn&amp;#39;t return success.&lt;/p&gt;
&lt;p&gt;Furthermore, to answer my earlier question - In order to send multiple packets during a single connection, all you need to do is call ble_nus_data_send() multiple times. If you have an HVN queue large enough, all of your packets will get queued and sent without you having to worry.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Increasing bluetooth speed without blocking other peripherals</title><link>https://devzone.nordicsemi.com/thread/365795?ContentTypeID=1</link><pubDate>Mon, 02 May 2022 13:10:46 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:2a987198-941e-4a88-8257-b92292299197</guid><dc:creator>Simonr</dc:creator><description>&lt;p&gt;Hi Ryan&lt;/p&gt;
&lt;p&gt;The sample project that is used in the novelbits blog post is the &lt;a href="https://infocenter.nordicsemi.com/topic/sdk_nrf5_v17.1.0/ble_sdk_app_att_mtu.html"&gt;ble_app_mtu_throughput &lt;/a&gt;example that lets you transmit longer packets (up to 247 bytes in a packet).&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Simon&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Increasing bluetooth speed without blocking other peripherals</title><link>https://devzone.nordicsemi.com/thread/365646?ContentTypeID=1</link><pubDate>Fri, 29 Apr 2022 21:37:33 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:1d1a87b8-409d-4ea2-a7c5-278745427885</guid><dc:creator>ryerye120</dc:creator><description>&lt;p&gt;Hi Simon,&lt;/p&gt;
&lt;p&gt;I built the SPI functions off of the nrfx_spim example, yes! And exactly, right - I used ble_app_uart to get data from a serial device and send that over BLE. Double buffering makes a lot of sense - I&amp;#39;ll implement a double buffer scheme.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;I read through the novelbits blog post (thanks for the link!) and it mentions sending multiple packets within a single connection interval. That&amp;#39;s ultimately what I&amp;#39;m trying to do but I don&amp;#39;t know how to do it haha. How can I go about sending multiple packets in a single connection interval? Is there a way to feed a larger packet and have a subfunction break it up? Or do I just need to call&amp;nbsp;&lt;span&gt;ble_nus_data_send() over and over again and trust that it will handle it?&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Kindest regards,&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Ryan&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Increasing bluetooth speed without blocking other peripherals</title><link>https://devzone.nordicsemi.com/thread/365560?ContentTypeID=1</link><pubDate>Fri, 29 Apr 2022 10:56:33 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:2af350c9-efe1-42fb-8011-5e99a5db3155</guid><dc:creator>Simonr</dc:creator><description>&lt;p&gt;Hi&lt;/p&gt;
&lt;p&gt;It seems like you&amp;#39;re on the right track. You&amp;#39;re using the SPI example for SPI communication I presume, and the ble_app_uart example to see how we get data from a serial device and send that data over BLE? If you&amp;#39;re struggling with the buffer being taken by the radio peripheral, hindering the SPI from transmitting data, you can do double buffering. Good discussion on that &lt;a href="https://devzone.nordicsemi.com/f/nordic-q-a/67213/clarification-on-spi-double-buffer-and-events_ready/"&gt;here&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Trying to transmit more than&amp;nbsp;251 bytes in one BLE packet would result in an error as that would be outide of the BLE specification. This is very well explained in &lt;a href="https://www.novelbits.io/bluetooth-5-speed-maximum-throughput/"&gt;this Novelbits blog post&lt;/a&gt;. It also explains how BLE packets are built up.&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Simon&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Increasing bluetooth speed without blocking other peripherals</title><link>https://devzone.nordicsemi.com/thread/365477?ContentTypeID=1</link><pubDate>Thu, 28 Apr 2022 16:45:05 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:eb641d3c-663c-4927-90c5-76ea6152f303</guid><dc:creator>ryerye120</dc:creator><description>&lt;p&gt;Hi Simon,&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Thank you for the pointer! A previous post had pointed me to the ble_app_uart example but it seems like it might not actually use the queued writes module.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Unfortunately, I may be barking up the wrong tree here - I was reading this &lt;a href="https://devzone.nordicsemi.com/f/nordic-q-a/43140/queued-write-module"&gt;post&lt;/a&gt;&amp;nbsp;and they mention:&lt;pre class="ui-code" data-mode="text"&gt;that queued writes only make sense if you want to synchronize 
writes to multiple characteristics, so that the change take 
effect simultaneously.&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;That&amp;#39;s not actually what I want to do. I really just want to send a large amount of data at a fast rate without breaking my SPI. Furthermore, from looking through everything it seems that the central device is the one that actually uses the &amp;quot;queued writes&amp;quot; and peripheral devices just receive them (or am I wrong there?).&lt;br /&gt;&lt;br /&gt;Looking back I should have stated this in the original post: &lt;strong&gt;my problem is that my peripheral device needs to perform SPI transactions every 500us and I need to send all&amp;nbsp;this&amp;nbsp;SPI&amp;nbsp;data over BLE &lt;span style="text-decoration:underline;"&gt;without halting the SPI operations&lt;/span&gt;.&amp;nbsp;&lt;/strong&gt;I know for a fact people have done this sort of thing before, but it seems I&amp;#39;m terrible at googling it because I only ever get my forum posts hahaha.&lt;/p&gt;
&lt;p&gt;Is there a way to run the BLE in parallel with SPI? If so, does it involve using the SPI interrupt and CPU bound BLE_transfers?&amp;nbsp;&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;
&lt;p&gt;Do you know what would happen if I gave the (ble_nus_data_send) a packet that was larger than 256 bytes? Does the bluetooth peripheral automatically break it into the correct number of packets?&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Thank you so much, Simon! I can&amp;#39;t tell you how much I appreciate all of your help and this sort of support from Nordic.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Kindest regards,&lt;/p&gt;
&lt;p&gt;Ryan&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Increasing bluetooth speed without blocking other peripherals</title><link>https://devzone.nordicsemi.com/thread/365315?ContentTypeID=1</link><pubDate>Thu, 28 Apr 2022 07:46:56 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d866c2f7-fd5c-46a6-a775-bf3e46f528cc</guid><dc:creator>Simonr</dc:creator><description>&lt;p&gt;Hi&lt;/p&gt;
&lt;p&gt;The &lt;a href="https://infocenter.nordicsemi.com/topic/sdk_nrf5_v17.1.0/ble_sdk_app_queued_writes.html"&gt;Queued Writes application&lt;/a&gt; in the SDK should give a good example on how to use the queued writes module. You will indeed have to&amp;nbsp;set the&amp;nbsp;NRF_BLE_QWR_MAX_ATTR define to 1 or more, depending on how many attribute handles you want to be able to register. As stated, if this is zero, all queued write requests will be rejected by the Queued Write module.&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Simon&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Increasing bluetooth speed without blocking other peripherals</title><link>https://devzone.nordicsemi.com/thread/365257?ContentTypeID=1</link><pubDate>Wed, 27 Apr 2022 15:50:25 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:29c2eafb-18d5-423c-8c35-cc156fca90dc</guid><dc:creator>ryerye120</dc:creator><description>&lt;p&gt;Hi Simon!&lt;br /&gt;&lt;br /&gt;1) Right now it looks like it&amp;#39;s happening on the Bluetooth side. I probed the spi pins and the data looks good&amp;nbsp;and is being transmitted at the right rate. As far as waiting for the &amp;quot;success&amp;quot; response I ran into a weird issue.&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;I figured things would run fastest if I put everything in the interrupt handlers so I have a timer_interrupt trigger a SPI transaction and then a SPI_interrupt handler that triggers a bluetooth transaction. My original code (where I wait for NRF_SUCCESS) is below:&lt;br /&gt;&lt;br /&gt;&lt;pre class="ui-code" data-mode="text"&gt;void spim_event_handler(nrfx_spim_evt_t const * p_event,
                       void *                  p_context)
{
    spi_xfer_done = true;
    // Bring CS high
    nrf_gpio_pin_set(NRFX_SPIM_SS_PIN);
    
    // send 3 packets at once to take advantage of the large payload size
    if (spi_trx_counter == 3)
    {
        //NRF_LOG_INFO(&amp;quot;READ 3 SPI PACKETS, SEND to BLE&amp;quot;);
        spi_trx_counter = 0;
        while(ble_nus_data_send(&amp;amp;m_nus, ble_tx_buf, &amp;amp;ble_packet_length, m_conn_handle) != NRF_SUCCESS);
    }
}&lt;/pre&gt;&amp;nbsp;&lt;br /&gt;&lt;br /&gt;This became problematic because waiting with &amp;quot;&lt;em&gt;while(ble_nus_data_send(&amp;amp;m_nus, ble_tx_buf, &amp;amp;ble_packet_length, m_conn_handle) != NRF_SUCCESS);&lt;/em&gt;&amp;quot; in the interrupt handler&amp;nbsp;prevented&amp;nbsp;the SPI from operating &amp;#39;while&amp;#39; the bluetooth was running. I confirmed this by&amp;nbsp;probing my SPI pins with an oscilloscope - I&amp;#39;d get 3 SPI packets (all spaced &amp;lt;1ms apart) and then there would be a 6-7ms gap (what I assume is the connection interval) while the code hit the bluetooth transfer. In other words, the BLE was blocking the SPI&amp;nbsp;&amp;nbsp;&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;Removing the &amp;quot;while&amp;quot;&amp;nbsp; fixed this&amp;nbsp;blocking problem. SPI transactions are happening at the proper rate now - but I worry I&amp;#39;m not queueing packets properly (which is why I&amp;#39;m getting some dropped packets). Do you know if how the queueing is handled in the backend? Or is this something I have to implement myself? If so,&amp;nbsp;does that mean I &amp;#39;have&amp;#39; to move the BLE transfers to my main loop?&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&lt;strong&gt;Edit:&lt;/strong&gt; I took another look at my sdk_config and I saw the following block:&lt;br /&gt;&lt;pre class="ui-code" data-mode="text"&gt;// &amp;lt;e&amp;gt; NRF_BLE_QWR_ENABLED - nrf_ble_qwr - Queued writes support module (prepare/execute write)
//==========================================================
#ifndef NRF_BLE_QWR_ENABLED
#define NRF_BLE_QWR_ENABLED 1
#endif
// &amp;lt;o&amp;gt; NRF_BLE_QWR_MAX_ATTR - Maximum number of attribute handles that can be registered. This number must be adjusted according to the number of attributes for which Queued Writes will be enabled. If it is zero, the module will reject all Queued Write requests. 
#ifndef NRF_BLE_QWR_MAX_ATTR
#define NRF_BLE_QWR_MAX_ATTR 0
#endif&lt;/pre&gt;&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;I probably need to make&amp;nbsp;NRF_BLE_QWR_MAX_ATTR at least 1 for the NUS notifications. Don&amp;#39;t I? I also don&amp;#39;t see anything in my sdk config for length extension. Do you know if I have to enable this in my SDK_config?&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&lt;/p&gt;
&lt;p&gt;2) Ahh that makes alot of sense. So playing with tx power and link budget won&amp;#39;t really help me with this blocking problem that I&amp;#39;m dealing with. At least that&amp;#39;s cleared up!&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Thanks so much for your help, Simon. I really appreciate it!&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Kindest regards,&lt;/p&gt;
&lt;p&gt;Ryan&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Increasing bluetooth speed without blocking other peripherals</title><link>https://devzone.nordicsemi.com/thread/365209?ContentTypeID=1</link><pubDate>Wed, 27 Apr 2022 13:07:53 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:7eef712e-6d36-4baf-bf2c-804fffc202e5</guid><dc:creator>Simonr</dc:creator><description>&lt;p&gt;Hi Ryan&lt;/p&gt;
&lt;p&gt;1. Have you been able to track down where exactly the packets are dropped? Does it occur from the SPI to the transmitting device, or is the data lost over the air?&amp;nbsp;I think you should wait for the ble_nus_data_send() to be completed before you call it again.&lt;/p&gt;
&lt;p&gt;2. It only helps to increase the TX power if you&amp;#39;re having trouble with the connection in terms of range, higher TX power won&amp;#39;t help much if the devices are right next to each other. The 2MBPS PHY does not alter the TX power.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Simon&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>