本帖最后由 Sam131208 于 2023-11-29 08:57 编辑
RTC唤醒配置为0.5秒唤醒一次,上电后,前三次唤醒,大概1秒多才中断一次。
另外还有未确认的问题,CPU计算任务重的时候,0.5秒的中断,似乎也变为了1秒钟。
在STOP2模式下,0.5秒中断比较稳定,尚未发现问题。
下面时RTC初始化:
中断处理:
EXTI_ClrITPendBit(EXTI_LINE20);
if (RTC_GetITStatus(RTC_INT_WUT) != RESET)
{
RTC_ClrIntPendingBit(RTC_INT_WUT);
}
初始化: RTC_InitType RTC_InitStructure;
RTC_DateType RTC_DateStructure;
RTC_TimeType RTC_TimeStructure;
EXTI_InitType EXTI_InitStructure;
NVIC_InitType NVIC_InitStructure;
PWR_BackupAccessEnable(ENABLE);
if (0xA5A5 != BKP_ReadBkpData(0x0000) )
{
/* Enable the PWR clock */
RCC_EnableAPB1PeriphClk(RCC_APB1_PERIPH_PWR, ENABLE);
RCC_EnableAPB2PeriphClk(RCC_APB2_PERIPH_AFIO, ENABLE);
/* Allow access to RTC */
PWR_BackupAccessEnable(ENABLE);
/* Disable RTC clock */
RCC_EnableRtcClk(DISABLE);
/* Enable the LSE OSC32_IN PC14 */
RCC_EnableLsi(DISABLE); // LSI is turned off here to ensure that only one clock is turned on
RCC_ConfigLse(RCC_LSE_ENABLE,0x1FF);
/****Waite LSE Ready *****/
while(RCC_GetFlagStatus(RCC_LDCTRL_FLAG_LSERD) == RESET){
};
RCC_ConfigRtcClk(RCC_RTCCLK_SRC_LSE);
RCC_EnableRtcClk(ENABLE);
RTC_WaitForSynchro();
/* Configure the RTC data register and RTC prescaler */
RTC_InitStructure.RTC_AsynchPrediv = 0x7F;
RTC_InitStructure.RTC_SynchPrediv = 0xff;
RTC_InitStructure.RTC_HourFormat = RTC_24HOUR_FORMAT;
/* Check on RTC init */
if (RTC_Init(&RTC_InitStructure) == ERROR)
{
}
RTC_DateStructure.WeekDay = 7;
RTC_DateStructure.Date = 1;
RTC_DateStructure.Month = 10;
RTC_DateStructure.Year = 23;
if(RTC_SetDate(RTC_FORMAT_BIN, &RTC_DateStructure) == ERROR){
}
RTC_TimeStructure.H12 = RTC_AM_H12;
RTC_TimeStructure.Hours = 0;
RTC_TimeStructure.Minutes = 0;
RTC_TimeStructure.Seconds = 0;
if (RTC_ConfigTime(RTC_FORMAT_BIN, &RTC_TimeStructure) == ERROR){
}
/* wake up clock select */
RTC_ConfigWakeUpClock(RTC_WKUPCLK_RTCCLK_DIV16);
/* wake up timer value */
RTC_SetWakeUpCounter(0x400 - 1);
BKP_WriteBkpData(0x0000, 0xA5A5);
}
EXTI_ClrITPendBit(EXTI_LINE20);
EXTI_InitStructure.EXTI_Line = EXTI_LINE20;
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising;
EXTI_InitStructure.EXTI_LineCmd = ENABLE;
EXTI_InitPeripheral(&EXTI_InitStructure);
/* Enable the RTC WakeUp Interrupt */
NVIC_InitStructure.NVIC_IRQChannel = RTC_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
/* Enable the RTC Wakeup Interrupt */
RTC_ClrIntPendingBit(RTC_INT_WUT);
RTC_ConfigInt(RTC_INT_WUT, ENABLE);
RTC_EnableWakeUp(ENABLE);
|