Up Counting Timer using STM32L476

Posted

in

by

I have created this Upcounting timer using the RTC of STM32L476vgt. In this timer, time will keep on incrementing and it will be displayed using the onboard LCD.

How to Read RTC of STM32L476G-DISCO

Here is the code that I have used to make this.

I have used STM32 CUBE IDE for programming and debugging purposes.

  MX_RTC_Init();				// RTC initalization and configuration created using integrated cube mx
  /* USER CODE BEGIN 2 */
  BSP_LCD_GLASS_Init();
  BSP_LCD_GLASS_Clear();
  BSP_LCD_GLASS_DisplayString((uint8_t *)"HALLO");
  HAL_Delay(1000);
  BSP_LCD_GLASS_DisplayString((uint8_t *)"EXASUB");
  HAL_Delay(2000);


  /* USER CODE END 2 */

  /* Infinite loop */
  /* USER CODE BEGIN WHILE */

  RTC_TimeTypeDef readTime;	// RTC Time structure
  RTC_DateTypeDef readDate;	// RTC Date structure
  while (1)
  {
    /* USER CODE END WHILE */
    MX_USB_HOST_Process();

    /* USER CODE BEGIN 3 */

    char bufSec[2];
    char bufMin[2];
    char bufHou[2];
    HAL_RTC_GetTime(&hrtc, &readTime, RTC_FORMAT_BIN);	// function to read time from RTC shadow register
    HAL_RTC_GetDate(&hrtc, &readDate, RTC_FORMAT_BIN);	// function to read date from RTC shadow register
   itoa(readTime.Seconds,bufSec,10);
   itoa(readTime.Minutes,bufMin,10);
   itoa(readTime.Hours,bufHou,10);
   if(readTime.Seconds == 0){
	   BSP_LCD_GLASS_Clear();
   }
   if(readTime.Minutes == 0){
	   BSP_LCD_GLASS_Clear();
   }
   /*
    if(readTime.Hours == 0){
   	   BSP_LCD_GLASS_Clear();
      }
   */
   BSP_LCD_GLASS_DisplayChar((uint8_t *)&bufHou[0], POINT_OFF, DOUBLEPOINT_OFF, 0);
   BSP_LCD_GLASS_DisplayChar((uint8_t *)&bufHou[1], POINT_OFF, DOUBLEPOINT_ON, 1);
   BSP_LCD_GLASS_DisplayChar((uint8_t *)&bufMin[0], POINT_OFF, DOUBLEPOINT_OFF, 2);
   BSP_LCD_GLASS_DisplayChar((uint8_t *)&bufMin[1], POINT_OFF, DOUBLEPOINT_ON, 3);
   BSP_LCD_GLASS_DisplayChar((uint8_t *)&bufSec[0], POINT_OFF, DOUBLEPOINT_OFF, 4);
   BSP_LCD_GLASS_DisplayChar((uint8_t *)&bufSec[1], POINT_OFF, DOUBLEPOINT_OFF, 5);

    HAL_Delay(1000);									// HAL Delay of 1000 millisecond
  }
  /* USER CODE END 3 */
}

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *