前一阵写好的程序,拷机大概有两个多月了,一直没发现问题。这几天准备批量的时候,突然发现RTC时钟出现问题。装上纽扣电池,第一次烧写程序后,无法进入RTC中断。代码如下:
void RTC_Configuration(void)
{
/* Enable PWR and BKP clocks */
RCC_APB1PeriphClockCmd (RCC_APB1Periph_PWR | RCC_APB1Periph_BKP, ENABLE);
/* Allow access to BKP Domain */
PWR_BackupAccessCmd(ENABLE);
if (BKP_ReadBackupRegister(BKP_DR1)!=0xA5A5)
{
/* Reset Backup Domain */
BKP_DeInit();
BKP_WriteBackupRegister(BKP_DR2,2008);
BKP_WriteBackupRegister(BKP_DR3,1);
BKP_WriteBackupRegister(BKP_DR4,1);
BKP_WriteBackupRegister(BKP_DR1, 0xA5A5);
RTC_SetCounter(0x0);
/* Enable LSE */
RCC_LSEConfig(RCC_LSE_ON);
/* Wait till LSE is ready */
while (RCC_GetFlagStatus(RCC_FLAG_LSERDY) == RESET)
{}
/* Select LSE as RTC Clock Source */
RCC_RTCCLKConfig(RCC_RTCCLKSource_LSE);
/* Enable RTC Clock */
RCC_RTCCLKCmd(ENABLE);
/* Wait for RTC registers synchronization */
RTC_WaitForSynchro();
/* Wait until last write operation on RTC registers has finished */
RTC_WaitForLastTask();
RTC_WaitForSynchro();
RTC_WaitForLastTask();
/* Enable the RTC Second */
RTC_ITConfig(RTC_IT_SEC, ENABLE);
/* Wait until last write operation on RTC registers has finished */
RTC_WaitForLastTask();
/* Set RTC prescaler: set RTC period to 1sec */
RTC_SetPrescaler(32767);
/* RTC period = RTCCLK/RTC_PR = (32.768 KHz)/(32767+1) */
/* Wait until last write operation on RTC registers has finished */
RTC_WaitForLastTask();
}
else
{
RTC_WaitForLastTask();
/* Enable the RTC Second */
RTC_ITConfig(RTC_IT_SEC, ENABLE);
RTC_WaitForLastTask();
}
CheckForDaysElapsed();
}
该问题在断电后,拿掉纽扣电池,重新上电装电池后一切恢复正常。
我感觉应该是第一次检测备份区,并设置,然后进行RTC相关配置,开启RTC中断不成功。
哪位给看看代码什么地方出问题了。 |