void rtc_init(void) {
RCC->APB1ENR|=1<<28; //POWER interface clock enable PWR->CR|=1<<8; //Access RTC and Backup registers enabled RCC->APB1ENR|=1<<27; //Backp interface clock enabled RCC->BDCR|=1<<16; //RESET the entire Backup domain //BKP->RTCCR|=1<<7; //RCC->APB2ENR|=1<<4; //GPIOC->CRH&=0X00FFFFFF; //GPIOC->CRH|=0xb4000000; //RCC->BDCR&=~(1<<2); //RCC->BDCR|=1<<0; //LSEON //while((RCC->BDCR&0x00000002)==0); //wait LSE ready //RCC->CSR|=1<<0; //while((RCC->CSR&(1<<1))==0); //LSI used as RTC clock RCC->BDCR|=3<<8; //select LSE used as RTC clock RCC->BDCR|=1<<15; //RTC clock enable //配置RTC //RTC->CRL&=~(1<<3); while((RTC->CRL&(1<<5))==0); RTC->CRL|=1<<4; // ENTER configuration mode //RTC->CRH=0; // NO interrupt //RTC->PRLH=0; RTC->PRLL=0X7FFF; //RTC->PRL=0X00007FFF,即TR_CLK=1Hz //RTC->CNTH=0; //RTC->CNTL=0; RTC->CRL&=~(1<<4); //Exit configuration mode while((RTC->CRL&(1<<5))==0); }
不能成功,望大侠们指正 |