Question
RTC with HSE and STMF0
Posted on July 10, 2014 at 15:27
I am trying to make a clock LCD display on my STM32F0. I want to use the external 8MHz crystal that is on my board. I cannot use any of the example code as none of it gives examples using the HSE. The code that I am using is below. However the code hangs in the while loop.
What am I doing wrong? //(1) Write access for RTC registers //(2) Enable init phase //(3) Wait until it is allow to modify RTC register values //(4) set prescaler, 48/32 kHz/128 => 312 Hz, 312Hz/312 => 1Hz //(5) New time in TR //(6) Disable init phase //(7) Disable write access for RTC registers RTC->WPR = 0xCA; //(1) RTC->WPR = 0x53; //(1) RCC->BDCR |= RCC_BDCR_RTCEN; RTC->ISR |= RTC_ISR_INIT; //(2) //while ((RTC->ISR & RTC_ISR_INITF) != RTC_ISR_INITF) //(3) //{ //add time out here for a robust application //} RCC->BDCR = RCC_BDCR_RTCSEL_HSE; //RCC_RTCCLKConfig(RCC_RTCCLKSource_HSE_Div32); //RTC_InitStructure.RTC_AsynchPrediv = 125 - 1; //=0x7C //RTC_InitStructure.RTC_SynchPrediv = 2000 - 1; // 0x7CF RTC->PRER = 0x007C7CF; //(4) RTC->TR = RTC_TR_PM | 0x00000001; //(5) RTC->ISR &=~ RTC_ISR_INIT; //(6) RTC->WPR = 0xFE; //(7) RTC->WPR = 0x64; //(7)} #stm32f0 #stm32f10x-rtc