void InitPeriph(void) { CRC_Configure(); TIM_Configure(); GPIO_Configure(); USART_Configure(); ADC_Configure(); RTC_Configure(); RTC_Time_Configure(0, 0, 0); RTC_Alarm_Configure(0xFF, 20, 0); //Alarm each 20 min (Check humidity) dxdev_out(USART_SendChar); SPI_Configure(); }
// 初始化RTC时钟。 void rtc_init(void) { systick = 0; // 检查备份寄存器中的RTC校准标志是否被设置,若未被设置,则校准RTC if(BKP_ReadBackupRegister(BKP_DR1) != 0xA5A5) { /* Backup data register value is not correct or not yet programmed (when the first time the program is executed) */ /* RTC Configuration */ RTC_Configure(); /* Adjust time by values entred by the user on the hyperterminal */ // Time_Adjust(); // 校准RTC后在备份寄存器中写入校准标志 BKP_WriteBackupRegister(BKP_DR1, 0xA5A5); } else // 若RTC已经被校准(备份寄存器在MCU关机但不断电情况下可保持内容),则无需再校准 { //启用PWR和BKP的时钟(from APB1) RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR | RCC_APB1Periph_BKP, ENABLE); //后备域解锁,以为内RTC处于后备域,操作其相关寄存器时需要先解锁 PWR_BackupAccessCmd(ENABLE); #ifdef RTCClockSource_LSI /* Enable LSI */ RCC_LSICmd(ENABLE); /* Wait till LSI is ready */ while(RCC_GetFlagStatus(RCC_FLAG_LSIRDY) == RESET) { } /* Select LSI as RTC Clock Source */ RCC_RTCCLKConfig(RCC_RTCCLKSource_LSI); #endif RCC_RTCCLKCmd(ENABLE); //========================================================== /* Check if the Power On Reset flag is set */ #if 0 if(RCC_GetFlagStatus(RCC_FLAG_PORRST) != RESET) { //printf("\r\n\n Power On Reset occurred...."); } /* Check if the Pin Reset flag is set */ else if(RCC_GetFlagStatus(RCC_FLAG_PINRST) != RESET) { //printf("\r\n\n External Reset occurred...."); } #endif //printf("\r\n No need to configure RTC...."); /* Wait for RTC registers synchronization */ RTC_WaitForSynchro(); /*允许RTC报警中断*/ RTC_ITConfig(RTC_IT_ALR, ENABLE); /* Wait until last write operation on RTC registers has finished */ RTC_WaitForLastTask(); } /* Clear reset flags */ RCC_ClearFlag(); /*等待最后一条写指令完成*/ RTC_WaitForLastTask(); /* Display time in infinte loop */ //Time_Show(); RTC_SetAlarm(systick+SYSTICK_PERIOD); }