729 views|5 replies

6822

Posts

11

Resources
The OP
 

[National Technology Automotive MCU N32A455 Development Board] 2. Drive LCD screen [Copy link]

[National Technology Automotive MCU N32A455 Development Board] 1. Development Board Test - Automotive Electronics

Continuing from the previous article, my homework requires the use of an LCD screen, so I will drive the LCD screen first.

【Screen and GPIO selection】

1. There are many screens on hand. A big guy wrote a stm7735 one before, so I "learned" from his post [National Technology Automotive MCU N32A455 Development Board] Evaluation - 4 - Zhongjingyuan TFT_LCD Transplantation + SPI2 Test - Evaluation Center Special Edition . Special thanks to @沛红恩. Mainly because I have too many things on hand recently.

2. GPIO selection, in order to prepare hardware SPI for driving later, considering the speed, I chose SPI1 as the interface. For specific pin selection, see the following macro definition code:

#define LCD_SPI                SPI1
#define LCD_SPI_CLK            RCC_APB2_PERIPH_SPI1
#define LCD_SPI_SCK_PIN        GPIO_PIN_5 /* PA.05 */
#define LCD_SPI_SCK_GPIO_PORT  GPIOA      /* GPIOA */
#define LCD_SPI_SCK_GPIO_CLK   RCC_APB2_PERIPH_GPIOA
#define LCD_SPI_MISO_PIN       GPIO_PIN_6 /* PA.06 */
#define LCD_SPI_MISO_GPIO_PORT GPIOA      /* GPIOA */
#define LCD_SPI_MISO_GPIO_CLK  RCC_APB2_PERIPH_GPIOA
#define LCD_SPI_MOSI_PIN       GPIO_PIN_7 /* PA.07 */
#define LCD_SPI_MOSI_GPIO_PORT GPIOA      /* GPIOA */
#define LCD_SPI_MOSI_GPIO_CLK  RCC_APB2_PERIPH_GPIOA

#define LCD_CS_PIN             GPIO_PIN_10 /* PE.10 */
#define LCD_CS_GPIO_PORT       GPIOE      /* GPIOE */
#define LCD_CS_GPIO_CLK        RCC_APB2_PERIPH_GPIOE

#define LCD_RES_PIN             GPIO_PIN_8 /* PE.8 */
#define LCD_RES_GPIO_PORT       GPIOE      /* GPIOE */
#define LCD_RES_GPIO_CLK        RCC_APB2_PERIPH_GPIOE

#define LCD_BL_PIN             GPIO_PIN_9 /* PE.9 */
#define LCD_BL_GPIO_PORT       GPIOE      /* GPIOE */
#define LCD_BL_GPIO_CLK        RCC_APB2_PERIPH_GPIOE

3. In the screen driver, I used a mode that is compatible with software SPI and hardware SPI, and used the macro #define SPI_Soft to switch which mode to use.

4. GPIO initialization. Currently, I only use the output interface, so all 5 IOs are initialized to output 50MHz speed:

void LCD_GPIO_Init(void)
{
	GPIO_InitType GPIO_InitStructure;

	RCC_EnableAPB2PeriphClk(RCC_APB2_PERIPH_GPIOE, ENABLE);
	RCC_EnableAPB2PeriphClk(RCC_APB2_PERIPH_GPIOA, ENABLE);
	GPIO_InitStructure.Pin        =  LCD_CS_PIN | LCD_RES_PIN | LCD_BL_PIN;
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  GPIO_InitStructure.GPIO_Mode  = GPIO_Mode_Out_PP;
#ifdef  SPI_Soft
	GPIO_InitPeripheral(GPIOE, &GPIO_InitStructure);
	GPIO_InitStructure.Pin        = LCD_SPI_SCK_PIN | LCD_SPI_MISO_PIN | LCD_SPI_MOSI_PIN ;
  GPIO_InitPeripheral(GPIOA, &GPIO_InitStructure);
#else
		
	  RCC_EnableAPB2PeriphClk(LCD_SPI_CLK, ENABLE);

    /*!< Configure sFLASH_SPI pins: SCK */
    GPIO_InitStructure.Pin        = LCD_SPI_SCK_PIN;
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
    GPIO_InitStructure.GPIO_Mode  = GPIO_Mode_AF_PP;
    GPIO_InitPeripheral(LCD_SPI_SCK_GPIO_PORT, &GPIO_InitStructure);

    /*!< Configure sFLASH_SPI pins: MOSI */
    GPIO_InitStructure.Pin = LCD_SPI_MOSI_PIN;
    GPIO_InitPeripheral(LCD_SPI_MOSI_GPIO_PORT, &GPIO_InitStructure);

    /*!< Configure sFLASH_SPI pins: MISO */
    GPIO_InitStructure.Pin       = LCD_SPI_MISO_PIN;
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
    GPIO_InitPeripheral(LCD_SPI_MISO_GPIO_PORT, &GPIO_InitStructure);
#endif
}

Function to modify SPI output data at the same time:

/******************************************************************************
      函数说明:LCD串行数据写入函数
      入口数据:dat  要写入的串行数据
      返回值:  无
******************************************************************************/
void LCD_Writ_Bus(u8 dat) 
{	
	u8 i;
	LCD_CS_Clr();
#ifdef  SPI_Soft
	for(i=0;i<8;i++)
	{			  
		LCD_SCLK_Clr();
		if(dat&0x80)
		{
		   LCD_MOSI_Set();
		}
		else
		{
		   LCD_MOSI_Clr();
		}
		LCD_SCLK_Set();
		dat<<=1;
	}	
#else
	
	SPI_I2S_TransmitData(LCD_SPI, dat);
	while (SPI_I2S_GetStatus(LCD_SPI, SPI_I2S_TE_FLAG) == RESET)
	{;}
#endif
  LCD_CS_Set();	
}

In this way, the work of porting the code is completed. In fact, if it is a single display, you don’t need to initialize CS and BLK. CS is directly connected to ground and BLK is directly connected to VCC. In this way, 4 lines can be used for driving.

5. Create a font library. Open PCtoLCD and create a 24*24 font:

In the settings, select as shown below.

Finally, enter the required Chinese characters in the area shown in the figure below, generate the font template, and then copy the generated content into the font library.

Then write the test code in the main program:


#include "main.h"

#include "log.h"
#include "lcd_init.h"
#include "lcd.h"


int main(void)
{

    log_init();

	
		LCD_Init();//LCD初始化
		LCD_Fill(0,0,LCD_W,LCD_H,WHITE);
		LCD_ShowChinese(10,0,"国民技术",RED,WHITE,24,0);
		LCD_ShowString(24,30,"N32A455",RED,WHITE,16,0);
		while(1)
		{

		}

}

After downloading to the development board, the effect is as shown below:

But I haven't used SPI to drive the screen well yet, I'll try again later. Attached is the project source code.

ST7735_LDC.zip (8.37 MB, downloads: 5)
This post is from Automotive Electronics

Latest reply

It is a very good chip, and we should try to make it shine more. Will you use this chip in your own projects?   Details Published on 2024-4-6 14:23

赞赏

1

查看全部赞赏


1117

Posts

2

Resources
2
 

What series of automotive MCUs does the N32A455 compare to? NXP's S32K144/6/8 had strong market promotion in the past few years.

This post is from Automotive Electronics

Comments

I don't have a clear dream about this, I just use it. But in the past, NXP and Infineon accounted for the majority of automotive specifications.  Details Published on 2024-3-22 15:34
 
 

6822

Posts

11

Resources
3
 
beyond_笑谈Published on 2024-3-22 15:11 What series of automotive MCUs does N32A455 match? NXP's S32K144/6/8 had strong market promotion in the past few years

I don't have a clear dream about this, I just use it. But in the past, NXP and Infineon accounted for the majority of automotive specifications.

This post is from Automotive Electronics

Comments

I just took a look at the specification sheet. This MCU can be used for some automotive-grade controllers with non-active functional safety, except for navigation systems and audio-visual entertainment systems.  Details Published on 2024-3-22 16:33
 
 
 

1117

Posts

2

Resources
4
 
lugl4313820 posted on 2024-3-22 15:34 I am not very clear about this, I just use it. However, NXP and Infineon used to account for the majority of automotive specifications.

I just took a look at the specification sheet. This MCU can be used for some automotive-grade controllers with non-active functional safety, except for navigation systems and audio-visual entertainment systems.

This post is from Automotive Electronics

Comments

It is a very good chip, and we should try to make it shine more.  Details Published on 2024-3-22 16:48
 
 
 

6822

Posts

11

Resources
5
 
beyond_笑谈Published on 2024-3-22 16:33 I just looked at the specification sheet. This MCU can be used for some non-active functional safety automotive-grade controllers, except for navigation systems and audio-visual entertainment systems.

It is a very good chip, and we should try to make it shine more.

This post is from Automotive Electronics
 
 
 

37

Posts

0

Resources
6
 

It is a very good chip, and we should try to make it shine more.

Will you use this chip in your own projects?

This post is from Automotive Electronics
 
 
 

Guess Your Favourite
Just looking around
Find a datasheet?

EEWorld Datasheet Technical Support

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号
快速回复 返回顶部 Return list