Interfacing STM32 microcontroller with STVC101WT-01 LCD/Touch Display

This article mainly aims at making a simple design of beauty instrument, teaching everyone how to use the STONE LCD screen to develop an instrument with a touch screen, as shown in Figure 1 below:

STM32-development-board-tutorial-Use-STONE-LCD-control-STM32 (1)

MCU like STM32 can generally plug in an LCD screen through IIC or SPI or serial port, such as 0.96-inch display screen, 1602 LCD screen, and various TFT LCD screens, and I decided to use the STONE LCD screen to do this project.

Project requirements

Here we want to do a project about the use of medical devices and instruments. This project uses the STVC101WT-01 serial port LCD screen with touch input. The LCD screen sends the command to STM32l053r8 through the serial port. When our STM MCU receives the specific command, it starts to analyze the command. After that, MCU will analyze and recognize specific fan instructions and led instructions, to realize the control of fan and led.

There are four functions:

  • Serial port screen realizes touch key function.
  • Send touch command.
  • MCU analyzing instruction.
  • Control the FAN and LED.

After the function is determined, we need to select the model of each module:

  • Type of touch screen.
  • What kind of MCU module do we use.
  • What kind of peripheral module to use.

I plan to use the STVC101WT-01 serial port for the touch screen, after all, it is very convenient to use, and the market also has a certain proportion, the most important thing is that it is easy to use.

We use a 5V 4W DC power supply for the fan so that it can be controlled directly through the IO port; an ordinary LED is used.

Introducing STVC101WT-01 LCD Module.

STVC101WT-01

STVC101WT-01 is a 10.1 inch 1024x600 industrial grade TFT panel and 4-wire resistance touch screen.

  • brightness is 300cd / m2, LED backlight.
  • RGB colour is 65K.
  • visual area is 222.7mm * 125.3mm.
  • visual angle is 70 / 70 / 50 / 60.
  • working life is 20000 hours.
  • 32-bit cortex-m4 200Hz CPU.
  • CPLD epm240 TFT-LCD controller.
  • 128MB (or 1GB) flash memory.
  • USB port (U disk) download.

Basic functions

Touch screen control / display image / display text / display curve / read and write data / play video and audio.

  • UART interface is RS232 / RS485 / TTL.
  • Voltage is 6v-35v.
  • Power consumption is 3.0w;
  • Working temperature is - 20 ℃ / + 70 ℃;

STVC101WT-01 module communicates with MCU through a serial port. We only need to add the designed UI image through the upper computer through the menu bar options to buttons, text boxes, background pictures, and page logic, then generate the configuration file, and finally download it to the display screen to run.

The manual can be downloaded through the official website:

In addition to the data manual, there are user manuals, common development TOOLBox, drivers, some simple routine demos, video tutorials, and demo projects on the official website.

Introducing STM32L0538 Microcontroller

The ultra-low-power STM32L053X6/8 microcontroller combines the connection capability of the universal serial bus (USB 2.0-less crystal) with the high-performance arm cortex - M0 + 32-bit RISC core running at 32 MHz.

STM32L053X6/8 device has many analog functions, one 12 bit ADC, one DAC, two ultra-low-power comparators, multiple timers, one low power timer (LPTIM), three general 16-bit timers, one basic timer, one RTC and one systick timer can be used as the time base. It also has two watchdogs, a watchdog with independent clock and window functions, and a window watchdog based on a bus clock.

Besides, the STM32L053X6/8 device also embeds standard and advanced communication interfaces: up to two I2C, two SPI, one I2S, two USART, one low-power UART (LPUART) and one USB. The device provides up to 24 capacitive sensing channels, which can simply add touch sensing functionality to any application.

Developmental steps

Generally speaking, the following steps are needed to develop a serial port screen:

  • Design with Tool 2019 software;
  • Realize the interface communication project between MCU and screen;
  • Realize MCU’s analysis of each command and trigger the action of response.

STONE TOOLBox 2019 (Free GUI design software)

STONE TOOLBox 2019 and related USB serial port drivers can be downloaded from our official website. The software is as follows:

STM32-development-board-tutorial-Use-STONE-LCD-control-STM32 (8)

Click here to open, we just need to select MCU model STM32L053R8, and then generate the project.

How to interface TFT LCD with STM32 microcontroller?

Hardware is the basis of all electronic design and the carrier of code. To make the code run, there must be hardware, and to ensure that the code can run normally, there must be a normal hardware connection.

STM32-development-board-tutorial-Use-STONE-LCD-control-STM32 (10)

TOOL to interface design

Use the installed tool 2019, click the new project in the upper left corner, and then click OK.

STM32-development-board-tutorial-Use-STONE-LCD-control-STM32 (11)

After that, a default project will be generated, with a blue background by default. Select it and right-click, then select remove to remove the background. Then right-click the picture file and click Add to add your picture background, as follows:

STM32-development-board-tutorial-Use-STONE-LCD-control-STM32 (12)

Then add the required controls, which are mainly button control, numerical addition and subtraction control, and data variable control.

STM32-development-board-tutorial-Use-STONE-LCD-control-STM32 (13)

The following operations are available when configuring the add/subtract buttons:

Expressed as follows:

  • Configure the effect of button pressing;
  • Configure the variable address of the control to write the value;
  • Configure addition or subtraction;
  • Configure the value range.

When configuring a digital text box:

Followed by:

  • Set the variable address of the control;
  • Set the number of digits;
  • Set the size of the number;
  • Set the alignment of the numbers.

Finally, we click ‘generate configuration tool

Now the configuration is complete

The interface is mainly used to adjust the speed, dose and radio frequency, to achieve the cosmetic effect of the face and waist.

  • Speed adjuSTMent address 0x0001
  • Dose regulation address 0x0002
  • RF regulation address 0x0003

Note:

The relationship between touch addition and subtraction and digital display box is related by variable address, so it is necessary to maintain consistency to achieve correct control.

The development of STM32L053R8

STM32-development-board-tutorial-Use-STONE-LCD-control-STM32 (17)

After selecting the corresponding chip model, click start project to enter the configuration interface.

Configure and select the project name and storage path, then click generate code to generate the code. After adding the protocol code, the demo can be tested. The detailed code is as follows:

Code

/* USER CODE BEGIN Header */
/**
******************************************************************************
* @file : main.c
* @brief : Main program body
******************************************************************************
* @attention
*
* <h2><center>© Copyright (c) 2019 STMicroelectronics.
* All rights reserved.</center></h2>
*
* This software component is licensed by ST under BSD 3-Clause license,
* the "License"; You may not use this file except in compliance with the
* License. You may obtain a copy of the License at:
* opensource.org/licenses/BSD-3-Clause
*
******************************************************************************
*/
/* USER CODE END Header */
/* Includes ------------------------------------------------------------------*/

#include "main.h"

/* Private includes ----------------------------------------------------------*/

/* USER CODE BEGIN Includes */

/* USER CODE END Includes */

/* Private typedef -----------------------------------------------------------*/

/* USER CODE BEGIN PTD */

/* USER CODE END PTD */

/* Private define ------------------------------------------------------------*/

/* USER CODE BEGIN PD */

uint8_t aTxStartMessage[] = "\r\n****UART-Hyperterminal communication based on IT ****\r\nEnter 10 characters using keyboard :\r\n";

uint8_t aRxBuffer[20];

uint8_t RxBuffer[9];

uint8_t IOSwitch = 0;

uint8_t PWM_DUTY = 20;// Adjust duty cycle, this value can only be 0-100

/* USER CODE END PD */

/* Private macro -------------------------------------------------------------*/

/* USER CODE BEGIN PM */

/* USER CODE END PM */

/* Private variables ---------------------------------------------------------*/

TIM_HandleTypeDef htim2;

UART_HandleTypeDef huart1;

/* USER CODE BEGIN PV */

#define VGUS_Variable_cmd 0x83

/* USER CODE END PV */

/* Private function prototypes -----------------------------------------------*/

void SystemClock_Config(void);

static void MX_GPIO_Init(void);

static void MX_USART1_UART_Init(void);

static void MX_TIM2_Init(uint16_t param);

void FAN_ON();

void FAN_OFF();

/* USER CODE BEGIN PFP */

void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart)// Analyze the received data

{

if(huart->Instance==USART1)//

{

HAL_UART_Transmit(&huart1, (uint8_t *)RxBuffer, 9, 0xFFFF);

switch(RxBuffer[3])//Analysis

{

case VGUS_Variable_cmd:
{

//

/********* Stop timer, reconfigure ******/

HAL_TIM_Base_Stop_IT(&htim2);//Stop timer

MX_TIM2_Init( (uint16_t)RxBuffer[8] );

// MX_TIM2_Init( 1);

PWM_DUTY = RxBuffer[8];

HAL_TIM_Base_Start_IT(&htim2);

break;

}

default:

break;

}

}

}

void FAN_ON()//Open LED

{

HAL_GPIO_WritePin(FAN_GPIO_Port, FAN_Pin, GPIO_PIN_SET);

}

void FAN_OFF()//Close LED

{

HAL_GPIO_WritePin(FAN_GPIO_Port, FAN_Pin, GPIO_PIN_RESET);

}

/* USER CODE END PFP */

uint8_t cout = 0;

/* Private user code ---------------------------------------------------------*/

/* USER CODE BEGIN 0 */

void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)

{

if (htim->Instance == htim2.Instance)

{

cout ++;

if(cout <= PWM_DUTY)// Adjust LED brightness

{

// HAL_GPIO_WritePin(FAN_GPIO_Port, FAN_Pin, GPIO_PIN_SET);

HAL_GPIO_WritePin(LED_GPIO_Port, LED_Pin, GPIO_PIN_SET);

}

else if((cout > PWM_DUTY)&& (cout < 100))

{

// HAL_GPIO_WritePin(FAN_GPIO_Port, FAN_Pin, GPIO_PIN_RESET);

HAL_GPIO_WritePin(LED_GPIO_Port, LED_Pin, GPIO_PIN_RESET);

}

else

{

cout = 0;

}

if(cout == 20)

{

HAL_TIM_Base_Stop_IT(&htim2);

}

}

}

/* USER CODE END 0 */

/**

* @brief The application entry point.

* @retval int

*/

int main(void)

{

/* USER CODE BEGIN 1 */

/* USER CODE END 1 */

/* MCU Configuration--------------------------------------------------------*/

/* Reset of all peripherals, Initializes the Flash interface and the Systick. */

HAL_Init();

/* USER CODE BEGIN Init */

/* USER CODE END Init */

/* Configure the system clock */

SystemClock_Config();

/* USER CODE BEGIN SysInit */

/* USER CODE END SysInit */

/* Initialize all configured peripherals */

MX_GPIO_Init();

MX_USART1_UART_Init();

MX_TIM2_Init(1);

/* USER CODE BEGIN 2 */

HAL_UART_Transmit_IT(&huart1, (uint8_t *)aTxStartMessage, sizeof(aTxStartMessage));

HAL_TIM_Base_Start_IT(&htim2);

/* USER CODE END 2 */

/* Infinite loop */

/* USER CODE BEGIN WHILE */

while (1)

{

/* USER CODE END WHILE */

/* USER CODE BEGIN 3 */

}

/* USER CODE END 3 */

}

Then you can download the code to the development board for testing.

STM32-development-board-tutorial-Use-STONE-LCD-control-STM32 (19)

This touch screen looks very good, I am also recently conceived a project using LCD, maybe I can use it.

1 Like