我现在在调439的RTC功能,参照407的一个例程,写了一下RTC的初始化代码,我希望用
RTC的Wakeup中断来产生一个秒中断,但是预期的RTC Wakeup秒钟没有产生,不知道是
怎么回事,大家有时间帮我看一下吗,代码如下
uint32_t InitRTC(void)
{
RTC_InitTypeDef RTC_InitStructure;
EXTI_InitTypeDef EXTI_InitStructure;
uint32_t AsynchPrediv=0,SynchPrediv=0;
RTC_TimeTypeDef RTC_TimeStructure;
RTC_AlarmTypeDef RTC_AlarmStructure;
u32 tmp_hh = 0x01, tmp_mm = 0x01, tmp_ss = 0x01;
if (RTC_ReadBackupRegister(RTC_BKP_DR0) != 0x32F2)//未设置时间
{
RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE);
PWR_BackupAccessCmd(ENABLE);//使能RTC操作
RCC_LSEConfig(RCC_LSE_ON);//使用外部晶振
while(RCC_GetFlagStatus(RCC_FLAG_LSERDY)==RESET);//等待外部晶振准备好
RCC_RTCCLKConfig(RCC_RTCCLKSource_LSE);//选择RTC时钟源
SynchPrediv=0xFF;
AsynchPrediv=0x7F;
RCC_RTCCLKCmd(ENABLE);//使能RTC时钟
RTC_WaitForSynchro();//等待RTC APB寄存器同步
RTC_InitStructure.RTC_AsynchPrediv = AsynchPrediv;//RTC 异步除数 (<0X7F)
RTC_InitStructure.RTC_SynchPrediv = SynchPrediv;//RTC 同步除数 (<0X7FFF)
RTC_InitStructure.RTC_HourFormat = RTC_HourFormat_24;//24小时制
if(RTC_Init(&RTC_InitStructure) == ERROR)
return 1;
RTC_TimeStructure.RTC_H12= RTC_H12_AM;
RTC_TimeStructure.RTC_Hours = tmp_hh;
RTC_TimeStructure.RTC_Minutes = tmp_mm;
RTC_TimeStructure.RTC_Seconds = tmp_ss;
if(RTC_SetTime(RTC_Format_BIN, &RTC_TimeStructure)!=ERROR)
RTC_WriteBackupRegister(RTC_BKP_DR0,0x32F2);
}
else//已设置时间
{
RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE);
 
WR_BackupAccessCmd(ENABLE);//使能RTC操作
RTC_WaitForSynchro();//等待RTC APB寄存器同步
RTC_ClearFlag(RTC_FLAG_ALRAF);//清除RTC闹钟标志
//EXTI_ClearITPendingBit(EXTI_Line17);//清除中断线17标志(内部连接至RTC闹钟)
EXTI_ClearITPendingBit(EXTI_Line22);//清除中断线22标志(RTC Wakeup中断)
}
RTC_WakeUpClockConfig(RTC_WakeUpClock_CK_SPRE_16bits);
RTC_SetWakeUpCounter(1);
RTC_ITConfig(RTC_IT_WUT, ENABLE);//使能闹钟A的中断
RTC_ClearFlag(RTC_FLAG_WUTF);
RTC_WakeUpCmd(ENABLE);
/* Configure Button EXTI line */
EXTI_InitStructure.EXTI_Line = EXTI_Line22;
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling;
EXTI_InitStructure.EXTI_LineCmd = ENABLE;
EXTI_Init(&EXTI_InitStructure);
EXTI_ClearITPendingBit(EXTI_Line22);
return 0;
}
void EnableRTCWakeupIRQ(void)
{
NVIC_InitTypeDef NVIC_InitStructure;
NVIC_InitStructure.NVIC_IRQChannel = RTC_WKUP_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x0F;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x0F;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
}
---------------------------------
唤醒中断是在调用了函数InitRTC时候再调用的,如下:
InitRTC();
EnableRTCWakeupIRQ();
中断服务程序如下:
void RTC_WKUP_IRQHandler(void)
{
TracePrintf("RTC_WKUP_IRQHandler ==> 0 ");
if(EXTI_GetITStatus(EXTI_Line22) != RESET)
{
TracePrintf("RTC_WKUP_IRQHandler ==> 1 ");
EXTI_ClearITPendingBit(EXTI_Line22);
if (RTC_GetFlagStatus(RTC_FLAG_WUTF))
{
TracePrintf("RTC_WKUP_IRQHandler ==> 2 ");
RTC_ClearFlag(RTC_FLAG_WUTF);
// do something other
}
}
}
现在发现根本就没进中断。
一周热门 更多>