cancel
Showing results for 
Search instead for 
Did you mean: 

Need help initializing RTC on STM32F407

jimmieh85
Associate
Posted on July 18, 2012 at 22:11

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?

42 REPLIES 42
cdb1702
Associate II
Posted on September 30, 2015 at 15:11

At present time it is not possible to download because probably the CPU is broken

With power on  it  heats up

Posted on September 30, 2015 at 16:28

Related to the code you downloaded, or something else you were doing to the board?

Do you have a schematic for what you've built? You can redact anything that's sensitive, but let's start with the STM32 and all the components and supplies connected to it.

Do you have any high loading on PC13?

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

Hi Carlo,

Try calling RCC_RTCCLKCmd(ENABLE) then RTC_WaitForSynchro() before calling RTC_Init().

It works for me.

Renaud