cancel
Showing results for 
Search instead for 
Did you mean: 

RTC, how to configure periodic wake up time of 24h

chai2145
Associate III

Hi, I'm using STM32L0 series MCU to configure the RTC to wake up after 24 hour during sleep/standby mode. Understand that we need to configure the Wake up clock to use 1Hz with 1 bit wake up counter added so that it can have the wake up time from 18h to ~36h.

Anyone know what number of wake up counter I have to set in order to have 24 hours wake up time? The wake up counter is 16 bit with max value of 65535.

if configure the Wake up clock to use 1Hz with 1 bit wake up counter added (RTC_WAKEUPCLOCK_CK_SPRE_17BITS), we can set the wake up time range from < 1hour up to 36h  or from 18h up to 36h?

 

chai2145_0-1727408466608.png

 

23 REPLIES 23

thanks Kim,i know you mean,but my code is set  if v0u32 = 36 * 60 * 60,

if( v0u32 > 0xFFFF )
{
v1u32 = RTC_WAKEUPCLOCK_CK_SPRE_17BITS;

v0u32 &= 0xFFFF;
}

 

v0u32 &= 0xFFFF  the same as 36 * 60 * 60 - 0xFFFF,

thanks。

Hi freedomcain

Thanks for pointing out.

I think compiler do the typecasting by convert 0xFFFF to 32 bits and probably overflow occured , as you see that it is important to putting 'UL' in constant value of 0x0FFFFUL, maybe you can print the result of v0u32 &= 0xFFFF, for obeservation. I'm not sure. 

 

 

Regards,

Kim

thanks kim,the result is the same,i  print  hrtc.Instance->WUTR param is  64065,the same as 36 * 60 * 60 - 0xFFFF。so how can i set the period time more than 18 hours ,24 hours,please help,thanks。

What series of MCU are you using, I'm using STM32L071, not sure if different series have different wake up period time range to set, could you check the datasheet?

Hi,

64065 = 17 hours, 47 minutes, 45 seconds...

Kind regards
Pedro

AI = Artificial Intelligence, NI = No Intelligence, RI = Real Intelligence.

thanks Kim,the same to you, STM32L071KZT6。

thanks Pedro,but  i set RTC_WAKEUPCLOCK_CK_SPRE_17BITS,so how can i set the period time more than 18 hours ,24 hours,can you give some code advice,thanks。

Hi,

Provide evidence that the RTC_WAKEUPCLOCK_CK_SPRE_17BITS is set.

Provide evidence that the timer is ALWAYS 24 hours.

Kind regards
Pedro

AI = Artificial Intelligence, NI = No Intelligence, RI = Real Intelligence.

i use this code to set RTC_WAKEUPCLOCK_CK_SPRE_17BITS, debug can comfirm the RTC_WAKEUPCLOCK_CK_SPRE_17BITS is set,so if i set RTC_WAKEUPCLOCK_CK_SPRE_17BITS, v0u32 = 64065,the fact is 17 hours, how can i set the period time more than 24 hours if v0u32 = 129600,can you give some code advice? thanks

 

unsigned int v0u32 = 36 * 60 * 60,v1u32 = 0;

if( v0u32 > 0xFFFF )
{
v1u32 = RTC_WAKEUPCLOCK_CK_SPRE_17BITS;

v0u32 &= 0xFFFF;
}
else
{
v1u32 = RTC_WAKEUPCLOCK_CK_SPRE_16BITS;
}


if (HAL_RTCEx_SetWakeUpTimer_IT(&hrtc, v0u32, v1u32) != HAL_OK)
{
Error_Handler();
}

Hi,

Print hrtc.Instance->CR after HAL_RTCEx_SetWakeUpTimer_IT().

Kind regards
Pedro

AI = Artificial Intelligence, NI = No Intelligence, RI = Real Intelligence.