AnsweredAssumed Answered

Need help initializing RTC on STM32F407

Question asked by hansson.jimmie.001 on Jul 18, 2012
Latest reply on Oct 6, 2015 by renaud.renaud
Hi I am trying to write date and time to the RTC which I later will read.

But something in my RTC configuration doesn’t work and reading the values in debug mode shows that the RTC registers that I try to set never get the new values.
Here is my code:

void Set_RTC()
{


/* Enable the PWR clock */
RCC_APB1ENR.PWREN = 1;


/* Allow access to RTC */
PWR_CR.DBP = 1;


/* LSE used as RTC source clock */
RCC_BDCR.LSEON = 1;    //External low-speed oscillator enable


 /* Wait till LSE is ready */
while(RCC_BDCR.LSERDY != 1)
{
}


/* Select the RTC Clock Source to LSE */
RCC_BDCR.F8 = 1;
RCC_BDCR.F9 = 0;


/* Wait for RTC APB registers synchronisation */
while(RTC_ISR.RSF != 1)
{
}


RCC_BDCR.RTCEN = 1;   //Enable RTC clock  <<<


RTC_WPR = 0xCA;   //unlock write protection
RTC_WPR = 0x53;   //unlock write protection




/* Configure the RTC prescaler */
RTC_PRER = 0x7f00ff;  //  set   SynchPrediv to FF and AsynchPrediv to 7F


//RCC_BDCR.RTCEN = 1;   //Enable RTC clock  <<<








RTC_ISR.INIT = 1;     //enter initialization mode <<<<<< THIS REGISTER NEVER GETS THE NEW VALUE


while(RTC_ISR.INITF != 1)   //poll INITF
{


}
/* Configure the RTC PRER */
 RTC_PRER = 0x7F;
 RTC_PRER |= 0xFF << 16;


 RTC_TR = 0x123500; //setting time to 12.35.00
 RTC_DR = 0x126718;  // set date to  2012-07-18
 RTC_CR.F6 = 0; // set FMT 24H format


 RTC_ISR.INIT = 0;     //exit initialization mode


  /* Enable the write protection for RTC registers */
  RTC_WPR = 0xFF;
}

I am using a STM32F407 @ 140Mz internal HSI oscillator.

What am I doing wrong?

Outcomes