Question
The best sequency to initialize RCT in STM32f37x
Posted on March 10, 2016 at 13:30
I've tried to access the document in the , but the result is 404 server error.
What I'm trying to do is initialize a RCT clocked from HSE 12 MHz quarz. It's initializing after I restart it from the debugger several times, otherwise it's unable to initialize. Absolute mystery... Here is the code:void RTC_Config(struct tm* ptm) { RTC_InitTypeDef RTC_InitStructure; RTC_TimeTypeDef RTC_TimeStruct; RTC_DateTypeDef RTC_DateStruct; /* Enable the PWR clock */ RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE); /* Allow access to RTC */ PWR_BackupAccessCmd(ENABLE); /* For HSE no need of clock domain reset!!! */ // RCC_BackupResetCmd(ENABLE); // RCC_BackupResetCmd(DISABLE); /* Select the RTC Clock Source */ // RCC_HSEConfig(RCC_HSE_ON); RCC_RTCCLKConfig(RCC_RTCCLKSource_HSE_Div32); /* Configure the RTC data register and RTC prescaler */ RTC_InitStructure.RTC_AsynchPrediv = 0x7C; RTC_InitStructure.RTC_SynchPrediv = 0xBB7; RTC_InitStructure.RTC_HourFormat = RTC_HourFormat_24; while(RTC_Init(&RTC_InitStructure)!=SUCCESS) { /* Enable the RTC Clock */ RCC_BackupResetCmd(ENABLE); RCC_BackupResetCmd(DISABLE); RCC_RTCCLKCmd(ENABLE); RTC_Init(&RTC_InitStructure); RCC_RTCCLKCmd(DISABLE); } /* Set the time to 00h 00mn 00s AM */ RTC_TimeStruct.RTC_H12 = RTC_H12_AM; RTC_TimeStruct.RTC_Hours = ptm->tm_hour; RTC_TimeStruct.RTC_Minutes = ptm->tm_min; RTC_TimeStruct.RTC_Seconds = ptm->tm_sec; RTC_SetTime(RTC_Format_BIN, &RTC_TimeStruct); RTC_DateStruct.RTC_Year = ptm->tm_year; RTC_DateStruct.RTC_Month = ptm->tm_mon; RTC_DateStruct.RTC_Date = ptm->tm_mday; RTC_DateStruct.RTC_WeekDay = ptm->tm_wday; RTC_SetDate(RTC_Format_BIN, &RTC_DateStruct); /* Wait for RTC APB registers synchronisation */ RCC_RTCCLKCmd(ENABLE); RTC_WaitForSynchro(); RTC_AlarmConfig(); }