Bluetooth packet transfer limit on Feather nRF52

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Post Reply
User avatar
eceng04
 
Posts: 4
Joined: Tue Aug 02, 2022 9:46 am

Bluetooth packet transfer limit on Feather nRF52

Post by eceng04 »

How many packets per second can be transmitted using Adafruit Feather nRF52 Bluefruit LE - nRF52832?

In my tests, I was able to transmit only 5 to 6 packets per second, not more than that. Is there any example code or optimisation techniques to increase this rate?

User avatar
mikeysklar
 
Posts: 8427
Joined: Mon Aug 01, 2016 8:10 pm

Re: Bluetooth packet transfer limit on Feather nRF52

Post by mikeysklar »

Looking through the guide there are some examples of fast mode down to 20ms and slow mode at 150ms which would match what you have observed. Have you messed withe advertising inteval?

Code: Select all

 /* Start Advertising
 * - Enable auto advertising if disconnected
 * - Interval: fast mode = 20 ms, slow mode = 152.5 ms
 * - Timeout for fast mode is 30 seconds
 * - Start(timeout) with timeout = 0 will advertise forever (until connected)
 *
 * For recommended advertising interval
 * https://developer.apple.com/library/content/qa/qa1931/_index.html
 */
 Bluefruit.Advertising.restartOnDisconnect(true);
 Bluefruit.Advertising.setInterval(32, 244); // in unit of 0.625 ms
 Bluefruit.Advertising.setFastTimeout(30); // number of seconds in fast mode
 Bluefruit.Advertising.start(0); // 0 = Don't stop advertising
after n seconds
}
https://cdn-learn.adafruit.com/download ... -guide.pdf

User avatar
eceng04
 
Posts: 4
Joined: Tue Aug 02, 2022 9:46 am

Re: Bluetooth packet transfer limit on Feather nRF52

Post by eceng04 »

Code: Select all

Bluefruit.Advertising.setInterval(32, 244);
I tried lowering the values here but then the phone could not connect with the device. What would be the optimum values for faster packet transfer?

And how do we actually select the transfer mode, fast or slow? This statement is simply setting the interval values for both the modes.

I have done a few tests and found that each successful packet transfer takes 85 ms.

Another issue is that every time it runs the loop, the first packet transfer is always unsuccessful, which takes 100 ms. Then the second successful transfer takes 85 ms.

Code: Select all

do { uartsent = bleuart.write(bytes,sizeof(idat));
          } while(!uartsent);

User avatar
eceng04
 
Posts: 4
Joined: Tue Aug 02, 2022 9:46 am

Re: Bluetooth packet transfer limit on Feather nRF52

Post by eceng04 »

So I tried to dig deeper in to the issue and found that this statement takes up to 100 ms to execute:

Code: Select all

// Failed if there is no free buffer
      if ( !conn->getHvnPacket() ) return false;
It is inside the notify function of BLECharacteristic.cpp file.

Code: Select all

bool BLECharacteristic::notify(uint16_t conn_hdl, const void* data, uint16_t len)
getHvnPacket is defined in BLEConnection.cpp

Code: Select all

bool BLEConnection::getHvnPacket (void)
{
  return xSemaphoreTake(_hvn_sem, ms2tick(BLE_GENERIC_TIMEOUT));
}
I couldn't find _hvn_sem but reducing BLE_GENERIC_TIMEOUT in bluefruit_common.h from 100 to 50 or 80 did not help much in solving the issue. Instead, it increased the number of failed packets, and sometimes caused connection issues with the device.

User avatar
mikeysklar
 
Posts: 8427
Joined: Mon Aug 01, 2016 8:10 pm

Re: Bluetooth packet transfer limit on Feather nRF52

Post by mikeysklar »

Good work digging into this. You have turned up some clues.

1) Which library are you running? Are you running Adafruit_nRF52_Arduino v1.3.0? I ask because the side issue you brought up about the first packet failing with getHvnPacket() that is within:

Code: Select all

bool BLECharacteristic::notify(uint16_t conn_hdl, const void* data, uint16_t len)
has been resolved.

_hvn_sem btw:

https://github.com/adafruit/Adafruit_nR ... q=_hvn_sem

Another technique for improving performance would be to try setting this before Bluefruit.begin() to increase the queue length from 1 to 256.

Code: Select all

  Bluefruit.configPrphConn(BLE_GATT_ATT_MTU_DEFAULT, BLE_GAP_EVENT_LENGTH_MIN, 256, 256);
  Bluefruit.configPrphBandwidth(BANDWIDTH_MAX);

User avatar
eceng04
 
Posts: 4
Joined: Tue Aug 02, 2022 9:46 am

Re: Bluetooth packet transfer limit on Feather nRF52

Post by eceng04 »

Thanks for the tip, I was able to get much faster throughput using the following,

Code: Select all

// GATT ATT MTU (23 bytes/packet), GAP Event len (6*1.25 ms), HVN Tx Queue size (25), Wr CMD Tx Queue size (25)
Bluefruit.configPrphConn(23, 6, 25, 25);
While using BANDWIDTH_MAX, the device couldn't connect and the max values for QSize would be 255, not 256.

Post Reply
Please be positive and constructive with your questions and comments.

Return to “Wireless: WiFi and Bluetooth”