使用的芯片是STM32L152C8,使用ALARMA每到1秒钟时产生中断,刷新时间显示。程序如下:
/**********************************************************************************
* 名称:RTC_NVIC_Config()
* 功能:RTC的中断配置,分钟中断,用于更新显示
* 入口参数:无
* 出口参数:无
***********************************************************************************/
void RTC_NVIC_Config(void)
{
RTC_AlarmTypeDef RTC_AlarmStruct;
NVIC_InitTypeDef NVIC_InitStructure;
EXTI_InitTypeDef EXTI_InitStructure;
/* EXTI configuration */
EXTI_ClearITPendingBit(EXTI_Line17);
EXTI_InitStructure.EXTI_Line = EXTI_Line17;
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising;
EXTI_InitStructure.EXTI_LineCmd = ENABLE;
EXTI_Init(&EXTI_InitStructure);
/* Configure one bit for preemption priority */
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);
/* Enable the RTC Interrupt */
NVIC_InitStructure.NVIC_IRQChannel = RTC_Alarm_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 5;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
RTC_AlarmStruct.RTC_AlarmMask=RTC_AlarmMask_DateWeekDay|RTC_AlarmMask_Hours|RTC_AlarmMask_Minutes; //取消秒中断的屏蔽
RTC_AlarmStruct.RTC_AlarmTime.RTC_Seconds=1; //每到1秒时产生中断
RTC_SetAlarm(RTC_Format_BCD, RTC_Alarm_A, &RTC_AlarmStruct);
/* 使能闹钟A中断 */
RTC_ITConfig(RTC_IT_ALRA, ENABLE);
/* Enable the alarmA */
RTC_AlarmCmd(RTC_Alarm_A, ENABLE);
}
/**
* @brief This function handles RTC_Alarm interrupt request.
* @param None
* @retval None
*/
void RTC_Alarm_IRQHandler(void)
{
if(RTC_GetITStatus(RTC_IT_ALRA) != RESET)
{
/* Clear RTC AlarmA Flags */
RTC_ClearITPendingBit(RTC_IT_ALRA);
Time_Display();
/* Clear the EXTIL line 17 */
EXTI_ClearITPendingBit(EXTI_Line17);
}
}
现在的情况是一上电,就立即进入中断刷新时间显示,而且是一直不断的进入中断,通过单步执行调试的话可以看到中断标志位被清除了的,而且单步执行后偶尔也会正常,不再进入中断。有没有人遇到这种情况的?
|