Skip to main content
Visitor II
July 17, 2021
Question

RTC for STM8L Discovery: Why the second runs correctly, but the minute does not run?

  • July 17, 2021
  • 1 reply
  • 837 views

The following is the main.c

It's a simple demo for RTC display on LCD. The second run correctly, which means the system and RTC clock set correctly. However, the minute does not change when the second runs a circle (60s). Do I set the registers incorrectly and forget set sth?

void main(void)

{

 u8 H_shi=0,H_ge=0,M_shi=0,M_ge=0,S_shi=0,S_ge=0;

  

  

 system_init();

  

 GPIO_Init();

 LCD_Config();

 RTC_Config();

  

  

 LCD_GLASS_Clear();

 LCD_GLASS_Confirm();

 Delay(50);

 LCD_GLASS_Clear();

 LCD_GLASS_Confirm();

 Delay(50);

 LCD_GLASS_Clear();

 LCD_DisplayNum(4,1);

 LCD_DisplayNum(3,5);

 LCD_DisplayNum(2,6);

 LCD_DisplayNum(1,8);

 Delay(50);

 LED2 = 0;

 LED3 = 1;

 MOTOR1 = 1;

 MOTOR2 = 0;

  

 LCD_GLASS_Clear();

  

 //asm("rim");

 while(1)

 {

  LED3 = 1;

  while(!RTC_ISR1_RSF);

   

   

  S_ge = (u32)RTC_TR1_SU;

  S_shi = (u32)RTC_TR1_ST;

  M_ge = (u32)RTC_TR2_MNU;

  M_shi = (u32)RTC_TR2_MNT;

  H_ge = (u32)RTC_TR3_HU; 

  H_shi = (u32)RTC_TR3_HT; 

   

   

  RTC_ISR1_RSF=0;

   

   

  LCD_DisplayNum(4,M_shi);

  LCD_DisplayNum(3,M_ge);

  LCD_DisplayNum(2,S_shi);

  LCD_DisplayNum(1,S_ge);

   

   

  Delay(5);

  LED3 = 0;

  Delay(5);

   

}

}

  

    This topic has been closed for replies.

    1 reply

    Super User
    July 24, 2021

    Read RTC_DR3.

    JW

    FCai.1Author
    Visitor II
    July 28, 2021

    It works. THX​