This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Streaming SAADC data (16kHz sampling rate) over BLE

Hi there,

I'm currently working on getting a streaming application running which is supposed to sample some audio at 16kHz and send it (uncompressed) to a central device via BLE.

Current Status, what works:
The SAADC is configured with a double buffer, each containing 122 samples of uint16 samples. The samples are stored intermediately in an Atomic FIFO until they are then broken up into two uint8 values and sent using the function sd_ble_gatts_hvx(). The transmission works with data-length extension and connection-length extension enabled. The code as of now, works at lower sampling rates of about 1.5kHz, however going beyond this sampling-rate makes the BLE connection fail. Consequently the peripheral device looses the connection to the central device and needs to reconnect. 
Connecting the peripheral with the nRF Connect App on an Android phone, the central (App) side reports: Disconnected Error 0x8 [= GATT CONN TIMEOUT].

What doesn't work:
At this point I am confident to say, it is most likely a timing constraint which is violated, since the BLE connection breaks earlier the higher the sampling-rate. Likewise increasing the distance, i.e. latency of the BLE connection leads to a earlier loss of connection. The connection breaks with the BLE_GAP_EVT_DISCONNECTED case. The code never reconnects after this event and just remains / "freezes" in this state. No error is reported, the program keeps running.

The problem:

  • I have isolated the SAADC part of my code printing the values via UART to my terminal instead of transmitting via BLE. This works just fine, even at sampling-rates as high as 32kHz the code never freezes and the Atomic FIFO never fills up.
  • I have isolated the BLE transmission part, sending simply dummy data in intervals triggered by a timer. This too works at frequencies of up to 20kHz with out loosing connection or "freezing up".

The set-up I use is:
2x NRF52 DevKit (nrf52832) with S132
nrf SDK 15.3.0
Segger Embedded Studio 4.16

The code I am using is based on the ble_app_uart example from the SDK.

Question:

  1. Am I correct in my calculations/ assumptions that this amount of data should be transmittable via BLE?
  2. How can I increase the throughput of my code, such that the data stream may run continuously?
  3. Is there any working example around of streaming large quantities of data while using the SAADC?
  4. How can I resolve the loosing of connection on my device and how to fix the freezing up/ not reconnecting of the devices?

Thanks a lot for your time and help

Oliver

Parents
  • Hi Oliver

    First of all, thanks for a detailed question. We appreciate that you take the time to describe your setup and what you are doing!

    1. You could try implementing the NRF_DRV_SAADC_EVT_LIMIT to see if the converted sample on a given channel is exceeding a limit. I suspect this is the reason you are experiencing disconnects. Have you been able to see an error code when the BLE_GAP_EVT_DISCONNECTED occurs? Might give us some pointers to what exactly is causing the disconnection.

    2. What are your connection parameters (This might be the reason you aren't able to connect to the Android device) etc.? Also check that your BLE_GAP_PHY_2MBPS is set for the highest possible throughput.

    3. As far as I know, we don't have any "official" examples of this, but someone might have done it earlier either here on DevZone, or on GitHub.

    4. This can be a variety of reasons. First of all, what pins do you use as UART pins? The ones described in the PS as close to the radio might cause interference if active simultaneously as the radio is. Another reason might be that your slave latency is set to 0. This is the number of failed connection events before the link is broken. By increasing this number the link will tolerate that number of missing connection events before the connection is broken. I suggest setting this to 3 or 4 and tweak it if necessary.

    Best regards,

    Simon 

Reply
  • Hi Oliver

    First of all, thanks for a detailed question. We appreciate that you take the time to describe your setup and what you are doing!

    1. You could try implementing the NRF_DRV_SAADC_EVT_LIMIT to see if the converted sample on a given channel is exceeding a limit. I suspect this is the reason you are experiencing disconnects. Have you been able to see an error code when the BLE_GAP_EVT_DISCONNECTED occurs? Might give us some pointers to what exactly is causing the disconnection.

    2. What are your connection parameters (This might be the reason you aren't able to connect to the Android device) etc.? Also check that your BLE_GAP_PHY_2MBPS is set for the highest possible throughput.

    3. As far as I know, we don't have any "official" examples of this, but someone might have done it earlier either here on DevZone, or on GitHub.

    4. This can be a variety of reasons. First of all, what pins do you use as UART pins? The ones described in the PS as close to the radio might cause interference if active simultaneously as the radio is. Another reason might be that your slave latency is set to 0. This is the number of failed connection events before the link is broken. By increasing this number the link will tolerate that number of missing connection events before the connection is broken. I suggest setting this to 3 or 4 and tweak it if necessary.

    Best regards,

    Simon 

Children
No Data
Related