cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F103 Config & Read RTC

primagen23
Associate II
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.
}

6 REPLIES 6
Posted on May 31, 2012 at 18:16

I can't say I like the way you sequenced that. You should check the oscillator with a scope if it still looks to be running slowly. If you program at a register level, expect to spend hours of time debugging it.

I might do something like this:

RCC->APB1ENR |= (RCC_APB1ENR_PWREN | RCC_APB1ENR_BKPEN);
PWR->CR |= PWR_CR_DBP; // access to backup register
RCC->BDCR |= RCC_BDCR_LSEON; // Enable
while((RCC->BDCR & RCC_BDCR_LSERDY) == 0); //external Low Speed oscillator Ready?
RCC->BDCR |= RCC_BDCR_RTCSEL_LSE; // Select Source
RCC->BDCR |= RCC_BDCR_RTCEN; // Enable
RTC->CRL &= ~RTC_FLAG_RSF; // Clear RSF
while((RTC->CRL & RTC_FLAG_RSF) == 0); // wait for sync
RTC->CRL |= RTC_CRL_CNF; //enter configuration mode
RTC->PRLH = 0x0000;
RTC->PRLL = 0x7FFF; //signal period of 1sec.
RTC->CNTH = 0x0000; //reset 32bit counter
RTC->CNTL = 0x0000;
RTC->CRL &= ~RTC_CRL_CNF; //exit configuration mode
while((RTC->CRL & RTC_FLAG_RTOFF) == 0) // wait for last task

Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..
kemal
Associate II
Posted on January 31, 2015 at 16:51

hi

clive

1

mcu stm32f103 How does

each

1Hz

also

led

on off ?

if( ????? ==0) { led = 1;

}

else

{

led

= 0; } thanks

I might do something like this:
RCC->APB1ENR |= (RCC_APB1ENR_PWREN | RCC_APB1ENR_BKPEN);
PWR->CR |= PWR_CR_DBP; // access to backup register
RCC->BDCR |= RCC_BDCR_LSEON; // Enable
while((RCC->BDCR & RCC_BDCR_LSERDY) == 0); //external Low Speed oscillator Ready?
RCC->BDCR |= RCC_BDCR_RTCSEL_LSE; // Select Source
RCC->BDCR |= RCC_BDCR_RTCEN; // Enable
RTC->CRL &= ~RTC_FLAG_RSF; // Clear RSF
while((RTC->CRL & RTC_FLAG_RSF) == 0); // wait for sync
RTC->CRL |= RTC_CRL_CNF; //enter configuration mode
RTC->PRLH = 0x0000;
RTC->PRLL = 0x7FFF; //signal period of 1sec.
RTC->CNTH = 0x0000; //reset 32bit counter
RTC->CNTL = 0x0000;
RTC->CRL &= ~RTC_CRL_CNF; //exit configuration mode
while((RTC->CRL & RTC_FLAG_RTOFF) == 0) // wait for last task

Posted on January 31, 2015 at 17:56

Sorry, I really don't understand the question here.

Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..
kemal
Associate II
Posted on January 31, 2015 at 18:41

I want to watch using the LSE oscillator.

How to use the sec data?

     

for example:

  if (secdata == 0)

            {

 

sec ++;

         

          }

thanks.
Posted on January 31, 2015 at 20:07

Ok, still not really getting this, but..

As nominally configured the F1 RTC will tick on a 1 second (1 Hz) period. You can a) use the RTC to generate a 1 Hz interrupt and count those, or b) read the 32-bit tick clock and modulus it, ie secs = RTC_GetCounter() % 60;

Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..
kemal
Associate II
Posted on January 31, 2015 at 22:46

thanks.