I have another issue with my MG24 that I’m not sure about. I wanted to try storing some variable in memory so I could resume after deep sleep, but maybe the MG24 doesn’t support it? I con’t know. Simply writing something like RTC_DATA_ATTR unsigned int counter = 0;
results in the compilation error 'RTC_FAST_ATTR' does not name a type
. Obviously, it does here, and I haven’t been able to google up any answers.
Hi there,
So is it similar to this:
were you able to get a WiKi example to run?
HTH
GL PJ
Hi Dave_Reese,
File–>Examples–>Arduino Low Power–>DeepSleepMemory–>DeepSleepMemory.ino
with a few changes, and it works.
//----------------------------------------------------------------------------------------------
// BoardBoard Library : Silicon Labs 2.2.0
// Board Select : Seeed Studio XIAO MG24 (Sense)
// Plotocol stack : None
//----------------------------------------------------------------------------------------------
// IMPORTANT NOTE:Cannot upload new sketches during DeepSleep
// need to reset after upload
/*
ArduinoLowPower deep sleep example with timed wakeup and memory retention
The example shows the basic usage of the Arduino Low Power library by putting the device into deep sleep.
The device will remain in deep sleep until an external interrupt is triggered or the sleep timer expires.
During deep sleep the whole device is powered down except for a minimal set of peripherals (like the Back-up RAM and RTC).
This means that the CPU is stopped and the RAM contents are lost - the device will start from the beginning of the sketch after waking up.
This example utilizes the deep sleep memory (Back-up RAM) to retain data during deep sleep.
The back-up RAM is a small amount of RAM (128 bytes) which is retained even in deep sleep.
This example is compatible with all Silicon Labs Arduino boards.
Author: Tamas Jozsi (Silicon Labs)
*/
#include <Arduino.h>
#include "ArduinoLowPower.h"
// pin definition
#define USER_SW PC3 // (3), D3 for example
void setup()
{
Serial.begin(115200);
Serial.println("---- Deep sleep memory test ----");
pinMode(LED_BUILTIN, OUTPUT);
digitalWrite(LED_BUILTIN, LOW);
// Check if we woke up from deep sleep or were reset by an other cause
if (LowPower.wokeUpFromDeepSleep()) {
Serial.println("Woke up from deep sleep");
} else {
Serial.println("Something else caused a reset other than sleeping");
// Clear the deep sleep memory at address 0 and 1
LowPower.deepSleepMemoryWrite(0, 0);
LowPower.deepSleepMemoryWrite(1, 0);
}
// if user sw is on, blink and enable to upload new sketch
pinMode(USER_SW, INPUT_PULLUP);
if(digitalRead(USER_SW) == LOW) {
Serial.println("enable to upload new sketch");
while(true) {
digitalWrite(LED_BUILTIN, LOW);
delay(50);
digitalWrite(LED_BUILTIN, HIGH);
delay(50);
}
}
Serial.println("end of setup");
}
void loop()
{
digitalWrite(LED_BUILTIN, LOW);
delay(500);
digitalWrite(LED_BUILTIN, HIGH);
// Read the current sleep cycle counter from the deep sleep memory (address 0)
uint32_t sleep_cycles = LowPower.deepSleepMemoryRead(0);
Serial.printf("Sleep cycle counter: %lu\n", sleep_cycles);
// Increment the sleep cycle counter and write it back to the deep sleep memory
sleep_cycles++;
LowPower.deepSleepMemoryWrite(0, sleep_cycles);
// Read the total uptime counter from the deep sleep memory (address 1)
uint32_t total_uptime = LowPower.deepSleepMemoryRead(1);
Serial.printf("Total uptime: %lu\n", total_uptime + millis());
// Increment the total uptime counter and write it back to the deep sleep memory
total_uptime += millis();
LowPower.deepSleepMemoryWrite(1, total_uptime);
// Go to deep sleep
// IMPORTANT NOTE:Cannot upload new sketches during DeepSleep
Serial.println("Going to deep sleep\n");
Serial.end();
LowPower.deepSleep(5000);
}
Be sure to look at the following links as well.
Thank you @msfujino ! I did figure out a similar approach using EEPROM, but I like this one you added because it uses the same library. Appreciate it! On another note, there’s no interrupt pins on the MG24, are there
Details of interrupts are described in the “EFR32xG24 Wireless SoC
Reference Manual” in section “3.3.1 Interrupt Operation”.
Hmm, I looked at it, but I’m way too much of a noob for that to make sense. All I know is LowPower.attachInterruptWakeup()
doesn’t seem to work, and nobody talks about it with this microcontroller. There isn’t any info on using the IMU as an interrupt either.
See the link below for the wake-up pins.
Attached is a sketch that confirms it works.
MG24_XIAO_DeepSleep_ExternalWakeup.zip (2.1 KB)
Unfortunately the IMU interrupt is not connected to the controller.