I am programming STM32L051R8 and have next problem. I'm trying use standby mode in most part of time, and sometimes wake up by RTC, it is an auto wake-up. If I work without sleep - all works perfectly, I got an RTC interrupt every time, but when I use standby - don't.
If I use standby, I have a good first cycle:
But second and next cycles wake up immediately after entering standby (3).
RTC_WAKEUP and ELAPSED_REALTIME_WAKEUP will wake up the device out of sleep mode. If your PendingIntent is a broadcast PendingIntent , Android will keep the device awake long enough for onReceive() to complete.
Power can also be saved by disabling the peripherals and GPIO pins before going in the stop or sleep mode. This prevents any leakage current from draining out the battery. Standby mode. In standby mode, all the clocks are stopped, and static RAM loses all its content. Only the RTC clock is active.
Most of the STM32 devices have RTC (Real Time Clock) built in which can keep the track of the current time and date. RTC can be used for chronometers, alarm clocks, watches, small electronic agendas, and many other devices and today we are going to learn HOW to access internal RTC in STM32.
When the microcontroller is in Standby mode and an RTC interrupt occurs the WUF: Wakeup flag will be set by the hardware in the PWR control/status register (Page 162).
Bit 0 WUF: Wakeup flag
This bit is set by hardware and cleared by a system reset or by setting the CWUF bit in the PWR power control register (PWR_CR)
0: No wakeup event occurred
1: A wakeup event was received from the WKUP pin or from the RTC alarm (Alarm A or Alarm B), RTC Tamper event, RTC TimeStamp event or RTC Wakeup).
Initially this is cleared by a system reset so that is why your first cycle is OK. But after a wake-up from standby you have to clear it manually using the CWUF bit in the PWR control register. If you do not do this then the controller will wake up at once as the this bit signals an occurred wake-up event.
You can access the register directly to set this bit or with HAL library the following macro can be used:
__HAL_PWR_CLEAR_FLAG(PWR_FLAG_WU);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With