AnsweredAssumed Answered

STM32F050 RTC with HSE not starting

Question asked by shallcross.harris on Jun 3, 2014
Hi,

I'm trying to get the RTC working on an STM32F050 processor with an 8MHz external crystal connected. The crystal correctly starts up and allows the rest of the mcu to work. I'm using Coocox on an external board and a debugging LCD connected. 

My code is:
RCC_HSEConfig(RCC_HSE_ON);
RCC_WaitForHSEStartUp();
RCC_SYSCLKConfig(RCC_SYSCLKSource_HSE);
 
RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1, ENABLE);
 
PWR_BackupAccessCmd(ENABLE);
 
//RCC_LSICmd(ENABLE);
//while(RCC_GetFlagStatus(RCC_FLAG_LSIRDY) == RESET);
RCC_RTCCLKConfig(RCC_RTCCLKSource_HSE_Div32);
RCC_RTCCLKCmd(ENABLE);
RTC_WriteProtectionCmd(DISABLE);
 
if(RTC_WaitForSynchro() == ERROR){
    PStr("Synchro", 0, 0, 0, PixNorm);
    PScrn();
    while(1);
}
 
RI.RTC_AsynchPrediv = 100-1;
RI.RTC_HourFormat = RTC_HourFormat_24;
RI.RTC_SynchPrediv = 2500-1;
RTC_Init(&RI);
 
RT.RTC_Hours = 14;
RT.RTC_Minutes = 50;
RTC_SetTime(RTC_Format_BIN, &RT);

It works fine if I set the clock for LSI and I can see the RTC counting upwards when I display the time to my debugging LCD. It calls an error on Synchro however if I change the clock to HSE. Why is this happening?

Thanks,

Outcomes