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

 

1 ACCEPTED SOLUTION

Accepted Solutions
PGump.1
Senior III

Hi,

This is the way I do it in code...

	  		  V0u32 = 24 * 60 * 60; /// set for 24 hours
	  		  /// test/ limit timer to 17bits
	  		  if (v0u32 >= 0x10000UL) {		/// ? greater than 16bit
	  			  v1u32 = RTC_WAKEUPCLOCK_CK_SPRE_17BITS;
	  			  v0u32 &= 0x0FFFFUL;		/// force modulus
	  		  }
	  		  else {
	  			  v1u32 = RTC_WAKEUPCLOCK_CK_SPRE_16BITS;
	  		  }
	  		  HAL_RTCEx_SetWakeUpTimer_IT(&hrtc, v0u32, v1u32);

 I hope this helps.

Kind regards
Pedro

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

View solution in original post

23 REPLIES 23
PGump.1
Senior III

Hi,

This is the way I do it in code...

	  		  V0u32 = 24 * 60 * 60; /// set for 24 hours
	  		  /// test/ limit timer to 17bits
	  		  if (v0u32 >= 0x10000UL) {		/// ? greater than 16bit
	  			  v1u32 = RTC_WAKEUPCLOCK_CK_SPRE_17BITS;
	  			  v0u32 &= 0x0FFFFUL;		/// force modulus
	  		  }
	  		  else {
	  			  v1u32 = RTC_WAKEUPCLOCK_CK_SPRE_16BITS;
	  		  }
	  		  HAL_RTCEx_SetWakeUpTimer_IT(&hrtc, v0u32, v1u32);

 I hope this helps.

Kind regards
Pedro

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

Thank you Pedro, meaning my assumption is correct, if using RTC_WAKEUPCLOCK_CK_SPRE_17BITS, the wake up time will be range from 18h to ~36h

Hi Pedro, i use your code to set  v0u32 = 36 * 60 *60 36 hours,but i found the wakeup period always 24 hours,can not reach 36hours ,can you give some help?i hope the wakeup period can reach 36hours, thanks。

Post your code.

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

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();
}

HAL_PWR_EnterSTANDBYMode();

 

thanks

Hi,

Are you sure it is 24 hours? It looks like you are setting it for 17 hours...

Kind regards
Pedro

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

Sorry,i mean i want to set 36 hours period time,and i use yours code to change the v0u32,the fact is always 24hours awake,can you give some advices?thanks。

Hi, 

 

I think you cannot set v0u32 = 36 * 60 * 60, if you chose RTC_WAKEUPCLOCK_CK_SPRE_17BITS, 

v0u32  value should be 36 * 60 * 60 - 0xFFFF ?

 

 

 

Regards,

Kim

 

You didn't force modulus based on Pedro's answer previously. 

 v0u32 &= 0x0FFFFUL;		/// force modulus