Wake up from low power sleep or Deepsleep mode using RTC

Heyy
I working on project where i am planing using XIAO nrf52840 chip am using Ardunio IDE for Rapid development,
I was unable to implement wake and sleep  functionalities , my requirement is to  put by device into lowest power mode possible and wake it up every 15 min , on every wake up it should take reading from sensor and as we get 4 reading it should shoot over BLE to its client.

Honestly i dont have any software document for XIAO nrf52 for Ardunio ide i implemented other functionality by reading available blogs and example code, if you could share advnce link it would be helpful

please help me with following 2 code, tell me what header files and  libraries i should use .....

Code 1:

#include <nrf52840.h>
#include "Wire.h"
#include <bluefruit.h>
#include <Arduino.h>
// Function to configure RTC to generate interrupts at regular intervals
void configureRTC(unsigned long seconds) {
  NRF_RTC2->TASKS_STOP = 1;  // Stop RTC2
  NRF_RTC2->TASKS_CLEAR = 1;  // Clear RTC2

  NRF_RTC2->PRESCALER = 327;  // 32.768 kHz clock, 1 tick per millisecond
  NRF_RTC2->CC[0] = seconds * 1000;  // Set compare value (in milliseconds)
  NRF_RTC2->EVTENSET = RTC_EVTENSET_COMPARE0_Msk;  // Enable compare event
  NRF_RTC2->INTENSET = RTC_INTENSET_COMPARE0_Msk;  // Enable compare interrupt

  NVIC_EnableIRQ(RTC2_IRQn);  // Enable RTC2 interrupt
  NRF_RTC2->TASKS_START = 1;  // Start RTC2
}

// Interrupt handler for RTC wake-up
extern "C" void RTC2_IRQHandler() {
  if (NRF_RTC2->EVENTS_COMPARE[0]) {
    NRF_RTC2->EVENTS_COMPARE[0] = 0;  // Clear the event
  }
}

void setup() {
  Serial.begin(115200);
  Serial.println("Communication...");
  configureRTC(10);  // Configure RTC to trigger an interrupt every 10 seconds
}

void loop() {

Serial.println("Wake up...");
delay(2000);

sd_power_mode_set(NRF_POWER_MODE_LOWPWR);
sd_power_dcdc_mode_set(NRF_POWER_DCDC_ENABLE);
__WFE();
__WFI();
sd_app_evt_wait();

Serial.println("sleep...");
delay(2000);
}

Above code should wait for 10 sec and system should go in sleep mode but this isnt happening please help me with this

Code 2 : just replace sd_app_evt_wait() with sd_power_system_off() let me if RTC could wake it up?
Parents Reply Children
No Data
Related