Page 1 of 1

How to temporarily PAUSE Bluetooth / BLE

Posted: Mon Sep 23, 2024 2:10 am
by jcolebaker
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);


Re: How to temporarily PAUSE Bluetooth / BLE

Posted: Mon Sep 23, 2024 2:42 am
by chegewara
Did you try to do sampling on second core, or even better to use second core only for sampling task?

Re: How to temporarily PAUSE Bluetooth / BLE

Posted: Mon Sep 23, 2024 6:54 am
by MicroController
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.

Re: How to temporarily PAUSE Bluetooth / BLE

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

Re: How to temporarily PAUSE Bluetooth / BLE

Posted: Thu Sep 26, 2024 12:55 am
by jcolebaker
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?

Re: How to temporarily PAUSE Bluetooth / BLE

Posted: Sun Sep 29, 2024 7:29 pm
by jcolebaker
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.