cancel
Showing results for 
Search instead for 
Did you mean: 

RTC & stm32F746

Franzi.Edo
Senior
Posted on March 19, 2017 at 18:08

Hi,

I have a strange behaviour with the stm32F746 RTC.

I use a 32768-Hz crystal (I have verified with the scope that it is running).

I initialise as indicated in the following code, but the time register is incremented approximatively every 1500s instead of every 1s. The same code works perfectly with a stm32F429 (same board and same crystal).

Can someone give me an advice ?

Thank you

  Edo

static void aProcess_0(void) {

   uint32_t time, date, cpt =0;

   

   RCC->APB1ENR |= RCC_APB1ENR_PWREN; // Turn on the PWREN

// Make possible the access to the RTC & RTC backup register.

// Add 1ms delay (for tests).

// After the restart, the RTC is in the protected mode

// Select the 32768-Hz clock & enable the RTC

   PWR->CR1 |= PWR_CR_DBP;

   kern_suspendProcess(1);

   RCC->BDCR = 0;

   RCC->BDCR = (RCC_BDCR_RTCSEL_0

| RCC_BDCR_RTCEN

| RCC_BDCR_LSEON);

   while (!(RCC->BDCR & RCC_BDCR_LSERDY));

// Remove the write protection

// Enter in the initialization mode

   RTC->WPR = 0xCA;

   RTC->WPR = 0x53;

// Waiting for ready to write

// Set the new counter values

   RTC->ISR |= RTC_ISR_INIT;

   while (!(RTC->ISR & RTC_ISR_INITF));

   RTC->TR = (K24H<<22)

            | ((KHOURS/16)<<20)

            | ((KHOURS&0xF)<<16)

            | ((KMINUTES/16)<<12)

            | ((KMINUTES&0xF)<<8)

            | ((KSECONDS/16)<<4)

            | ((KSECONDS&0xF)<<0);

   RTC->DR = ((KYEARS/16)<<20)

            | ((KYEARS&0xF)<<16)

            | (KasciiWeek<<13)

            | ((KMONTHS/16)<<12)

            | ((KMONTHS&0xF)<<8)

            | ((KDAYS/16)<<4)

            | ((KDAYS&0xF)<<0);

// Exit from the initialization mode

// Set the write protection

   RTC->ISR &= ~RTC_ISR_INIT;

   RTC->WPR = 0xFF;

   while (TRUE) {

      kern_suspendProcess(1000);

      time = RTC->TR;

      date = RTC->DR;

      printf('RTC_DR %X RTC_TR = %X %d\n', date, time, cpt++);

   }

}

1 ACCEPTED SOLUTION

Accepted Solutions
Posted on March 22, 2017 at 23:13

Hi Jan,

Thank you for you suggestion. The RTC_PRER is corrected initialised (

RTC->PRER =

0x007F00FF

;).

I have just found the problem. With a 100x scope probe (a very low capacitance one) I could measure the amplitude of the sinus on the crystal; only few mV! Of course, this is too small to maintain the oscillation. In the RCC->BDCR configuration I added the

red

modification:

RCC->BDCR = RCC_BDCR_RTCEN

         | RCC_BDCR_LSEDRV_0

         | RCC_BDCR_LSEDRV_1

         | RCC_BDCR_LSEON

         | RCC_BDCR_RTCSEL_0;

while (!(RCC->BDCR & RCC_BDCR_LSERDY));

Now, the amplitude of the sinus is correct (> 200-mV) and everything work perfectly.

It is not completely clear the real effect of these bits; the documentation is quite poor in this respect.

Thank you for the support,

Regards,

  Edo

View solution in original post

2 REPLIES 2
Posted on March 21, 2017 at 00:46

What's the content of RTC_PRER?

You may want to perform a backup-domain reset by toggling  RCC_BDCR.BDRST before enabling LSE/RTC and setting it up.

JW

Posted on March 22, 2017 at 23:13

Hi Jan,

Thank you for you suggestion. The RTC_PRER is corrected initialised (

RTC->PRER =

0x007F00FF

;).

I have just found the problem. With a 100x scope probe (a very low capacitance one) I could measure the amplitude of the sinus on the crystal; only few mV! Of course, this is too small to maintain the oscillation. In the RCC->BDCR configuration I added the

red

modification:

RCC->BDCR = RCC_BDCR_RTCEN

         | RCC_BDCR_LSEDRV_0

         | RCC_BDCR_LSEDRV_1

         | RCC_BDCR_LSEON

         | RCC_BDCR_RTCSEL_0;

while (!(RCC->BDCR & RCC_BDCR_LSERDY));

Now, the amplitude of the sinus is correct (> 200-mV) and everything work perfectly.

It is not completely clear the real effect of these bits; the documentation is quite poor in this respect.

Thank you for the support,

Regards,

  Edo