3047 views|6 replies

205

Posts

0

Resources
The OP
 

[National Technology Low Power Series N32L43x Review] 05. SPI drive TFT screen & TF card to achieve Chinese and English mixed display [Copy link]

 

The National N32L43X series MCU has two hardware SPI interfaces, and we can use one of them to drive the SPI interface TFT display; although this series of MCUs does not have an SDIO interface to operate the TF card, the TF card can work in SPI mode, so our other SPI can be used to drive the TF card and implement file reading operations by transplanting the FatFs file system.

The SPI interface of the N32L43X series MCU can work in master or slave mode, supports full-duplex and simplex high-speed communication modes, has hardware CRC calculation and can be configured in multi-master mode, and has the following features:

  • Full-duplex and simplex synchronous transmission
  • Support master mode, slave mode, multi-master mode
  • 8-bit or 16-bit data frame format
  • Data bit order programmable
  • NSS management by software or hardware
  • Programmable clock polarity and phase
  • Sending and receiving support hardware CRC calculation and verification
  • Support DMA operation

We use the SPI1 interface to drive the TF card and the SPI2 interface to drive the TFT display. The specific pin usage allocation is shown in the following table:

Multiplexing function

Pins

Remap

SPI1_NSS

PB6

AF4

SPI1_SCK

PB3

AF1

SPI1_MISO

PB4

AF1

SPI1_MOSI

PB5

AF0

Multiplexing function

Pins

Remap

SPI2_NSS

PB12

AF0

SPI2_SCK

PB13

AF0

SPI2_MISO

PB14

AF0

SPI2_MOSI

PB15

AF0

Implementing functions

The TF card is driven by the SPI1 interface of the N32L43X series MCU. The data reading operation of the font file GBK_FONT.bin stored in the TF card is realized by transplanting the FatFs file system. The TFT display is driven by the SPI2 interface. The graphic data is extracted by combining the Image2Lcd tool to display the graphics on the TFT display. The English font dot matrix data stored in the MCU FLASH and the GBK Chinese font dot matrix data stored in the TF card are used to realize the mixed display of Chinese and English on the TFT. The main implementation code is as follows:

Read GBK Chinese character font dot matrix data

void FatFs_GetGBK(const char *str, uint8_t *Buffer)
{
    FIL     File;
    FRESULT Result;
    UINT    br = 0;

    uint8_t  GBKH   = str[0];
    uint8_t  GBKL   = str[1];
    uint32_t Offset = 0;

    if(GBKL < 0x7F) Offset = ((GBKH - 0x81) * 190 + GBKL - 0x40);
    else            Offset = ((GBKH - 0x81) * 190 + GBKL - 0x41);

    Result = f_open(&File, "/GBK_FONT.bin", FA_OPEN_ALWAYS | FA_READ);

    if(Result != RES_OK)
    {
        printf("\r\nf_open Fail! Result = %d\r\n", Result);
    }
    else
    {
        f_lseek(&File, Offset * 32);

        Result = f_read(&File, Buffer, 32, &br);

        f_close(&File);
    }
}

Show image

void LCD_DrawImage(void)
{
    uint16_t Color = 0;
    uint32_t Index = 8;

    for(uint32_t i = 0; i < 30; i++)
    {
        for(uint32_t j = 0; j < 113; j++)
        {
            Color   = gImage_LOGO[Index++];
            Color <<= 8;
            Color  |= gImage_LOGO[Index++];

            TFT_DrawPoint(64 + j, 30 + i, Color);
        }
    }

    Index = 8;

    for(uint32_t i = 0; i < 40; i++)
    {
        for(uint32_t j = 0; j < 135; j++)
        {
            Color   = gImage_EEWORLD[Index++];
            Color <<= 8;
            Color  |= gImage_EEWORLD[Index++];

            TFT_DrawPoint(52 + j, 100 + i, Color);
        }
    }
}

Display Chinese and English

void TFT_DrawEN(uint16_t StartX, uint16_t StartY, char ch)
{  
    uint8_t  Data  = 0;
    uint16_t Color = 0;

    for(uint8_t i = 0; i < 16; i++)
    {
        Data = ASCII_1608[ch - 32][i];

        for(uint8_t j = 0; j < 8; j++)
        {
            if((Data >> j) & 0x01) Color = TFT_Forecolor;
            else                   Color = BACKCOLOR;

            TFT_DrawPoint(StartX + j, StartY + i, Color);
        }
    }
}

void TFT_DrawCN(uint16_t StartX, uint16_t StartY, const char *str)
{
    uint8_t Buffer[32];
    uint8_t Array[16][16];
    uint8_t Point[16][16];

    FatFs_GetGBK(str, Buffer);

    for(uint8_t i = 0; i < 8; i++)
    {
        for(uint8_t j = 0; j < 4; j++)
        {
            uint8_t Data = Buffer[i*4+j];

            for(uint8_t k = 0; k < 4; k++)
            {
                if(Data & (0x08 >> (k-0)))  Array[i*2+0][j*4+k-0] = 1;
                else                        Array[i*2+0][j*4+k-0] = 0;
            }

            for(uint8_t k = 4; k < 8; k++)
            {
                if(Data & (0x80 >> (k-4)))  Array[i*2+1][j*4+k-4] = 1;
                else                        Array[i*2+1][j*4+k-4] = 0;
            }
        }
    }

    for(uint8_t i = 0; i < 16; i++)
    {
        for(uint8_t j = 0; j < 16; j++)
        {
            Point[i][j] = Array[j][15-i];
        }
    }

    for(uint8_t i = 0; i < 16; i++)
    {
        for(uint8_t j = 0; j < 16; j++)
        {
            if(Point[15-i][j])
            {
                TFT_DrawPoint(StartX+i, StartY+j, TFT_Forecolor);
            }
            else
            {
                TFT_DrawPoint(StartX+i, StartY+j, BACKCOLOR);
            }
        }
    }
}

void TFT_ShowLOG(uint16_t StartX, uint16_t StartY, const char *str)
{
    while(*str != '\0')
    {
        if(*str < 0x7F)
        {
            if(StartX > (240 - 8))
            {
                StartX = 0; StartY += 16;
            }

            if(StartY > (320 - 16))
            {
                StartX = 0; StartY = 0;

                TFT_ClearScreen(BACKCOLOR);
            }

            TFT_DrawEN(StartX, StartY, *str);

            StartX += 0x08;
            str    += 0x01;
        }
        else
        {
            if(StartX > (240 - 16))
            {
                StartX = 0; StartY += 16;
            }

            if(StartY > (320 - 16))
            {
                StartX = 0; StartY = 0;

                TFT_ClearScreen(BACKCOLOR);
            }

            TFT_DrawCN(StartX, StartY,  str);

            StartX += 0x10;
            str    += 0x02;
        }
    }
}

For other codes such as SPI configuration, TFT display driver and configuration, TF card read and write operations, FATFS file system transplantation, etc., please refer to the software engineering source code in the attachment.

Operation effect

appendix

Software engineering source code: Template_TFT.zip (2.54 MB, downloads: 35)

This post is from Domestic Chip Exchange

Latest reply

good  Details Published on 2022-12-15 10:07

赞赏

1

查看全部赞赏

Personal signatureWe are a team and we work as a team !
 
 

221

Posts

0

Resources
2
 
The SPI interface can work in master or slave mode, supports full-duplex and simplex high-speed communication modes, has hardware CRC calculation and can be configured for multi-master mode learning
This post is from Domestic Chip Exchange
 
 
 

1700

Posts

4

Resources
3
 
What is the screen refresh rate?
This post is from Domestic Chip Exchange

Comments

At present, the whole screen refresh will definitely have an obvious feeling. This article mainly realizes the drive, display pictures, and mixed display of Chinese and English. The refresh rate has not been tested. In addition, the connection method of the Dubind line is used, so the communication rate will definitely be affected. If you want to test it, you still need to make a display board, with DMA  Details Published on 2022-7-18 15:47
 
 
 

205

Posts

0

Resources
4
 
DavidZH posted on 2022-7-18 11:55 What is the screen refresh rate?

At present, there will definitely be an obvious feeling when the whole screen is refreshed. This article mainly realizes the drive, displays pictures, and mixed display of Chinese and English. The refresh rate has not been tested. In addition, the connection method of Dubinding line is used, so there will definitely be an impact on the communication rate. If you want to test it, you still need to make a display board, and cooperate with DMA method to have a higher refresh rate.

This post is from Domestic Chip Exchange
Personal signatureWe are a team and we work as a team !
 
 
 

6818

Posts

11

Resources
5
 
This interface is very beautiful.
This post is from Domestic Chip Exchange
 
 
 

205

Posts

0

Resources
6
 
lugl4313820 posted on 2022-7-23 21:28 This interface is very beautiful.

This post is from Domestic Chip Exchange
Personal signatureWe are a team and we work as a team !
 
 
 

12

Posts

0

Resources
7
 
good
This post is from Domestic Chip Exchange
 
 
 

Just looking around
Find a datasheet?

EEWorld Datasheet Technical Support

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews

Room 1530, Zhongguancun MOOC Times Building, Block B, 18 Zhongguancun Street, Haidian District, Beijing 100190, China Tel:(010)82350740 Postcode:100190

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