cancel
Showing results for 
Search instead for 
Did you mean: 

LSE not starting when used for RTC

ashley
Associate II
Posted on July 05, 2013 at 13:21

I am trying to use a 768kHz Xtal with 7pF load capacitors with an STM32F050C6. The problem I am having is that I cannot get the XTAL to reliably start up. I have seen it start a few times but most of the time it will not start.

I have attempted to use the same code with the recommended XTAL and caps on the STM32F0 Discovery board and I have the same problem. Has anyone got the LSE working with the RTC and if so would you be so kind to point out any issues with my code. The code gets stuck on line 24 until the timeout forces it to stop. Without the timeout the code gets stuck in the loop indefinitely.


int
main (
void
)

{

uint32_t count=0x200000;


RTC_TimeTypeDef RTC_TimeStructure;

RTC_DateTypeDef RTC_DateStructure;

RTC_InitTypeDef RTC_InitStructure;


// Turn on PWR clock

RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE);


// Allow access to RTC 

PWR_BackupAccessCmd(ENABLE);


//Forces reset of RTC

RCC_BackupResetCmd(ENABLE);

RCC_BackupResetCmd(DISABLE);


//PWR_DeInit();


// Enable the LSE OSC 

//768 External Osc

RCC_LSEConfig(RCC_LSE_ON);

//RCC_LSEDriveConfig(RCC_LSEDrive_High);


//Check for clock stability

while
( (RCC_GetFlagStatus(RCC_FLAG_LSERDY) == RESET) )

if
(--count==0)

{

return
-1;

}


// Select the RTC Clock Source

RCC_RTCCLKConfig(RCC_RTCCLKSource_LSE);


// Enable the RTC Clock 

RCC_RTCCLKCmd(ENABLE);


// Wait for RTC APB registers synchronisation 

if
( RTC_WaitForSynchro() == ERROR )

return
-2;


RTC_InitStructure.RTC_HourFormat = RTC_HourFormat_24;

//768kHz Clock is divided by (0x40 * 0x200) which 

//gives a 1Hz output from 768kHz crystal

RTC_InitStructure.RTC_AsynchPrediv = 0x40; 
//Max 0x7F

RTC_InitStructure.RTC_SynchPrediv = 0x0200; 
//Max 0x1FFF


if
( RTC_Init(&RTC_InitStructure) == ERROR )

return
-3;


while
(1)

{

RTC_TimeStructInit(&RTC_TimeStructure);

RTC_DateStructInit(&RTC_DateStructure);


RTC_GetTime(RTC_Format_BIN, &RTC_TimeStructure);

RTC_GetDate(RTC_Format_BIN, &RTC_DateStructure);

}

}

#lse #rtc
5 REPLIES 5
Posted on July 05, 2013 at 14:45

The LSE can have a significant start up time from a cold start. This can be up to 2 seconds, and your timeout count doesn't seem to be sufficient for that.

It's also very fussy about components (crystal 6pf or less) and signal lengths. The STM32L-Discovery has parts placed for the LSE, you could pull those off and place them on the test boards.
Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..
ashley
Associate II
Posted on July 05, 2013 at 15:03

You're right, I have increased the timeout but even if I remove the timeout completely the code still gets stuck in the while loop for ever. 

I don't have the STM32L-Discovery but I have soldered the recommended parts to the STM32F0Discovery and the code does not work there either which makes me think that there is an issue with the software. 

I could buy an STML-Discovery and try that but the device is based on the STM32F1 and this uses a slightly different RTC architecture from what I've read.I'm not sure if this will help me solve the problem. 

Posted on July 05, 2013 at 15:43

Make sure you remove solder bridges (SB20,21) on PC14/15 to the outer pins.

C15,C16 are 6.8pF

R24,25 are zero-ohm/short

X3 is 32.768 KHz, 6pF

http://www.digikey.com/product-detail/en/MC-306%2032.768K-E3:ROHS/SER2417TR-ND/1022179

I doubt it's software, problems with the LSE are almost universally with components (physically/electrically).

I suggested the STM32L-Discovery as it would provide known working components, which you could test first.
Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..
ashley
Associate II
Posted on July 05, 2013 at 15:54

I will order some new crystals and the STM32L now and see if that helps. Thanks for your advice.

Posted on July 05, 2013 at 18:50

No guarantee, no explanation, by why not try :   while ( (RCC_GetFlagStatus(RCC_FLAG_LSERDY) == RESET) ) {

RCC_LSEConfig(RCC_LSE_ON);  }

JW