How to temporarily PAUSE Bluetooth / BLE

jcolebaker
Posts: 64
Joined: Thu Mar 18, 2021 12:23 am

How to temporarily PAUSE Bluetooth / BLE

Postby jcolebaker » Mon Sep 23, 2024 2:10 am

Hi,

We have an ESP32 project which uses Bluedroid to implement some services (BLE, plus a Bluetooth classic serial port). The BLE advertises some services, and also we support connections for a BT classic serial port.

We also have a data sampling task which has to (periodically) sample from a digital input and measure the timing of rising edges using the MCPWM peripheral. The sampling task is required in bursts. Typically we need to sample for about 20 mS, and this might need to be done every 200 - 500 mS (exact timing not decided yet).

The problem is that we are sampling a frequency of about 130 kHz, so the response to the capture interrupt has to be quite fast. If it is delayed, we miss one or more edges in the signal.

The sampling works well without Bluetooth, but when we enable Bluetooth, I can see some interference: We are missing 3 edges in a burst about every 0.9 mS during the sampling (it looks very regular). My interpretation is that the Bluetooth library has a higher priority interrupt (maybe based on a timer) and is taking CPU time.

QUESTION: Is there a way to temporarily pause activity in the Bluetooth library (Bluedroid) for a brief time (20 - 50 mS) while sampling is active?

What I have tried so far:

Code: Select all


// BLE works, but still get interference:
esp_ble_gap_stop_advertising();
// ...Run MCPWM sampling
esp_ble_gap_start_advertising(&m_hr_adv_params);


// Still get interference, and BLE no longer works after first cycle: (can't find device with BLE scanner):
esp_bt_controller_disable();
// ...Run MCPWM sampling
esp_bt_controller_enable(ESP_BT_MODE_BTDM);

Last edited by jcolebaker on Mon Sep 23, 2024 3:11 am, edited 1 time in total.

chegewara
Posts: 2378
Joined: Wed Jun 14, 2017 9:00 pm

Re: How to temporarily PAUSE Bluetooth / BLE

Postby chegewara » Mon Sep 23, 2024 2:42 am

Did you try to do sampling on second core, or even better to use second core only for sampling task?

MicroController
Posts: 1734
Joined: Mon Oct 17, 2022 7:38 pm
Location: Europe, Germany

Re: How to temporarily PAUSE Bluetooth / BLE

Postby MicroController » Mon Sep 23, 2024 6:54 am

jcolebaker wrote:
Mon Sep 23, 2024 2:10 am
We also have a data sampling task which has to (periodically) sample from a digital input and measure the timing of rising edges using the MCPWM peripheral. The sampling task is required in bursts. Typically we need to sample for about 20 mS, and this might need to be done every 200 - 500 mS (exact timing not decided yet).
Sounds like a task well suited for the RMT peripheral using DMA.

zhaofeng
Posts: 3
Joined: Mon Sep 23, 2024 6:51 am

Re: How to temporarily PAUSE Bluetooth / BLE

Postby zhaofeng » Mon Sep 23, 2024 7:04 am

抱歉,打扰了!
我刚刚接触ESP32C3,但编译的过程中出现了问题,无法通过编译,问题是:undefined reference to `bt_mesh_ext_log_timestamp',您能帮我解答么?

jcolebaker
Posts: 64
Joined: Thu Mar 18, 2021 12:23 am

Re: How to temporarily PAUSE Bluetooth / BLE

Postby jcolebaker » Thu Sep 26, 2024 12:55 am

chegewara wrote:
Mon Sep 23, 2024 2:42 am
Did you try to do sampling on second core, or even better to use second core only for sampling task?
How would I do this? The work is done in the input capture interrupt callback (as set by "mcpwm_capture_channel_register_event_callbacks"). How would I set which CPU this is done on?

jcolebaker
Posts: 64
Joined: Thu Mar 18, 2021 12:23 am

Re: How to temporarily PAUSE Bluetooth / BLE

Postby jcolebaker » Sun Sep 29, 2024 7:29 pm

MicroController wrote:
Mon Sep 23, 2024 6:54 am
Sounds like a task well suited for the RMT peripheral using DMA.
That's a good suggestion. I tried and the RMT peripheral does sample the signal nicely. However, we are using the ESP32 which doesn't support DMA for the RMT peripheral, so we can only sample a max of 512 cycles (high/low) which is not enough for our requirements.

Who is online

Users browsing this forum: brushlow18 and 102 guests