This is a problem I'm looking to tackle across various platforms that utilize the Bluefruit BLE library. Any and all help would be much appreciated.
Currently, no matter the platform (tested NRF52840 feather, itsybitsy NRF52840, NRF52832 feather, RAK4631 Core) that use this library, I cannot seem to get the microcontroller to deep sleep anymore in between operations once Bluefruit.begin() is called.
For the purposes of experimentation and my discussion I'm limiting the focus to the ItsyBitsy NRF52840, with a depopulated RGB LED to minimize power consumption. The device is being powered externally via a Nordic PPK2 on its 3V pin at 3300mV, the same kit is used for power consumption measurements.
For the firmware, I'm using a slightly modified BLE UART example with all print statements removed, using longer advertisement interval, and a hardcoded message ("hi") to be sent every 5s to the connected device on connection.
When running that sketch (pasted below) without connecting, the following consumption is found:
Code: Select all
#include <Arduino.h>
#include <bluefruit.h>
// Forward declarations for functions
void ble_connect_callback(uint16_t conn_handle);
void ble_disconnect_callback(uint16_t conn_handle, uint8_t reason);
BLEUart g_BleUart;
bool g_BleUartConnected = false;
void setup()
{
time_t timeout = millis(); // Timeout in case the system runs on its own
Bluefruit.configPrphBandwidth(BANDWIDTH_MAX);
Bluefruit.configPrphConn(92, BLE_GAP_EVENT_LENGTH_MIN, 16, 16);
Bluefruit.begin(1, 0);
// Set max power. Accepted values are: -40, -30, -20, -16, -12, -8, -4, 0, 4
Bluefruit.setTxPower(4);
// Set the BLE device name
Bluefruit.setName("RAK4631_UART");
Bluefruit.Periph.setConnectCallback(ble_connect_callback);
Bluefruit.Periph.setDisconnectCallback(ble_disconnect_callback);
Bluefruit.Periph.setConnInterval(16, 16); // min = 9*1.25=11.25 ms, max = 16*1.25=20ms
// Configure and Start BLE Uart Service
g_BleUart.begin();
// Set up and start advertising
// Advertising packet
Bluefruit.Advertising.addFlags(BLE_GAP_ADV_FLAGS_LE_ONLY_GENERAL_DISC_MODE);
Bluefruit.Advertising.addTxPower();
Bluefruit.Advertising.addName();
Bluefruit.Advertising.restartOnDisconnect(true);
Bluefruit.Advertising.setInterval(1952, 1952); // in unit of 0.625 ms
Bluefruit.Advertising.setFastTimeout(30); // number of seconds in fast mode
Bluefruit.Advertising.start(0); // 0 = Don't stop advertising after n seconds
}
void ble_connect_callback(uint16_t conn_handle)
{
(void)conn_handle;
g_BleUartConnected = true;
//Serial.println("BLE client connected");
}
void ble_disconnect_callback(uint16_t conn_handle, uint8_t reason)
{
(void)conn_handle;
(void)reason;
g_BleUartConnected = false;
//Serial.println("BLE client disconnected");
}
void loop()
{
// Forward anything received from USB Serial to BLE UART
if (g_BleUartConnected)
{
g_BleUart.print("hi");
delay(5*1000);
}
// Forward anything received from BLE UART to USB Serial
if (g_BleUart.available())
{
//Serial.print(g_BleUart.readString());
}
}