AnsweredAssumed Answered

RTC & stm32F746

Question asked by franzi.edo on Mar 19, 2017
Latest reply on Mar 22, 2017 by franzi.edo

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++);
   }
}

Outcomes