how get the remaining time of RTC wakeup timer
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
2025-03-18 9:26 PM - last edited on 2025-03-21 1:54 AM by Andrew Neil
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.
- Labels:
-
Power
-
RTC
-
STM32L0 Series
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
2025-03-19 12:55 AM
Hello @jinyi7016
Please refer to the article How to use the RTC in STM32 microcontrollers for periodic wake-up and elapsed time calculation.
Thanks
Omar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
2025-03-19 6:43 PM - edited 2025-03-19 6:54 PM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
2025-03-21 1:53 AM - edited 2025-03-21 1:55 AM
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
Thanks
Omar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
2025-03-21 8:09 AM
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:
- 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.
- The source clock of the wake-up timer must be the RTC's asynchronous prescaler counter.
Let's dive into the details and steps:
- 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.
- 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,
