如题所示:RTC中断,秒中断可进入,闹钟中断无法进入
中断函数随意写的,没贴出来
配置代码如下:
void NVIC_Configuration(void)
{
NVIC_InitTypeDef NVIC_InitStructure;
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_InitStructure.NVIC_IRQChannel = RTCAlarm_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
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);
NVIC_InitStructure.NVIC_IRQChannel = RTC_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
NVIC_InitStructure.NVIC_IRQChannelSubPriority =0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
}
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() + 2); //设置闹铃的值
RTC_WaitForLastTask();
RTC_ITConfig(RTC_IT_SEC,ENABLE);
RTC_WaitForLastTask();
RTC_ITConfig(RTC_IT_SEC,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_SEC,ENABLE);
RTC_WaitForLastTask();
RTC_ITConfig(RTC_IT_SEC,ENABLE); //设置闹铃中断
RTC_WaitForLastTask();
}
}
此帖出自
小平头技术问答
一周热门 更多>