Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

STM32 wake up from standby by RTC

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:

  1. reset
  2. set RTC
  3. enter standby
  4. waiting for interrupt
  5. wake-up

But second and next cycles wake up immediately after entering standby (3).

like image 414
luden Avatar asked Feb 13 '17 14:02

luden


People also ask

What is RTC wakeup?

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.

What is a standby mode in STM32?

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.

Does STM32 have RTC?

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.


Video Answer


1 Answers

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);
like image 109
Bence Kaulics Avatar answered Sep 26 '22 20:09

Bence Kaulics