Question
STM32F103 Config & Read RTC
Posted on May 31, 2012 at 15:22
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?
RCC->APB1ENR |= (RCC_APB1ENR_PWREN | RCC_APB1ENR_BKPEN);
PWR->CR |= PWR_CR_DBP;
//access to backup register
RCC->BDCR |= (RCC_BDCR_RTCEN | RCC_BDCR_LSEON | RCC_BDCR_RTCSEL_LSE);
while
((RCC->BDCR & RCC_BDCR_LSERDY) == 0)
//external Low Speed oscillator Ready?
{
}
while
((RTC->CRL & RTC_CRL_RTOFF)== 0)
//end of write operation?
{
}
//enter configuration mode
RTC->CRL |= RTC_CRL_CNF;
//RTC->PRLL = 0x7FFF; //signal period of 1sec.
RTC->PRLL = 0x32;
//signal period of 1sec.
//RTC->PRLL = 0x5; //signal period 107 ms.
//RTC->PRLL = 0x1; //signal period 8 ms
//reset 32bit counter
RTC->CNTH = 0x0000;
RTC->CNTL = 0x0000;
RTC->CRL &= ~(RTC_CRL_CNF);
//exit configuration mode
while
((RTC->CRL & RTC_CRL_RTOFF)== 0)
//end of write operation?
{
}
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.
}