What causes the stm32 RTC to reset?
Posted: Mon Apr 27, 2020 8:33 am
Hi, i have a question about the RTC library, what would cause the RTC to reset?
Everything relating to using STM32 boards with the Arduino IDE and alternatives
https://www.stm32duino.com/
Code: Select all
#include <STM32RTC.h>
#include <STM32LowPower.h>
STM32RTC& rtc = STM32RTC::getInstance();
volatile bool sleeping = false;
void callback(void*data)
{
sleeping = false;
Serial.println("Callback!");
Serial.flush();
}
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
Serial.println("Started");
Serial.flush();
LowPower.begin();
rtc.begin();
if (!rtc.isTimeSet())
{
Serial.println("Time did not persist.");
Serial.flush();
}
else
{
Serial.println("Time persisted!");
Serial.flush();
}
rtc.setHours(5);
rtc.setMinutes(5);
rtc.setSeconds(1);
rtc.setWeekDay(1);
rtc.setDay(1);
rtc.setMonth(1);
rtc.setYear(20);
LowPower.enableWakeupFrom(&rtc, callback);
}
void loop() {
Serial.println("Shutting down!");
Serial.flush();
int epochNow = rtc.getEpoch();
int epochEnd = epochNow + 5;
sleeping = true;
rtc.setAlarmEpoch(epochEnd);
LowPower.deepSleep();
while (sleeping)
{
}
Serial.print("EPOCH: ");
Serial.println(rtc.getEpoch());
Serial.println("Done!");
Serial.flush();
}
Code: Select all
#include <STM32RTC.h>
#include <STM32LowPower.h>
STM32RTC& rtc = STM32RTC::getInstance();
volatile bool sleeping = false;
void callback(void* data)
{
sleeping = false;
Serial.println("Callback!");
Serial.flush();
}
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
Serial.println("Started");
Serial.flush();
LowPower.begin();
rtc.begin();
rtc.setClockSource(STM32RTC::LSE_CLOCK);
if (!rtc.isTimeSet())
{
Serial.println("Time did not persist.");
Serial.flush();
}
else
{
Serial.println("Time persisted!");
Serial.flush();
}
rtc.setHours(5);
rtc.setMinutes(5);
rtc.setSeconds(1);
rtc.setWeekDay(1);
rtc.setDay(1);
rtc.setMonth(1);
rtc.setYear(20);
LowPower.enableWakeupFrom(&rtc, callback);
}
void loop() {
Serial.println("Shutting down!");
Serial.flush();
LowPower.shutdown(1000);
Serial.println("Done!");
Serial.flush();
}
And then it doesn't start back up.11:45:12.586 -> Started
11:45:12.722 -> Time did not persist.
11:45:12.757 -> Shutting down!