cancel
Showing results for 
Search instead for 
Did you mean: 

Problems with RTC - wakeup from STOP-Mode

ledi001
Associate III

Hi,

i am using a STM32L010K8 MCU and i want to wake up from stop mode when a RTC-Wakeup interrupt occours. Here in this example i set the RTC wakeup interrupt for 30 seconds. Without entering the sleep mode the RTC IRQ works fine. But if the MCU enters the sleep mode, it seems that the MCU doesn't wake up anymore. Here are the regarding code instructions:

Set a flag in the Wake-up timer IRQ in file stm32l0xx_hal_rtc_ex.c

void HAL_RTCEx_WakeUpTimerIRQHandler(RTC_HandleTypeDef *hrtc)
{
  /* Get the pending status of the WAKEUPTIMER Interrupt */
  if (__HAL_RTC_WAKEUPTIMER_GET_FLAG(hrtc, RTC_FLAG_WUTF) != 0U)
  {
    wakeupFlag = 1;  // set the Flag if a wakeup event occours
  }
...
...
...

In main() routine, if wakeupFlag != 0 read some sensor values, otherwise enter STOP mode and sleep as long a new RTC-wakeup IRQ occours.

while (1)
{
  if(wakeupFlag == 0)
  {
    HAL_PWR_EnterSTOPMode(PWR_LOWPOWERREGULATOR_ON, PWR_STOPENTRY_WFI);
    __WFI();
  }
 
    if(wakeupFlag == 1)
    {
      if(sensorFlag == 1)
      {
        sensorFlag = 2;
        // read Sensor 1
      }
      else if(sensorFlag == 2)
      {
        sensorFlag = 3;
        // read Sensor 2
      }
      else if(sensorFlag == 3)
      {
        sensorFlag = 1;
        // read Sensor 3
      }
  }
}

2 REPLIES 2
ledi001
Associate III

​Problem solved!

I have the same issue. Thanks a lot for describing your solution...