cancel
Showing results for 
Search instead for 
Did you mean: 

how get the remaining time of RTC wakeup timer

jinyi7016
Associate

STM 32L 051 

use HAL_RTCEx_SetWakeUpTimer_IT() to wake up standby mode,it is work well.

when the wake up source is not RTC(maybe wkup pin  or NRST pin) ,how get the remaining time of RTC timer?

The value of HAL_RTCEx_GetWakeUpTimer() is not change.it is the value of HAL_RTCEx_SetWakeUpTimer_IT() set.

4 REPLIES 4
Saket_Om
ST Employee

Hello @jinyi7016 

Please refer to the article How to use the RTC in STM32 microcontrollers for periodic wake-up and elapsed time calculation.

If your question is answered, please close this topic by clicking "Accept as Solution".

Thanks
Omar

thanks reply. 

HAL_RTC_GetTime() can get the calendar time to calculate the remaining time.

but I really want to know:

1、

Can function HAL_RTCEx_GetWakeUpTimer()    get the remaining time of RTC timer? or only the value  HAL_RTCEx_SetWakeUpTimer_IT() set.

 

 

 

Hello @jinyi7016 

The function HAL_RTCEx_GetWakeUpTimer() get just the value of WUTR register previously set with the function HAL_RTCEx_SetWakeUpTimer_IT(). 

Please refer to for more details the UM174 more details 

Saket_Om_0-1742546765122.png

 

 

If your question is answered, please close this topic by clicking "Accept as Solution".

Thanks
Omar
ALABSTM
ST Employee

Hi @jinyi7016,

Here is a solution. However, it supposes you are not using the RTC Calendar, only the RTC WUT (Wake-Up Timer).

To better illustrate it, I join the figure below adapted from the reference manual of the STM32L0 series. The idea is the following:

  • manage to tune the RTC's prescalers to make the RTC_SSR register synchronous with the WUT counter,
  • read the RTC_SSR register once the WUT counter is launched, then when we want to know the current value of the WUT counter, to finally calculate the difference.

There are two cases:

  1. The source clock of the wake-up timer is the RTC's clock source RTCCLK (HSE, LSE, or LSI clock) divided by the WUT prescaler.
  2. The source clock of the wake-up timer must be the RTC's asynchronous prescaler counter.

Let's dive into the details and steps:

  1. The source clock of the wake-up timer is the RTC's clock source RTCCLK (HSE, LSE, or LSI clock) divided by the WUT prescaler.
    • For this, WUCKSEL[2:0] = 0xx in the RTC_CR register.
    • Make the RTC_SSR register synchronous with the WUT counter. For this:

      • Set the synchronous prescaler to 0. For this, PREDIV_S[14:0] = 0 in the RTC_PRER register.
      • Set the asynchronous prescaler to the same value as the WUT prescaler. For this,
        • PREDIV_A[6:0] = 15 in the RTC_PRER register if WUCKSEL[2:0] = 000xb in the RTC_CR register.
        • PREDIV_A[6:0] = 7   in the RTC_PRER register if WUCKSEL[2:0] = 001xb in the RTC_CR register. 
        • PREDIV_A[6:0] = 3   in the RTC_PRER register if WUCKSEL[2:0] = 010xb in the RTC_CR register. 
        • PREDIV_A[6:0] = 1   in the RTC_PRER register if WUCKSEL[2:0] = 011xb in the RTC_CR register. 
  2.  The source clock of the wake-up timer must be the RTC's asynchronous prescaler counter.
    • For this, WUCKSEL[2:0] = 1xx in the RTC_CR register.
    • Make the RTC_SSR register synchronous with the WUT counter. For this:
      • Set the synchronous prescaler to 0. For this, PREDIV_S[14:0] = 0 in the RTC_PRER register.

 

Now, to estimate the current value in the WUT counter:

  • Read the RTC_SSR register when the WUT counter is launched at t=0µs.
  • Read the RTC_SSR register at t>0µs.
  • Calculate the difference.

 

I hope this helps.

With regards,

 

ALABSTM_1-1742568920962.png