如果集成内部温度传感器,我们可以通过测温来自动改写校正值。还有我写了个校正程序,基本上不起什么作用,以下是配置源码,不知道那里有误 /******************************************************************************* * Function Name : RTC_Configuration * Description : Configures the RTC. * Input : None * Output : None * Return : None *******************************************************************************/ 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);
/* Reset Backup Domain */ BKP_DeInit();
/* 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);
/*正式运行时这里没必要输出*/ #ifdef RTCClockOutput_Enable /* Disable the Tamper Pin */ BKP_TamperPinCmd(DISABLE); /* To output RTCCLK/64 on Tamper pin, the tamper functionality must be disabled */ /* Enable RTC Clock Output on Tamper Pin */ BKP_RTCCalibrationClockOutputCmd(ENABLE); #endif
/* Wait for RTC registers synchronization */ RTC_WaitForSynchro();
/* Wait until last write operation on RTC registers has finished */ 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) */ /*这里设置成32765即预分频值为32766为了时钟校正的需要*/ RTC_SetPrescaler(32765); /* RTC period = RTCCLK/RTC_PR = (32.768 KHz)/(32767+1) */ /* Wait until last write operation on RTC registers has finished */ RTC_WaitForLastTask(); /*根据实际环境测量来确定校正值,这里以每月297秒来校正*/ BKP_SetRTCCalibrationValue(120); /* Wait until last write operation on RTC registers has finished */ RTC_WaitForLastTask(); }
|