在RTC调试过程中,出现ALR寄存器数据复位不保存的情况,而CNT可以保存.按手册上讲,这两个寄存器都在后备域中,在未发生后备域复位的情况下,这些数据应该不保存才对啊,而现在ALR不保存,CNT却可以,这是为何??以下先贴初始化程序,后贴图,望有人能解决及回答.
程序如下 : main() { u32 temp;
RCC_init(); Gpio_int(); Usart_int(); BKP_init(); Timer_init(); NVIC_init(); USART_Start_Recieive(USART1,USART1_datas);
while(1) …………………………………………………………….
void BKP_init(void) { /* Enable PWR and BKP clocks */ RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR | RCC_APB1Periph_BKP, ENABLE); /* Allow access to BKP Domain in order to enable rtc registers*/ PWR_BackupAccessCmd(ENABLE); /* Clear Tamper pin Event(TE) pending flag */ BKP_ClearFlag(); /* Enable Tamper pin */ BKP_TamperPinCmd(DISABLE); if(BKP_ReadBackupRegister(BKP_DR1) != 0xA6A7) { /* Backup data register value is not correct or not yet programmed (when the first time the program is executed) */
/* RTC Configuration */ GPIO_CPLBits(GPIOC,GPIO_Pin_6); RTC_init(); RTC_WaitForLastTask(); RTC_SetAlarm(80); RTC_WaitForLastTask(); BKP_WriteBackupRegister(BKP_DR1, 0xA6A7); } else { /* Wait for RTC registers synchronization */ RTC_WaitForLastTask(); //RTC_SetAlarm(BKP_ReadBackupRegister(BKP_DR2)); RTC_WaitForLastTask();
RTC_WaitForSynchro();
/* Enable the RTC Second */ RTC_ITConfig(RTC_IT_SEC, ENABLE); /* Wait until last write operation on RTC registers has finished */ RTC_WaitForLastTask(); } }
void RTC_init(void) { /* Enable PWR and BKP clocks */ RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR | RCC_APB1Periph_BKP, ENABLE); /* Allow access to BKP Domain in order to enable rtc registers*/ PWR_BackupAccessCmd(ENABLE);
//Reset Backup Domain,此执令会将备份域数据清零,建议初始化时屏蔽掉 BKP_DeInit();
#ifdef RTCClockSource_LSI RCC_LSICmd(ENABLE); /* Enable LSI */ while(RCC_GetFlagStatus(RCC_FLAG_LSIRDY) == RESET); /* Wait till LSI is ready */ RCC_RTCCLKConfig(RCC_RTCCLKSource_LSI); /* Select LSI as RTC Clock Source */ #elif defined RTCClockSource_LSE RCC_LSEConfig(RCC_LSE_ON); /* Enable LSE */ while(RCC_GetFlagStatus(RCC_FLAG_LSERDY) == RESET); /* Wait till LSE is ready */ RCC_RTCCLKConfig(RCC_RTCCLKSource_LSE);/* Select LSE as RTC Clock Source */ #endif
/* Enable RTC Clock */ RCC_RTCCLKCmd(ENABLE);
#ifdef RTCClockOutput_Enable /* Disable the Tamper Pin */ BKP_TamperPinCmd(DISABLE); /* To output RTCCLK/64 on Tamper pin, the tamper functionality must be disabled */ BKP_RTCCalibrationClockOutputCmd(ENABLE); /* Enable RTC Clock Output on Tamper Pin */ #endif
/* Wait for RTC registers synchronization */ RTC_WaitForSynchro(); RTC_WaitForLastTask(); /* Enable the RTC Second */ RTC_ITConfig(RTC_IT_SEC, ENABLE);
/* Set RTC prescaler: set RTC period to 1sec */ #ifdef RTCClockSource_LSI RTC_SetPrescaler(39999); /* RTC period = RTCCLK/RTC_PR = (40.000 KHz)/(39999+1) */ #elif defined RTCClockSource_LSE RTC_SetPrescaler(32767); /* RTC period = RTCCLK/RTC_PR = (32.768 KHz)/(32767+1) */ #endif /* Wait until last write operation on RTC registers has finished */ RTC_WaitForLastTask(); } ……………………………………………………………………………..
|