AnsweredAssumed Answered

STM32F103 Config & Read RTC

Question asked by ka.hak on May 31, 2012
Latest reply on Jan 31, 2015 by mahir
Hi,
RTC works but i get only 1 second counter if i set RTC->PRLL = 0x32; below the init and get function. In most example i see 0x7FFF for PRLL. Why the counter counts slow.Any prescaler i missed?
01.RCC->APB1ENR |= (RCC_APB1ENR_PWREN | RCC_APB1ENR_BKPEN);
02.PWR->CR |= PWR_CR_DBP;//access to backup register
03.RCC->BDCR |= (RCC_BDCR_RTCEN | RCC_BDCR_LSEON | RCC_BDCR_RTCSEL_LSE);
04. 
05.while((RCC->BDCR & RCC_BDCR_LSERDY) == 0) //external Low Speed oscillator Ready?
06.{
07.}
08. 
09.while ((RTC->CRL & RTC_CRL_RTOFF)== 0)   //end of write operation?
10.{
11.}
12.//enter configuration mode
13.RTC->CRL |= RTC_CRL_CNF;
14.//RTC->PRLL = 0x7FFF;  //signal period of 1sec.
15.RTC->PRLL = 0x32;  //signal period of 1sec.
16.//RTC->PRLL = 0x5;     //signal period 107 ms.
17.//RTC->PRLL = 0x1;  //signal period 26.8 ms
18.//reset 32bit counter
19.RTC->CNTH = 0x0000;
20.RTC->CNTL = 0x0000;
21.RTC->CRL &= ~(RTC_CRL_CNF); //exit configuration mode
22. 
23.while ((RTC->CRL & RTC_CRL_RTOFF)== 0)   //end of write operation?
24.{
25.}

Getting RTC Value
1.uint32_t RTC_GetCounter(void)
2.{
3.  uint16_t tmp = 0;
4.  tmp = RTC->CNTL;
5.  return (((uint32_t)RTC->CNTH << 16 ) | tmp) ;
6.}

Outcomes