What causes the stm32 RTC to reset?
What causes the stm32 RTC to reset?
Hi, i have a question about the RTC library, what would cause the RTC to reset?
This is not a bug.Bambo wrote: ↑Wed May 20, 2020 11:21 am Bug report created here: https://github.com/stm32duino/STM32LowPower/issues/22
Simply wrong usage of the API. See my comment here:
https://github.com/stm32duino/STM32LowP ... -631491658
Re: What causes the stm32 RTC to reset?
Looks like when you use LowPower.shutdown() it also resets the RTC
Re: What causes the stm32 RTC to reset?
It says in the documentation that the RTC doesn't reset over reboots, but when the unit reboots the RTC is reset?
See: https://github.com/stm32duino/STM32RTC at the bottom "Reset time management By default, if a time is set it will not be reset after a reboot."
See: https://github.com/stm32duino/STM32RTC at the bottom "Reset time management By default, if a time is set it will not be reset after a reboot."
Re: What causes the stm32 RTC to reset?
Additionally if you use LowPower.deepSleep() the unit carries on processing, you have to use something like this:
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();
}
Re: What causes the stm32 RTC to reset?
You need to set RTC source to LSE if you want it to work in shutdown mode or without power (just with RTC battery).
Re: What causes the stm32 RTC to reset?
ok thank you, do you know what impact using the LSE clock for the RTC will have? does it affect TIM3 or any other timers? Thanks again.
Re: What causes the stm32 RTC to reset?
It's just source for RTC, nothing else.
Don't know what board you're using, but with blue pills I found built-in RTC unreliable, probably due to bad quality oscillators.
Don't know what board you're using, but with blue pills I found built-in RTC unreliable, probably due to bad quality oscillators.
Re: What causes the stm32 RTC to reset?
Ok so i've added the setClockSource() to the RTC code but now it doesn't restart at all once shutdown is called? Here is the code i'm using to test it.
The output is
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!
Re: What causes the stm32 RTC to reset?
Which board? It have an LSE?