CH32V203C8T6 RTC例程每次重新上电时间都会被重置,请问怎么操作才能避免?
热门产品 :
CH585: 集成高速USB和NFC的蓝牙MCU
CH32V203C8T6 RTC例程每次重新上电时间都会被重置,请问怎么操作才能避免?
你好,后备寄存器是Vbat供电的,数据可以保持,可以判断标志位确定,VDD掉电后,要确保Vbat由电池供电。
u8?RTC_Init(void) { ????u8?temp?=?0; ????RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR?|?RCC_APB1Periph_BKP,?ENABLE); ????PWR_BackupAccessCmd(ENABLE); ????/*?Is?it?the?first?configuration?*/ ????if(BKP_ReadBackupRegister(BKP_DR1)?!=?0XA1A1){ ????BKP_DeInit(); ????RCC_LSEConfig(RCC_LSE_ON); ????while(RCC_GetFlagStatus(RCC_FLAG_LSERDY)?==?RESET?&&?temp?<?250) ????{ ????????????temp++; ????????????Delay_Ms(20); ????} ????if(temp?>=?250) ????return?1; ????RCC_RTCCLKConfig(RCC_RTCCLKSource_LSE); ????RCC_RTCCLKCmd(ENABLE); ????RTC_WaitForLastTask(); ????RTC_WaitForSynchro(); ????// RTC_ITConfig(RTC_IT_ALR,?ENABLE); ????RTC_ITConfig(RTC_IT_SEC,?ENABLE); ????RTC_WaitForLastTask(); ????RTC_EnterConfigMode(); ????RTC_SetPrescaler(32767); ????RTC_WaitForLastTask(); ????RTC_Set(2019,?10,?8,?13,?58,?55);?/*?Setup?Time?*/ ????RTC_ExitConfigMode(); ????BKP_WriteBackupRegister(BKP_DR1,?0XA1A1); ????RTC_NVIC_Config(); ????RTC_Get();} ????else{ ????????????RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR?|?RCC_APB1Periph_BKP,?ENABLE); ????????????PWR_WakeUpPinCmd(DISABLE); ????????????RTC_WaitForSynchro(); ????????????//?RTC_ITConfig(RTC_IT_ALR,?ENABLE); ????????????RTC_ITConfig(RTC_IT_SEC,?ENABLE); ????????????RTC_WaitForLastTask(); ????????} ????????//?nvic ????????????RTC_NVIC_Config(); ????????return?0; ????return?0; }