AnsweredAssumed Answered

STM32F103RET RTC issue

Question asked by keshavarz.abbas on Jul 5, 2015
Latest reply on Jul 14, 2015 by keshavarz.abbas
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();

    ...
}



Outcomes