21、stm32使用LTDC驱动LCD

注:本文基于stm32使用FMC驱动SDRAM(IS42S32800G-6BLI)工程继续开发

本例使用安富莱的H743XIH板子驱动LTDC点亮7寸LCD

硬件接线:RGB888


一、cubemx配置

1、LTDC配置




注意此引脚应于上面的硬件接线图一致

2、配置DMA2D


3、背光引脚和触摸引脚

4、时钟配置


5、定时器配置

定时器6用来做精确延时

TIM7配置成1ms中断一次

触摸先不予弄

生成代码...

二、代码编写

1、移植文件至工程中,可以去下载完整工程中获取

字体文件

ascii_32.h|ascii_32.c

AsciiFonts.h

fonts_32.c|fonts_32.h

LCD文件

lcd_driver.c|lcd_driver.h

lcd_h7_driver.c|lcd_h7_driver.h

精确延时文件

delay_driver.c|delay_driver.h

触摸文件

bsp_i2c.c|bsp_i2c.h

GT911_driver.c|GT911_driver.h

touch_driver.c|touch_driver.h

2、更改精确延时文件delay_driver.c中得接口dDelayTIM和dDelayTIM_Handle为定时器6

3、bsp.c文件中初始化硬件,编写1m中断执行函数

c 复制代码
/**********************************************************************
*file:板级支持包文件
*author:残梦
*versions:V1.0
*date:2023.08.10
*note:
**********************************************************************/
#include "bsp.h"
#include "common_driver.h"
#include "tim.h"
#include "lcd_driver.h"
#include "bsp_i2c.h"
#include "touch_driver.h"

/****************************************
@function:板硬件初始化
@param:void
@return:小于0--失败,0--成功
@note:
****************************************/
int32_t bsp_init(void)
{
    bsp_i2c_Init();
    touch_init();
    LCD_InitHard();
    HAL_TIM_Base_Start_IT(&htim7);
    return 0;
}

void bsp_Task_1ms(void)
{
    static uint16_t ms = 0;

    ms++;
    if(ms >= 1000)
    {
        ms = 0;
        //printf("1s到了\n");
    }
    touch_1ms();
}

bsp.h

c 复制代码
#ifndef _bsp_H_
#define _bsp_H_
#ifdef __Cplusplus
#extern "C" {
#endif
#include "stdint.h"

int32_t bsp_init(void);
void bsp_Task_1ms(void);

#ifdef __Cplusplus
}
#endif
#endif

4、tim.c文件中添加定时器回调

c 复制代码
/* USER CODE BEGIN 0 */
#include "bsp.h"
/* USER CODE END 0 */
c 复制代码
/* USER CODE BEGIN 1 */
void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
{
  if(htim->Instance == TIM7)
  {
    bsp_Task_1ms();
  }
}
/* USER CODE END 1 */

5、main.c中主函数添加触摸测试函数

c 复制代码
/* USER CODE BEGIN Header */
/**
  ******************************************************************************
  * @file           : main.c
  * @brief          : Main program body
  ******************************************************************************
  * @attention
  *
  * <h2><center>&copy; Copyright (c) 2023 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"
#include "dma2d.h"
#include "ltdc.h"
#include "tim.h"
#include "usart.h"
#include "gpio.h"
#include "fmc.h"

/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */
#include "bsp.h"
#include "common_driver.h"
#include "sdram_driver.h"
/* USER CODE END Includes */

/* Private typedef -----------------------------------------------------------*/
/* USER CODE BEGIN PTD */
#include "touch_driver.h"
/* USER CODE END PTD */

/* Private define ------------------------------------------------------------*/
/* USER CODE BEGIN PD */
/* USER CODE END PD */

/* Private macro -------------------------------------------------------------*/
/* USER CODE BEGIN PM */

/* USER CODE END PM */

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

/* USER CODE BEGIN PV */

/* USER CODE END PV */

/* Private function prototypes -----------------------------------------------*/
void SystemClock_Config(void);
static void MPU_Config(void);
/* USER CODE BEGIN PFP */

/* USER CODE END PFP */

/* Private user code ---------------------------------------------------------*/
/* USER CODE BEGIN 0 */

/* USER CODE END 0 */

/**
  * @brief  The application entry point.
  * @retval int
  */
int main(void)
{
  /* USER CODE BEGIN 1 */

  /* USER CODE END 1 */

  /* MPU Configuration--------------------------------------------------------*/
  MPU_Config();

  /* Enable I-Cache---------------------------------------------------------*/
  SCB_EnableICache();

  /* Enable D-Cache---------------------------------------------------------*/
  SCB_EnableDCache();

  /* 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_FMC_Init();
  MX_USART1_UART_Init();
  MX_DMA2D_Init();
  MX_LTDC_Init();
  MX_TIM6_Init();
  MX_TIM7_Init();
  /* USER CODE BEGIN 2 */
  if(bsp_init() < 0){printf("error:bsp_init()\r\n");Error_Handler();}

  /* USER CODE END 2 */

  /* Infinite loop */
  /* USER CODE BEGIN WHILE */
  while (1)
  {
    /* USER CODE END WHILE */

    /* USER CODE BEGIN 3 */
    touch_Test();
    HAL_Delay(1000);
  }
  /* USER CODE END 3 */
}

编译下载即可...

触摸屏幕随手指触摸轨迹画圆圈

屏幕800*480

三、完整工程下载

链接:https://pan.baidu.com/s/1PQfEsbaoNqUvyevT0YbDgA
提取码:p7j6

四、笔记

1、如何验证 LTDC 的时序配置是否正确

ltdc.c文件中void MX_LTDC_Init(void)内

下载程序,此处开启背光,测试背景色是否正常,如果背景层可以正常显示绿色,说明引脚和时序配置都是没有问题的

◆首先要清楚一点,当前的配置是否成功与 SDRAM 没有任何关系,因为背景层还用不到 SDRAM,图层 1 和图层 2 才需要 SDRAM 做显存使用。

◆ 从硬件着手检查,保证 STM32H7 芯片焊接没问题,TFT 接口一定要牢固,防止接触不良,特别是使用 FPC 软排线的时候,测试阶段,软排线越短越好。有时候也可能是显示屏有问题,最好可以备两个显示屏测试。

◆ 从软件配置着手检查,查看 LTDC 涉及到的所有引脚是否配置,引脚时钟是否使能。有时候无法显示也有可能是板子硬件设计不规范导致干扰较大造成的,此时,可以降低 LTDC 所涉及到 GPIO 的速度等级。

◆ 如果显示了,但是显示的位置不正确,可以重新调整时序参数即可。

相关推荐
嗯嗯=1 小时前
STM32单片机学习篇9
stm32·单片机·学习
小范馆5 小时前
ESP各模组的引脚图-小智接线图
stm32
松涛和鸣5 小时前
DAY63 IMX6ULL ADC Driver Development
linux·运维·arm开发·单片机·嵌入式硬件·ubuntu
想放学的刺客9 小时前
单片机嵌入式试题(第23期)嵌入式系统电源管理策略设计、嵌入式系统通信协议栈实现要点两个全新主题。
c语言·stm32·单片机·嵌入式硬件·物联网
猫猫的小茶馆9 小时前
【Linux 驱动开发】五. 设备树
linux·arm开发·驱动开发·stm32·嵌入式硬件·mcu·硬件工程
YouEmbedded9 小时前
解码内部集成电路(IIC)与OLED屏
stm32·0.96寸oled·硬件iic·软件模拟iic·图片取模·汉字取模
jghhh0110 小时前
基于上海钜泉科技HT7017单相计量芯片的参考例程实现
科技·单片机·嵌入式硬件
恶魔泡泡糖10 小时前
51单片机外部中断
c语言·单片机·嵌入式硬件·51单片机
意法半导体STM3211 小时前
【官方原创】如何基于DevelopPackage开启安全启动(MP15x) LAT6036
javascript·stm32·单片机·嵌入式硬件·mcu·安全·stm32开发
v_for_van11 小时前
STM32低频函数信号发生器(四通道纯软件生成)
驱动开发·vscode·stm32·单片机·嵌入式硬件·mcu·硬件工程