How to wake-up on time in time with RTC ?
Hi eveyone,
I have a problem with RTC wake up. I use LSE 32.768kHz.
I run example from manufacturer to wake up MCU from Stand by mode very 1min, 2mins. Everything work okay.
But, When I put delay 10s and HAL_PWR_EnterSTANDBYMode(); into while(1). Everything is not okay.
The RTC does not wake up on time, when I delay 10s it will lack of 10s, when I delay 20s it lack of 20s. I try to do it many times.
How can I wake-up mcu on time in time I set?
Thank you for any help.
int main(void)
{
HAL_Init();
/* Configure LED3 */
BSP_LED_Init(LED3);
/* Configure the system clock to 2 MHz */
SystemClock_Config();
/* Configure the system power */
SystemPower_Config();
/* Check and handle if the system was resumed from StandBy mode */
if(__HAL_PWR_GET_FLAG(PWR_FLAG_SB) != RESET)
{
/* Clear Standby flag */
__HAL_PWR_CLEAR_FLAG(PWR_FLAG_SB);
}
/* Disable Wakeup Counter */
HAL_RTCEx_DeactivateWakeUpTimer(&RTCHandle);
/*## Setting the Wake up time ############################################*/
/* RTC Wakeup Interrupt Generation:
Wakeup Time Base = (RTC_WAKEUPCLOCK_RTCCLK_DIV /(LSE or LSI))
Wakeup Time = Wakeup Time Base * WakeUpCounter
= (RTC_WAKEUPCLOCK_RTCCLK_DIV /(LSE or LSI)) * WakeUpCounter
==> WakeUpCounter = Wakeup Time / Wakeup Time Base
To configure the wake up timer to 4s the WakeUpCounter is set to 0x1FFF:
RTC_WAKEUPCLOCK_RTCCLK_DIV = RTCCLK_Div16 = 16
Wakeup Time Base = 16 /(~39.000KHz) = ~0,410 ms
Wakeup Time = ~4s = 0,410ms * WakeUpCounter
==> WakeUpCounter = ~4s/0,410ms = 9750 = 0x2616 */
HAL_RTCEx_SetWakeUpTimer_IT(&RTCHandle, 0x2616, RTC_WAKEUPCLOCK_RTCCLK_DIV16);
/* Insert 5 seconds delay */
HAL_Delay(5000);
/* Clear all related wakeup flags */
__HAL_PWR_CLEAR_FLAG(PWR_FLAG_WU);
while (1)
{
HAL_Delay(10000);
/* Request to enter STANDBY mode (Wake Up flag is cleared in PWR_EnterSTANDBYMode function) */
HAL_PWR_EnterSTANDBYMode();
}
}