cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F103 RTC Register problem

Michael2023
Associate II

Hi. I have a problem with the RTC on STM32F103C6T6A. I wanted to add the ability to set the time. I would like to have a 24h clock. When CNTL overflows, CNTH does not increase making the clock reset close to 18h.

 

void RTC_IRQHandler(void){
 
while ((RTC->CRL, RTC_CRL_RTOFF) == 0 );
 
RTC -> CRL &= ~RTC_CRL_SECF;
 
licznik = RTC -> CNTH;
licznik <<= 16;
licznik = RTC -> CNTL;
godziny = licznik / 3600;
minuty = (licznik % 3600)/60;
sekundy = (licznik % 3600) % 60;}
 
void RTC_Config(void){
RCC -> APB1ENR |= RCC_APB1ENR_PWREN; //Power interface clock enable (aby kozystac z rejestru PWR)
RCC -> APB1ENR |= RCC_APB1ENR_BKPEN; //Backup interface clock enable (aby kozystac z rejestru BKP)
PWR -> CR |= PWR_CR_DBP; //Enable Acces to RTC registers (Disable backup domain write protection)
// RCC -> CSR |= RCC_CSR_LSION; //LSI 40kHz ON
// while(!(RCC -> CSR & RCC_CSR_LSIRDY)); //Wait for LSI Ready
RCC -> BDCR |= RCC_BDCR_LSEON; //LSE ON
while(!(RCC -> BDCR & RCC_BDCR_LSERDY)); //Wait for LSE Ready
// RCC -> BDCR |= RCC_BDCR_RTCSEL_1; //LSI source for RTC
RCC -> BDCR |= RCC_BDCR_RTCSEL_0; //LSE source for RTC
RCC -> BDCR |= RCC_BDCR_RTCEN; //RTC clock ENABLE
 
while(!(RTC->CRL & RTC_CRL_RSF)); //Registers synchronized flag
while(!(RTC->CRL & RTC_CRL_RTOFF)); //RTC status operation OFF
 
RTC -> CRL |= RTC_CRL_CNF; //Enter Configuration mode
RTC -> PRLL = 39999; //RTC prescaler
RTC -> CRH |= RTC_CRH_SECIE; //Global Interrupt form RTC ENABLE
while(!(RTC->CRL & RTC_CRL_RTOFF)); //RTC status operation OFF
RTC -> CRL &=~ RTC_CRL_CNF; //Exit Configuration mode
while(!(RTC->CRL & RTC_CRL_RTOFF)); //RTC status operation OFF
}
5 REPLIES 5
JTP1
Lead

Hello

Put or | like this

licznik = RTC -> CNTH;
licznik <<= 16;
licznik| = RTC -> CNTL;
 
And make sure licznik is 32 bit
 
Br.J.T

Hi. Still nothing. 
when I exceed the value of 18h (CNTL overflow) RTC resets leaving "garbage" as minutes. (18h->RESET->0:48h).

CNTH still 0.

the main problem is CNT registers. When CNTL is overload CNTH isn't increment automatic.

 

Do you use some of the low-power modes?

> while ((RTC->CRL, RTC_CRL_RTOFF) == 0 );

Did you want to use the comma expression here?

JW

The only thing I use is a Vbat power supply to back up the RTC when it shuts down