I am trying to make a device based on Seeed XIAO BLE nRF52840, which should periodically transmit battery voltage via BLE. The BLE connection should be constant
I wanted to set the transmitting period by SoftwareTimer to make MCU fall asleep in System ON mode and wake up by timer
However, the MCU doesn't go to sleep by the sd_app_evt_wait() command, the code execution continues. Clear pending via the sd_nvic_ClearPendingIRQ function doesn't solve the problem either.
What am I doing wrong? Softdevice s140_7.3.0
sd_softdevice_is_enabled shows the softdevice is activated
Disabling Serial and SoftwareTimer does not help
My scetch is below (only the Timer cheking, with no BLE yet). sd_app_evt_wait() and then sd_evt_get both return 0x0
#include <bluefruit.h>
//#include <nrf_soc.h>
#include <nrf_nvic.h>
uint32_t sys_evt;
uint32_t err_code;
SoftwareTimer blinkTimer;
void setup()
{
Bluefruit.begin(); // Sleep functions need the softdevice to be active.
delay(30);
Serial.begin(115200);
delay(3000);
sd_power_mode_set(NRF_POWER_MODE_LOWPWR);
pinMode(LED_RED, OUTPUT); // initialize digital pin LED_BUILTIN as an output.
blinkTimer.begin(3000, blink_timer_callback); // Configure the timer with 1000 ms interval, with our callback
blinkTimer.start(); // Start the timer
}
void loop()
{
delay(500);
Serial.print("timer before sd_app_evt_wait at - ");
Serial.println(millis());
digitalToggle(LED_RED);
clearInterrupts();
NVIC_ClearPendingIRQ(SD_EVT_IRQn);
sd_nvic_ClearPendingIRQ(SD_EVT_IRQn);
err_code = sd_app_evt_wait(); // puts the nrf52 to sleep when there is nothing to do
//Проверяем системные события
sd_evt_get(&sys_evt);
Serial.print("SD answer: 0x");
Serial.println(err_code, HEX);
Serial.print("SD event: 0x");
Serial.println(sys_evt, HEX);
Serial.print("timer after sd_app_evt_wait at - ");
Serial.println(millis());
Serial.println();
Serial.println();
}
void blink_timer_callback(TimerHandle_t xTimerID)
{
// freeRTOS timer ID, ignored if not used
(void) xTimerID;
Serial.print("timer in blink_timer_callback at - ");
Serial.println(millis());
}
void clearInterrupts() {
for (int irq = 0; irq < 41; irq++) {
NVIC_ClearPendingIRQ((IRQn_Type)irq);
sd_nvic_ClearPendingIRQ((IRQn_Type)irq);
}
}