Posted on Leave a comment

Up Counting Timer using STM32L476

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 */
}

Posted on Leave a comment

How to use LCD Driver of STM32L476VGT on STM32L476 Discovery

To use the internal LCD driver of stm32l476; the best way is to use the LCD driver provided in the BSP. It is located inside the STM32Cube_FW_L4_V1.16.0 repository.

  • Go to the
    ..\STM32Cube\Repository\STM32Cube_FW_L4_V1.16.0\Drivers\BSP\STM32L476G-Discovery
  • Copy the stm32l476g_discovery.c, stm32l476g_discovery.h, stm32l476g_discovery_glass_lcd.c and stm32l476g_discovery_glass_lcd.h
  • Paste the files in your project.
  • Include the header file in your project.
    #include “stm32l476g_discovery_glass_lcd.h”

After this you need to

  1. Initialize the LCD segment
    BSP_LCD_GLASS_Init();
  2. Clear the LCD RAM
    BSP_LCD_GLASS_Clear();
  3. Write Data in LCD RAM
    BSP_LCD_GLASS_DisplayChar((uint8_t *)”A”, POINT_ON, DOUBLEPOINT_OFF, 1);
Posted on 1 Comment

How to start a project for STM32L476 Discovery in STM32 Cube IDE

Download the STM32 Cube IDE from https://www.st.com/en/development-tools/stm32cubeide.html

Watch this video tutorial.

Write a program using STM32L476G-DISCO

Step1: Install STM32 Cube IDE

Step2: Create a New Workspace
A workspace is a directory which will contain all your code and library related to your project.

Step 3: click on “Start new STM32 Project” button

Step 4: Select your board “stm32l476G-DISCO”

Step 5: Give your project a name
Do not change any options

Step 6: Select “YES” when prompted for “Initialze all peripheral with their default mode”
It is very important that you select YES other wise it will remove all the associated peripherals and you have to manually add the desired peripherals one by one; which is very difficult for beginners.

After these steps your project is created and it will open a STM32 CUBEMX inside your IDE.

Please watch the video. As there are a lots of steps and instruction which are difficult to explain by writing alone. Video will show you a step by step procedure and give you a basic explainition.

You can now change the option or you can proceed forward and click on generate code. This will create all the required code changes.

Now you can open you “main.c” file inside your IDE and write code.