本帖最后由 Aaron888 于 2010-12-23 22:41 编辑
如题:我的配置如下,有的时候程序下载下去,标志位有但是不进RTC中断,图片中是没有进中断时RTC寄存器的值,有劳香主赐教!
void RTC_Configuration(void)
{
RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR | RCC_APB1Periph_BKP, ENABLE);
PWR_BackupAccessCmd(ENABLE);
BKP_DeInit();
RCC_LSEConfig(RCC_LSE_ON);
while (RCC_GetFlagStatus(RCC_FLAG_LSERDY) == RESET)
{
}
RCC_RTCCLKConfig(RCC_RTCCLKSource_LSE);
RCC_RTCCLKCmd(ENABLE);
RTC_WaitForSynchro();
RTC_WaitForLastTask();
RTC_SetPrescaler(32767);//设置RTC预分频寄存器(RTC->RLH和RTC->RLL),RTC period = RTCCLK/RTC_PR = (32.768 KHz)/(32767+1)
RTC_WaitForLastTask();//等待RTC上一次操作结束
}
void RTCAlarm_Config(void)
{
EXTI_InitTypeDef EXTI_InitStructure;
NVIC_InitTypeDef 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);
NVIC_InitStructure.NVIC_IRQChannel = RTCAlarm_IRQChannel;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 2;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
RTC_SetAlarm(RTC_GetCounter()+1);
RTC_WaitForLastTask();
RTC_ITConfig(RTC_IT_ALR, ENABLE);//允许RTC闹钟中断(寄存器:RTC->CRH)
RTC_WaitForLastTask();//等待RTC上一次操作结束(寄存器:RTC->CRL)
}
void RTCAlarm_IRQHandler(void)
{
if( RTC_GetITStatus(RTC_IT_ALR) != RESET )
{
RTC_WaitForLastTask();
RTC_ClearFlag(RTC_FLAG_ALR);
RTC_WaitForLastTask();
RTC_SetAlarm(RTC_GetCounter()+1);
RTC_WaitForLastTask();
}
EXTI_ClearITPendingBit(EXTI_Line17);
}
} |