-
Notifications
You must be signed in to change notification settings - Fork 9
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
LowPower.deepSleep not working after modem.begin #36
Comments
Hi @janvrska, using rtc.begin(true) to reset the RTC after modem.begin(EU868) helped for me. |
Did you try to add a small delay after the modem begin? |
Seems strange as the My guess is something is pending which wake up the mcu. Calling @janvrska Your code is not correct: void loop() {
//Serial.begin(115200); --> Avoid to init each loop the instance
Serial.println("wakes up");
//delay(1000); --> Simply do a flush to prevent Serial IT to wakeup the board.
Serial.flush();
LowPower.deepSleep();
}
That is normal you can't send anything, if you remove the callback required for the modem timing or by reseting yourself the RTC as is do not set those callback. I tried within my LoRa-E5 mini and the low power is functional. @HelgeSeidel I don't understand your point:
This mean that if you call |
@fpistm Same behaviour on the RAK3172 Evaluation Board which is supported. Running the example as is will send the packet every 6 seconds. Calling rtc.begin(true) after modem.begin() and the example worked as expected. No battery connected to the board / RTC. |
Thank you for quick response. I tried LowPowerBasic example in ArduinoIDE and have same result as @HelgeSeidel After adding rtc.begin(true) after modem.begin, example works as expected |
@FRASTM |
Just to confirm that I also have the same issue on RAK3172 module (waking up after ~1s). Whoever came to this (temporary) solution - thank you a lot for saving lot of nerves! @HelgeSeidel |
In case of rtc reset, Can you please try with this: diff --git a/src/rtc.c b/src/rtc.c
index 73c911f..23cb143 100644
--- a/src/rtc.c
+++ b/src/rtc.c
@@ -411,6 +411,20 @@ bool RTC_init(hourFormat_t format, binaryMode_t mode, sourceClock_t source, bool
bool isAlarmBSet = false;
#endif
+ /* Ensure backup domain is enabled before we init the RTC so we can use the backup registers for date retention on stm32f1xx boards */
+ enableBackupDomain();
+
+ if (reset) {
+ resetBackupDomain();
+ /* After Backup domain reset, RTC is disabled and no RTC clock selected */
+ }
+
+#ifdef __HAL_RCC_RTCAPB_CLK_ENABLE
+ __HAL_RCC_RTCAPB_CLK_ENABLE();
+#endif
+ __HAL_RCC_RTC_ENABLE();
+ /* Also need to select the RTC clock source asap with RTC_initClock */
+
initFormat = format;
initMode = mode;
/* Ensure all RtcHandle properly set */
@@ -431,22 +445,6 @@ bool RTC_init(hourFormat_t format, binaryMode_t mode, sourceClock_t source, bool
#endif /* RTC_OUTPUT_REMAP_NONE */
#endif /* STM32F1xx */
- /* Ensure backup domain is enabled before we init the RTC so we can use the backup registers for date retention on stm32f1xx boards */
- enableBackupDomain();
-
- if (reset) {
- resetBackupDomain();
- }
-
-#ifdef __HAL_RCC_RTCAPB_CLK_ENABLE
- __HAL_RCC_RTCAPB_CLK_ENABLE();
-#endif
- __HAL_RCC_RTC_ENABLE();
-
- isAlarmASet = RTC_IsAlarmSet(ALARM_A);
-#ifdef RTC_ALARM_B
- isAlarmBSet = RTC_IsAlarmSet(ALARM_B);
-#endif
#if defined(STM32F1xx)
uint32_t BackupDate;
BackupDate = getBackupRegister(RTC_BKP_DATE) << 16;
@@ -510,6 +508,12 @@ bool RTC_init(hourFormat_t format, binaryMode_t mode, sourceClock_t source, bool
#else
RTC_setPrediv(predivAsync, predivSync);
#endif
+
+ isAlarmASet = RTC_IsAlarmSet(ALARM_A);
+#ifdef RTC_ALARM_B
+ isAlarmBSet = RTC_IsAlarmSet(ALARM_B);
+#endif
+
if (isAlarmASet) {
RTC_GetAlarm(ALARM_A, &alarmDay, &alarmHours, &alarmMinutes, &alarmSeconds, &alarmSubseconds, &alarmPeriod, &alarmMask);
} |
I've tried suggested change, but behaviour is the same. I also saw that setting up LoRaWAN (modem.begin) will reset time and date which are set up prior to that call |
If the rtc has already been initialized, we could skip the rtc init sequence requested by the Lorawan (calling a |
Change the STM32RTC : RTC_init function to force the update of the RTC ICS BIN and BDCU register in case of RTC is already initiliazed. See stm32duino/STM32RTC#106 |
I had the same issue and as reported, calling rtc.begin(true) after modem.begin() made it work. |
One difference seen inside the modem.begin() is that after the _rtc.begin(), there are two attachInterrupt :
Especially the attachSecondsInterrupt which also set the RTC WakeUpTimer interrupt. When rtc.begin() is called (independently) after the modem.init, the rtc.begin(true) is resetting the RTC registers, including wakeup Interrupt Enable bit, etc. The wakeUp Interrupt is no more enabled Could that explain the issue Does the issue change if the |
This indeed explains the issue, why the STM wakes up every second. Removing the attachSecondsInterrupt line solves this issue, as then the deepSleep works as expected. I tested this on a RAK3172. I also looked into why rtc.detachSecondsInterrupt after the modem.begin() does not work. In the RTC library, the detach seems to only detach the callback, but lets the one-second-wakeup in place. |
Fixes stm32duino#36. Signed-off-by: Frederic Pillon <[email protected]>
My mistake. I've tested and been able to reproduce. I thought it works as I've thought Thanks all for all your inputs and tests and sorry for the delay. |
@fpistm Thanks for fixing this! |
Thank you @fpistm - thats awesome to hear 👍🏻 |
@mrschuster @fpistm Thank you for fix, now everything works as expected. |
Expected Behavior
After setting
modem.begin(EU868)
andLowPower.deepSleep()
it goes sleep, and the chip will not wake up.Current Behavior
After setting
modem.begin(EU868)
andLowPower.deepSleep()
it goes sleep, but after around 900ms it wakes up.If
modem.begin(EU868)
isn't used then it works as intended, and the chip will not wake up.Minimal example
Power Profiler screenshot with modem.begin()
Power Profiler screenshot without modem.begin()
Details (what I tried)
I tried to look on
STM32LoRaWAN/src/STM32LoRaWAN.cpp
Lines 62 to 81 in 192c123
rtc.detachInterrupt, rtc.detachSecondsInterrupt, rtc.disableAlarm (both A ,B), but none of it worked.
Only when I after modem.begin() called rtc.end() and then rtc.begin() it stops waking up, but after joining the network (which was successfull), modem.send() didn't send any message (propably some problem with RTC settings that should have been set in modem.begin() and was cleared after rtc.end())
Context
I'm using supported LORA-E5 chip (STM32WLE5JC) on custom PCB
platformio.ini:
The text was updated successfully, but these errors were encountered: