cancel
Showing results for 
Search instead for 
Did you mean: 

RTC stm32f103

Michael2023
Associate II

Hi. I need help with RTC on STM32F103. 

I would like to edit the time (hours and minutes) in my RTC using a button. When I add an hour the maximum vartosc I can reach in the RTC->CNTL register is 65535 (18h20min), when this value is exceeded, the register zeroes some bits (it gets 0:48), while the RTC->CNTH register does not increment.

When I leave the clock without editing the time, no matter whether with the main power supply on or without (battery), the RTC works fine and counts correctly (the error with the CNTH and CNTL registers does not occur).


Please help, I've been sitting on this for a while and can't get past this problem.

 

void RTC_Edit_Time(void){
if(GPIOA -> IDR & SW2){
licznik_100ms_2++;
if(licznik_100ms_2 ==10){
licznik_100ms_2 = 0;
while ((RTC->CRL, RTC_CRL_RTOFF) == 0 );
RTC -> CRL |= RTC_CRL_CNF; //Enter Configuration mode
RTC -> CRH &=~ RTC_CRH_SECIE; //Global Interrupt form RTC DISABLE
 
 
licznik = licznik + 3600;
 
licznik_1 = licznik>>16;
if(licznik > 65535){
RTC->CNTH |= RTC->CNTH +1;
licznik_1 = licznik_1 - 64800;
RTC->CNTL = licznik_1;
}
else{
RTC -> CNTL = licznik;
}
 
while(!(RTC->CRL & RTC_CRL_RSF)); //Registers synchronized flag
RTC -> CRH |= RTC_CRH_SECIE; //Global Interrupt form RTC ENABLE
while(!(RTC->CRL & RTC_CRL_RSF)); //Registers synchronized flag
RTC -> CRL &=~ RTC_CRL_CNF; //Exit Configuration mode
while(!(RTC->CRL & RTC_CRL_RTOFF)); //RTC status operation OFF
 
 
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_obl_1 = licznik / 3600;
godziny = godziny_obl_1%24;
minuty = (licznik % 3600)/60;
sekundy = (licznik % 3600) % 60;
}
1 REPLY 1
Jacob WOODRUFF
ST Employee

Hi All,

 

This question was routed to our online support center for direct support. 


Regards,
Jake

ST Support