不知道是哪里配置的问题,老是进入去中断
中断函数随便写了一个,代码没贴出来
初始化配置RTC_Config()
配置如下:
/*初次进入RTC配置*/
void RTC_Configuration(void) { RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR,ENABLE); //开启PWR时钟 RCC_APB1PeriphClockCmd(RCC_APB1Periph_BKP,ENABLE); //开启BKP时钟
PWR_BackupAccessCmd(ENABLE); //开启RTC和后备寄存器的访问
BKP_DeInit(); RCC_LSEConfig(RCC_LSE_ON); //设置外部低速晶振 while(RESET == RCC_GetFlagStatus(RCC_FLAG_LSERDY)) //等待时钟稳定 {;} RCC_RTCCLKConfig(RCC_RTCCLKSource_LSE); //设置LSE为RTC时钟 RCC_RTCCLKCmd(ENABLE); //使能RTC时钟 RTC_WaitForSynchro(); //等待时钟与APB1时钟同步 RTC_WaitForLastTask(); //等待最近一次对RTC寄存器的操作完成 RTC_SetPrescaler(32767); //设置RTC的预分频值 RTC_WaitForLastTask(); //等待最近一次对RTC寄存器的操作完成 RTC_SetAlarm(RTC_GetCounter() + 10); //设置闹铃的值 RTC_WaitForLastTask();
RTC_ITConfig(RTC_IT_ALR,ENABLE); //设置闹铃中断 RTC_WaitForLastTask(); }
void RTC_Config(void) { RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR,ENABLE); RCC_APB1PeriphClockCmd(RCC_APB1Periph_BKP,ENABLE);
PWR_BackupAccessCmd(ENABLE);
if(0xA5A5 != BKP_ReadBackupRegister(BKP_DR1)) { RTC_Configuration(); BKP_WriteBackupRegister(BKP_DR1,0xA5A5); }else { if(RESET != RCC_GetFlagStatus(RCC_FLAG_LPWRRST)) //如果低功耗复位 {;} if(RESET != RCC_GetFlagStatus(RCC_FLAG_PINRST)) //如果wakeup复位 {;} RCC_ClearFlag();
while(RESET == RCC_GetFlagStatus(RCC_FLAG_LSERDY)) //等待时钟稳定 {;} RTC_WaitForLastTask(); RTC_SetAlarm(RTC_GetCounter() + 10); //设置闹铃的值 RTC_WaitForLastTask(); RTC_ITConfig(RTC_IT_ALR,ENABLE); //设置闹铃中断 RTC_WaitForLastTask(); } }
中断配置:
void NVIC_Configuration(void) { NVIC_InitTypeDef NVIC_InitStruction; EXTI_InitTypeDef EXTI_InitStructure;
#ifdef VECT_TAB_RAM NVIC_SetVectorTable(NVIC_VectTab_RAM,0x0); #else NVIC_SetVectorTable(NVIC_VectTab_FLASH,0x0); #endif //VECT_TAB_RAM
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
NVIC_InitStruction.NVIC_IRQChannel = RTCAlarm_IRQn; NVIC_InitStruction.NVIC_IRQChannelPreemptionPriority = 0; NVIC_InitStruction.NVIC_IRQChannelSubPriority = 1; NVIC_InitStruction.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStruction);
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);
}
|