各位大虾:
小弟在试用RTC秒中断和报警中断功能,秒中断正常,ALRF=1但是不进报警中断,不知道是哪里的配置不对,大虾们指教,代码如下:
void RTC_Configuration(void)
{
NVIC_InitTypeDef NVIC_InitStructure;
EXTI_InitTypeDef EXTI_InitStructure;
unsigned long Num;
RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR | RCC_APB1Periph_BKP, ENABLE);//电源时钟和备份时钟使能
PWR_BackupAccessCmd(ENABLE);//允许修改备份域参数和RTC
BKP_DeInit();
RCC_LSEConfig(RCC_LSE_ON);
while (RCC_GetFlagStatus(RCC_FLAG_LSERDY) == RESET)
{
}
RCC_RTCCLKConfig(RCC_RTCCLKSource_LSE);//选择外部32768作为RTC时钟
RCC_RTCCLKCmd(ENABLE);//RTC时钟使能
RTC_WaitForSynchro();
RTC_WaitForLastTask();
RTC_ITConfig(RTC_IT_SEC, ENABLE);//允许RTC秒中断
RTC_WaitForLastTask();
//RTC_ITConfig(RTC_IT_ALR, ENABLE);//允许RTC闹钟中断(寄存器:RTC->CRH)
RTC_WaitForLastTask();
RTC_SetPrescaler(32767);//设置RTC预分频寄存器
RTC_WaitForLastTask();
Num = RTC_GetCounter();
Num += 1;
RTC_SetAlarm(Num);//设置RTC闹钟寄存器
RTC_WaitForLastTask();
NVIC_InitStructure.NVIC_IRQChannel = RTC_IRQChannel;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 2;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
NVIC_InitStructure.NVIC_IRQChannel = RTCAlarm_IRQChannel;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
EXTI_InitStructure.EXTI_Line = EXTI_Line17;
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising;
EXTI_InitStructure.EXTI_LineCmd = ENABLE;
EXTI_Init(&EXTI_InitStructure);
}
void RTC_IRQHandler(void)
{
if (RTC_GetITStatus(RTC_IT_SEC) != RESET)
{
// Clear the RTC Second interrupt
RTC_ClearITPendingBit(RTC_IT_SEC);
}
}
void RTCAlarm_IRQHandler(void)
{
unsigned long Num;
if (RTC_GetITStatus(RTC_IT_ALR) != RESET)
{
// Clear the RTC Alarm interrupt
RTC_ClearITPendingBit(RTC_IT_ALR);
EXTI_ClearITPendingBit(EXTI_Line17);
Num = RTC_GetCounter();
Num += 1;
RTC_SetAlarm(Num);
}
} |