/******************************************************************************* * 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 */
/* Wait until last write operation on RTC registers has finished */ RTC_WaitForLastTask(); /*根据实际环境测量来确定校正值,这里以每月300秒来校正*/ BKP_SetRTCCalibrationValue(120); /* Wait until last write operation on RTC registers has finished */ RTC_WaitForLastTask(); }
STM32技术参考手册中第8.1节:After reset, access to Backup registers and RTC is disabled and the Backup domain is protected against possible parasitic write access. The DBP bit must be set in the Power Control Register (PWR_CR) to enable access to the Backup registers and RTC.
ppm 对应月差(s) 对应年差 2 5 1 min 4 11 2 min 12s 6 16 3 min 12s 8 21 4 min 12s 10 26 5 min 12s 20 53 10 min 36s 30 78 1 min 18s 15 min 36s 40 102 1 min 42s 20 min 24s 50 129 2 min 09s 25 min 48s 100 259 4 min 19s 51 min 48s 150 388 6 min 28s 1h 17min 36s