cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F103RET RTC issue

abbas
Associate II
Posted on July 05, 2015 at 14:30

Hello everyone

I am using STM32F103RET and I try to use RTC

The problem is, when I try to use LSE as RTC clock source, the code is trapped in

''while (RCC_GetFlagStatus(RCC_FLAG_LSERDY) == RESET)  {}; ''

loop, it seems that LSE Crystal is not working. I have changed the crystal and even I replaced the crystal with a working digital clock crystal ( I took crystal out from the board ). There is no 32768Hz oscillation at crystal pins

Also, when I try to use LSI instead, RTC runs but after reset ( when battery is connected ) it seems that LSI is getting disabled, while backup registers work correctly

Can anyone share his experience with me...

This is my Code

int main(void)

{

    ...

    RCC_Configuration(); // Clock config

    ...    

    RTC_init();

    ...

}

...

void RTC_init(void)

{

    RTC_NVIC_Configuration();

    RTC_Configuration();

}

...

void RTC_Configuration(void)

{

    RCC_APB1PeriphClockCmd( RCC_APB1Periph_PWR | RCC_APB1Periph_BKP, ENABLE );// Enable PWR and BKP clocks

    PWR_BackupAccessCmd ( ENABLE );    // Allow access to BKP Domain

    if ( BKP_ReadBackupRegister(BKP_REG_SIGN) != 0xA5A5 )

    {

        /* Reset Backup Domain */

        BKP_DeInit();

        

//         RCC_LSICmd ( ENABLE );    // ????????????????????????????????????????????????????

//         while( RCC_GetFlagStatus(RCC_FLAG_LSIRDY) == RESET ) {}; //    Wait till LSI is ready

//         RCC_RTCCLKConfig( RCC_RTCCLKSource_LSI ); // Select the RTC Clock Source

//         RTC_WaitForLastTask();    // Wait until last write operation on RTC registers has finished

        RCC_LSEConfig(RCC_LSE_ON);    // Enable LSE ?????????????????????????????????????

        while (RCC_GetFlagStatus(RCC_FLAG_LSERDY) == RESET)  {}; // Wait till LSE is ready

        RCC_RTCCLKConfig(RCC_RTCCLKSource_LSE);    // Select LSE as RTC Clock Source

        RTC_WaitForLastTask();    // Wait until last write operation on RTC registers has finished

//         RCC_RTCCLKConfig(RCC_RTCCLKSource_HSE_Div128); // assuming HSE is turned on before, in RCC_init()

        /* Enable RTC Clock */

        RCC_RTCCLKCmd(ENABLE);

        BKP_WriteBackupRegister( BKP_REG_SIGN, 0xA5A5 );

    }

    

    /* Wait for RTC registers synchronization */

    RTC_WaitForSynchro();

    /* Enable the RTC Second */

    RTC_ITConfig(RTC_IT_SEC, ENABLE);

    /* Wait until last write operation on RTC registers has finished */

    RTC_WaitForLastTask();

    ...

}

#lmgtfy #stm32f10x
3 REPLIES 3
Posted on July 05, 2015 at 14:49

This topic has be covered before on the forum. There is also an app note on crystals and supporting components. Suggest Google of ''STM32 Crystal Oscillator''

You can't just use random watch crystals. You need something in the 6-7 pF range, not the 9pF or 12pF variety. These will generally not start or oscillate properly.

Sticking scope probes on the crystal directly will alter the circuit characteristics, view indirectly through MCO pins.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
abbas
Associate II
Posted on July 06, 2015 at 06:29

Thanks Clive1 for your information,

but the same crystal works on another starter-kit of stm32f10x board ( for my friend ), and also do you have any idea for LSI problem I had?

abbas
Associate II
Posted on July 14, 2015 at 19:39

It was a technical difficulty, I replaced the micro-controller and the problem disappeared!!!

Maybe the RTC unit is corrupted while soldering or the soldering was not correct or ...

But the LSI issue still exists. In the reference manual, it is mentioned that it is not the guarantee for LSI or HSE to work correctly while master power supply is switched off

( ref. STM32F10x Reference Manual sec. 7.2.8 RTC Clock )