-
Notifications
You must be signed in to change notification settings - Fork 54
Never waking up when alarm is set without reseting RTC #82
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Hi @ClementFoucher , See details: https://github.com/stm32duino/STM32RTC#since-stm32-core-version--150 |
Thanks for your reply. However, even when changing that function, I still can't manage to get it working. Strange. I'll investigate my config to see if it comes from my settings. |
OK, there is a misunderstanding, when I said that it works, I mean: |
No misunderstanding: I understood that to you, the alarm wakes up every minute, but to me it doesn't. Thanks for your support, I'll then check for an error on my side since the library seems to behave OK. |
I did not do the unplug/replug part, because my device has a battery attached. However, when I just tested it with my Nucleo board with that additional step, it seemed to show a correct behavior, as the time is correctly updated every minute. However, since by unplugging the RTC time is lost, we actually fall in the case "time not set", thus time is reset to the default value ( Thus, I probably misinterpreted the error in the first place: actually, it may not be linked to the fact that I pass or not pass the I need to dig it up. Thanks for all your help. |
Ok, after digging up a little more, I can see why your use case (unplugging/replugging) works: As stated n my original post, I have a battery attached to my device and want the time to be preserved across board reset or firmware update. I know this is possible because of the test provided below. In Mode 1 has the same RTC configuration, thus should expose the same behavior. Mode 0 works for the sleeping part, but does not preserve time across reboot. #include <Arduino.h>
#include <STM32RTC.h>
#include <STM32LowPower.h>
// Mode 0: works correctly, but RTC has to be reset so time can't be preserved across reboot
//#define MODE 0
// Mode 1: RTC time preserved, but never wakes up
//#define MODE 1
// Mode 2: RTC time preserved, works OK, but no sleep mmode
#define MODE 2
STM32RTC& rtc = STM32RTC::getInstance();
void displayTime(uint8_t h, uint8_t m, uint8_t s)
{
String text;
text = String(h);
text += ":";
if (m < 10) text += "0";
text += String(m);
text += ":";
if (s < 10) text += "0";
text += String(s);
text += '\n';
Serial.print(text);
Serial.flush();
}
void sleepTillNextMinute(uint8_t h, uint8_t m)
{
m = (m+1)%60;
if (m==0) h = (h+1)%24;
rtc.setAlarmTime(h, m, 0);
rtc.enableAlarm(rtc.MATCH_HHMMSS);
LowPower.sleep(); // or .sleep(): same behavior
}
void setup()
{
Serial.begin(115200);
rtc.setClockSource(STM32RTC::LSE_CLOCK);
#if MODE == 0
// Working, but clock is reinitialized at every reset
rtc.begin(true);
rtc.setTime(7, 30, 45);
#elif (MODE == 1) || (MODE == 2)
// Time is correctly preserved, but board will never wake up if put in sleep mode
rtc.begin();
if (!rtc.isTimeSet())
rtc.setTime(7, 30, 45);
#endif
LowPower.begin();
}
void loop()
{
uint8_t h, m, s;
rtc.getTime(&h, &m, &s, nullptr);
#if (MODE == 0) || (MODE == 1)
displayTime(h, m, s);
sleepTillNextMinute(h, m);
#else
static uint8_t latest_minute = m;
static bool firstStart = true;
if ( (m != latest_minute) || (firstStart == true) )
{
rtc.getTime(&h, &m, &s, nullptr);
displayTime(h, m, s);
latest_minute = m;
firstStart = false;
}
#endif
} |
Ok, my bad from the beginning! I simply omitted to set the day on which to wake up by calling the function Sorry for wasting your time. |
Actuallly, there is an issue here: since I set Perhaps the LowPower library should provide an |
I agree with you, since you set the mask, it is not mandatory to set the day. I don't think
and in your case, Specially in your case, the problem comes from I will soon propose a fix to set a correct value in the |
Thank you for your support. Yes, you're right about |
@ABOSTM: |
Hello,
Note that I'm confused about where to post this issue, as the problem described below is linked to the sleep modes, but the partial workaround I found involves the RTC library.
I'm experiencing an issue where after being put in sleep or deepSleep mode with a programed alarm time, the µC seems to never wake up.
The issue depicted here was tested with the following Nucleo boards: L476RG and G474RE; and the following Adafruit board: STM32F405 Feather Express.
When I try to use the sleep modes in combination with a RTC alarm-based wake up at a specific time, the board will never wake up unless the RTC has been reset when calling its
begin()
function. Whentrue
is passed to that function, the behavior is correct. However, what I would like to do involves preserving the RTC time across reset (the µC has an attached battery to preserve its time), thus resetting RTC at each boot is not a viable solution.Note that I used the very latest versions of RTC and Low Power libraries: #f620b53 version for RTC and #1a17d41 version for Low Power. I even integrated the latest PR #79 of the Low Power library without more luck.
Here is a minimal test I set up, displaying current time every minute on the serial console. Behavior can be switched between correct and faulty behavior using the
MODE
macro as depicted in the comments:Thanks for your support.
The text was updated successfully, but these errors were encountered: