0

Slow ble.available, and feather suggestion
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Slow ble.available, and feather suggestion

by catash on Tue May 14, 2019 5:05 pm

Hi,
I'm using an Adafruit Feather M0 Bluefruit LE, upgraded to the latest firmware (0.8.1) today. I'm sending small packets via UART (15 byte payload). To see if data is available, I do a ble.available(), then a ble.read if it is. My testing says the ble.available is taking 3.8ms, which is a LOT for each character. Questions:
(1) Is 3.8ms for that command correct? Any way to speed that up, since it seems like a LOT.
(2) I'm loathe to just do that once, then assume there's 15 bytes waiting for me, but is this reasonable?

Side question - I'm beginning to think I should ditch bluetooth and go to wireless - getting the bluetooth coupling going in C++ has been a pain, and the communications rate seems really low (like 5 packets a second?). I'd really like more like 50 packets a second, and have a wired power connection so power isn't an issue. Would like to keep the feather form-factor. Is there a good alternative? WiFi I assume? Ideally a part with a 32-bit multiplier (M0 class), since the Uno is a bit slow for my purposes.

Thanks,

Scott

catash
 
Posts: 8
Joined: Mon Jan 22, 2018 4:19 pm

Re: Slow ble.available, and feather suggestion

by adafruit_support_mike on Wed May 15, 2019 2:57 am

It depends on how you're sending the data.

A single BLE packet can hold up to 20 bytes of payload, and BLE devices can transmit a maximum of 6 packets per connection interval. The minimum connection interval is 7.5ms, and most devices don't actually support 6 packets per interval.. it's more like 1 or 2.

If you're sending one packet per byte, you'll run into those timing limits.

Since you have a 15-byte payload, you'll use the connection most efficiently by sending the whole 15 bytes in one ble.print() statement, followed immediately by a .flush() to send the data without waiting for the output buffer to fill.

adafruit_support_mike
 
Posts: 58406
Joined: Thu Feb 11, 2010 2:51 pm

Re: Slow ble.available, and feather suggestion

by catash on Wed May 15, 2019 4:35 pm

I'm actually looking at the opposite direction - host CPU sends a ble message which is 15 bytes. Arduino checks to see if data is available via ble.available(), which takes like 3.8ms. If it is, I grab a byte of data. I guess the questions are:
(1) Is it reasonable for the ble.available() to take 3.8ms? I would assume this is basically a "check the FIFO, if data in FIFO return true".
(2) Yeah, the host sends 15 bytes at a time, but over UART is it fair to assume that if any of the packet arrives, it all does? That is, if ble.available() is true, feel free to gobble up 15 bytes without checking again.

Thanks,

Scott

catash
 
Posts: 8
Joined: Mon Jan 22, 2018 4:19 pm

Re: Slow ble.available, and feather suggestion

by catash on Wed May 15, 2019 6:33 pm

Never mind, figured it out by crawling through the code. The first ble.available() is doing a communication to the BLE chip via SPI, and grabbing a packet of data. Subsequent ble.available's, and ble.reads, are just consuming what's in the internal FIFO, and should be fast. So, I can stick with the code I have.

Still surprised it takes 3.8ms to do that communication with the BLE chip. But, at least it should be only once per packet coming in.

Scott

catash
 
Posts: 8
Joined: Mon Jan 22, 2018 4:19 pm

Re: Slow ble.available, and feather suggestion

by adafruit_support_mike on Thu May 16, 2019 12:12 am

Glad to hear you got it working!

adafruit_support_mike
 
Posts: 58406
Joined: Thu Feb 11, 2010 2:51 pm

Please be positive and constructive with your questions and comments.