4. 附上源码
void enter_stop_rtc(unsigned stoptime)
{
/* Enable Ultra low power mode */
HAL_PWREx_EnableUltraLowPower(); //必须要加,否则多出1.4uA的电流
/* Enable Fast WakeUP */
HAL_PWREx_EnableFastWakeUp();
/* Disable Wakeup Counter */
HAL_RTCEx_DeactivateWakeUpTimer(&hrtc);
/*To configure the wake up timer to 4s the WakeUpCounter is set to 0x242B:
RTC_WAKEUPCLOCK_RTCCLK_DIV = RTCCLK_Div16 = 16
Wakeup Time Base = 16 /(~37KHz) = ~0,432 ms
Wakeup Time = ~5s = 0,432ms * WakeUpCounter
==> WakeUpCounter = ~5s/0,432ms = 11562 */
HAL_RTCEx_SetWakeUpTimer_IT(&hrtc, stoptime*2396, RTC_WAKEUPCLOCK_RTCCLK_DIV16);
system_power_config();
/* Enter Stop Mode */
HAL_PWR_EnterSTOPMode(PWR_LOWPOWERREGULATOR_ON, PWR_STOPENTRY_WFI);
/* Clear all related wakeup flags */
__HAL_PWR_CLEAR_FLAG(PWR_FLAG_WU); //必须要加,否则多出1.4uA的电流
__HAL_RTC_WAKEUPTIMER_EXTI_CLEAR_FLAG(); //清除标志,否则第二次以后无法进入休眠
SystemClock_Config();
}
|