How to temporarily PAUSE Bluetooth / BLE
Posted: 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:
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);