2012-05-31 06:22 AM
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.
}
2012-05-31 09:16 AM
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
2015-01-31 07:51 AM
hi
clive
1
mcu stm32f103 How doeseach
1Hz
also
led
on off ?
if( ????? ==0) { led = 1;}
else{
led
= 0; } thanksI 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
2015-01-31 08:56 AM
Sorry, I really don't understand the question here.
2015-01-31 09:41 AM
I want to watch using the LSE oscillator.
How to use the sec data? for example: if (secdata == 0) { sec ++; } thanks.2015-01-31 11:07 AM
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;2015-01-31 01:46 PM
thanks.