yahboom
HomeTutorialsProduct
Solution
Blog
Online Store
About Us
EN/中文
Store
MSPM0G3519 Development Board📖
1. Introduction to MSPM0
  • 1. Introduction to MSPM0
2. Development environment construction
  • 1. CCS Theia Development
  • 2. MDK Arm Development
  • 3. UniFlash Downloader
  • 4. DAP-LINK download program
  • 5. Program Simulation and Debugging
  • 6. Engineering transplantation
3. Keil basic case
  • 1. Turn on the LED light
  • 2. System Delay
  • 3. Button Control
  • 4. External Interruption
  • 5. Serial Communication
  • 6. Timer
  • 7. PWM Breathing Light
  • 8. ADC Acquisition
  • 9. DMA Transfer
  • 10. Get MPU6050 data (I2C)
  • 11. LCD Display (SPI)
4. CCS basic case
  • 1. Turn on the LED light
  • 2. System Delay
  • 3. Button Control
  • 4. External Interruption
  • 5. Serial Communication
  • 6. Timer
  • 7. PWM Breathing Light
  • 8. ADC Acquisition
  • 9. DMA Transfer
  • 10. Get MPU6050 data (I2C)
  • 11. LCD Display (SPI)
5. MSPM0 Robot Expansion Board
  • 1. MSPM0 Robot Expansion Board Introduction
  • 2. Custom Buttons
  • 3. Drive Buzzer
6. MSPM0-K230Vision module application
  • 1. K230 Color Recognition
  • 2. K230 Barcode Recognition
  • 3. K230 QR Code Recognition
  • 4. K230 Apriltag Code Recognition
  • 5. K230 DM Code Recognition
  • 6. K230 Face Detection
  • 7. K230 Gaze Direction
  • 8. K230 Face Recognition
  • 9. K230 Human Body Detection
  • 10. K230 Fall Detection
  • 11. K230 Palm Detection
  • 12. K230 Gesture Recognition
  • 13. K230 OCR Character Recognition
  • 14. K230 Object Detection
  • 15. K230 Target Tracking
  • 16. K230 Self-learning Object Recognition
  • 17. K230 License Plate Recognition
7. MSPM0-K210Vision module application
  • 0. K210 Prerequisites For Making A Coprocessor - Must-see
  • 1. MSPM0_K210 Color Recognition
  • 2. MSPM0_K210 Barcode Recognition
  • 3. MSPM0_K210 QR Code Recognition
  • 4. MSPM0_K210 Mechanical Code Recognition
  • 5. MSPM0_K210 Face Detection
  • 6. MSPM0_K210 Facial Feature Detection
  • 7. MSPM0_K210 Mask Detection
  • 8. MSPM0_K210 Face Recognition
  • 9. MSPM0_K210 Object Detection
  • 10. MSPM0_K210 Self-study Classification
  • 11. MSPM0_K210 Handwritten Digit Recognition
8. Expansion case
  • 1. Autonomous Driving Car
  • 2. Vehicle-mounted Balance Ball Motion Control System
Download
  • Code
  • Hardware_Info
  • Software_Tools
Download ZIP

Welcome to MSPM0G3519 Development Board repository

11. LCD Display (SPI)

LCD Display (SPI)

LCD Display (SPI)1. Learning ObjectivesSPI ProtocolSPI Hardware InterfaceSPI AdvantagesSPI Disadvantages2. Hardware Setup3. Experiment Steps1. Open SYSCONFIG Configuration Tool2. SPI Parameter Configuration3. Pin Parameter ConfigurationLCD ScreenExternal Flash4. SPI Protocol Usage5. Write Program6. Compile4. Program Analysis5. Experimental Phenomena

 

1. Learning Objectives

  1. Learn basic SPI communication knowledge.

  2. Read data from flash and display it on the onboard LCD screen.

 

SPI Protocol

SPI protocol (Serial Peripheral Interface) is a commonly used synchronous serial communication protocol designed for high-speed, short-distance communication between microcontrollers and external devices. It supports full-duplex communication, meaning data can be sent and received simultaneously between master and slave devices. It is commonly used for memory chips, sensors, display drivers, wireless modules, and other devices.

SPI Hardware Interface

SPI protocol typically uses four lines for data transmission:

  • SCLK (Serial Clock): Clock signal generated by the master device for synchronizing communication.

  • MOSI (Master Output Slave Input): Master device sends data to slave device.

  • MISO (Master Input Slave Output): Slave device sends data to master device.

  • SS/CS (Slave Select): Master device activates the target slave device through chip select signal.

SPI Advantages

  • Fast communication speed, suitable for high bandwidth applications.

  • Supports full-duplex transmission, improving efficiency.

  • Simple hardware implementation, direct interface.

  • Supports multiple slave device connections.

SPI Disadvantages

  • Lack of standardized error detection mechanism.

  • Master device pin count increases with the number of slave devices.

  • Communication distance is limited, usually used for onboard communication.

 

2. Hardware Setup

W25Q32 is a common serial flash device using SPI (Serial Peripheral Interface) protocol. It has high-speed read, write, and erase functions and is widely used in embedded systems, storage devices, routers, and other high-performance electronic devices. W25Q32 has a capacity of 32 Mbit (4 MB). The numbers in the model represent different capacity options, such as W25Q16, W25Q64, W25Q128, etc., to meet requirements in different application scenarios.

W25Q32 chip memory is allocated by sector and block. Specifically:

  • Sector: Each sector is 4KB.

  • Block: Each block contains 16 sectors, meaning one block is 64KB.

These storage unit structures make data management and storage operations more flexible, especially suitable for embedded systems and storage applications that require frequent read/write operations.

We use hardware SPI to drive W25Q32, so we need to determine if the pins we set have hardware SPI peripheral interface. According to the data manual, PB14~PB17 can be multiplexed as SPI1's 4 communication lines.

image-20241129202635131

This course does not require additional hardware. You can directly use the onboard LCD screen and external storage flash on the MSPM0G3519 motherboard.

MSPM0G3519 Main Control Diagram:

image-20241118203957884

W25Q32 Part Schematic:

image-20241129202038392

LCD Screen Part Schematic:

image-20241126145019204

3. Experiment Steps

1. Open SYSCONFIG Configuration Tool

Create a new empty project empty in CCS.

image-20241126182939655

image-20241126183128934

Find and open the empty.syscfg file in the left workspace of CCS.

image-20241127152938881

2. SPI Parameter Configuration

Find the SPI column on the left, click to enter, and add SPI peripheral.

image-20241130082640872

image-20241130082953317

In most SPI protocols, the chip select needs to remain low during the entire timing for sending and receiving. However, the SPI peripheral's chip select will go high after each frame is sent and received. Therefore, the CS chip select line needs to be controlled independently by the MCU's IO pin. The SPI peripheral's CS pin cannot be used. Here, GPIO method (software method) is used to control the CS pin output.

image-20241130083026472

3. Pin Parameter Configuration

LCD Screen

Backlight BLK:

image-20241126153008730

CS, DC, RES, MOSI, SCLK are as follows:

image-20241126153332062

image-20241126153404464

External Flash

CS1:

image-20241130083259274

4. SPI Protocol Usage

We create a new folder in the project folder: BSP. In the BSP folder, create four new files: lcd.c, lcd.h, bsp_spi.c, and bsp_spi.h.

The LCD display driver and font library are as follows, put in the BSP folder.

image-20241128210143217

Update header file paths.

image-20241128210532713

image-20241128210500585

5. Write Program

Define LCD display operation interface and related functions.

lcd.h

​x
#ifndef __LCD_H
#define __LCD_H
#include <stdint.h>


void LCD_Fill(uint16_t xsta,uint16_t ysta,uint16_t xend,uint16_t yend,uint16_t color);// Specify area fill color
void LCD_DrawPoint(uint16_t x,uint16_t y,uint16_t color);// Draw a point at the specified location
void LCD_DrawLine(uint16_t x1,uint16_t y1,uint16_t x2,uint16_t y2,uint16_t color);// Draw a line at the specified position
void LCD_DrawRectangle(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2,uint16_t color);// Draw a rectangle at the specified location
void Draw_Circle(uint16_t x0,uint16_t y0,uint8_t r,uint16_t color);// Draw a circle at the specified location

void LCD_ShowChinese(uint16_t x,uint16_t y,uint8_t *s,uint16_t fc,uint16_t bc,uint8_t sizey,uint8_t mode);// Display Chinese character string
void LCD_ShowChinese12x12(uint16_t x,uint16_t y,uint8_t *s,uint16_t fc,uint16_t bc,uint8_t sizey,uint8_t mode);// Display a single 12x12 Chinese character
void LCD_ShowChinese16x16(uint16_t x,uint16_t y,uint8_t *s,uint16_t fc,uint16_t bc,uint8_t sizey,uint8_t mode);// Display a single 16x16 Chinese character
void LCD_ShowChinese24x24(uint16_t x,uint16_t y,uint8_t *s,uint16_t fc,uint16_t bc,uint8_t sizey,uint8_t mode);// Display a single 24x24 Chinese character
void LCD_ShowChinese32x32(uint16_t x,uint16_t y,uint8_t *s,uint16_t fc,uint16_t bc,uint8_t sizey,uint8_t mode);// Display a single 32x32 Chinese character

void LCD_ShowChar(uint16_t x,uint16_t y,uint8_t num,uint16_t fc,uint16_t bc,uint8_t sizey,uint8_t mode);// Display a character
void LCD_ShowString(uint16_t x,uint16_t y,const uint8_t *p,uint16_t fc,uint16_t bc,uint8_t sizey,uint8_t mode);// Display String
uint32_t mypow(uint8_t m,uint8_t n);// Power
void LCD_ShowIntNum(uint16_t x,uint16_t y,uint16_t num,uint8_t len,uint16_t fc,uint16_t bc,uint8_t sizey);// Display integer variables
void LCD_ShowFloatNum1(uint16_t x,uint16_t y,float num,uint8_t len,uint16_t fc,uint16_t bc,uint8_t sizey);// Display variables with two decimal places

void LCD_ShowPicture(uint16_t x,uint16_t y,uint16_t length,uint16_t width,const uint8_t pic[]);// Show image


// Brush Color
#define WHITE           0xFFFF
#define BLACK           0x0000
#define BLUE            0x001F
#define BRED            0XF81F
#define GRED            0XFFE0
#define GBLUE           0X07FF
#define RED             0xF800
#define MAGENTA         0xF81F
#define GREEN           0x07E0
#define CYAN            0x7FFF
#define YELLOW          0xFFE0
#define BROWN           0XBC40 // Brown
#define BRRED           0XFC07 // Brown red
#define GRAY            0X8430 // Gray
#define DARKBLUE        0X01CF  // Dark blue
#define LIGHTBLUE       0X7D7C  // Light blue
#define GRAYBLUE        0X5458 // Gray blue
#define LIGHTGREEN      0X841F // Light green
#define LGRAY           0XC618 // Light gray (PANNEL), window background color
#define LGRAYBLUE       0XA651 // Light gray blue (middle layer color)
#define LBBLUE          0X2B12 // Light brown blue (inverted color of selected item)

#endif

Next is the LCD display driver.

lcd.c (only partial excerpt shown here, see project source code for details)

xxxxxxxxxx
#include "lcd.h"
#include "lcd_init.h"
#include "lcdfont.h"
#include "board.h"


/******************************************************************************
      Function description: Fill the specified area with color
      Input data: xsta, ysta starting coordinates
                  xend, yend ending coordinates
                  color the color to be filled
      Return value: None
******************************************************************************/
void LCD_Fill(uint16_t xsta,uint16_t ysta,uint16_t xend,uint16_t yend,uint16_t color)
{
    uint16_t i,j;
    LCD_Address_Set(xsta,ysta,xend-1,yend-1);// Set the display range
    for(i=ysta;i<yend;i++)
    {
        for(j=xsta;j<xend;j++)
        {
            LCD_WR_DATA(color);
        }
    }
}

/******************************************************************************
      Function description: Draw a point at the specified position
      Input data: x, y coordinates of the point
                  color color of the point
      Return value: None
******************************************************************************/
void LCD_DrawPoint(uint16_t x,uint16_t y,uint16_t color)
{
    LCD_Address_Set(x,y,x,y);// Set the cursor position
    LCD_WR_DATA(color);
}
...

bsp_spi.h

xxxxxxxxxx
#ifndef _BSP_SPI_H__
#define _BSP_SPI_H__

#include "board.h"

// CS pin output control
// x=0 when output is low level
// x=1 when output is high level
#define SPI_CS(x)  ( (x) ? DL_GPIO_setPins(CS1_PORT,CS1_PIN_17_PIN) : DL_GPIO_clearPins(CS1_PORT,CS1_PIN_17_PIN) )

uint16_t W25Q32_readID(void);// Read the ID of W25Q32
void W25Q32_write(uint8_t* buffer, uint32_t addr, uint16_t numbyte);      // W25Q32 write data
void W25Q32_read(uint8_t* buffer,uint32_t read_addr,uint16_t read_length);// W25Q32 Read Data
#endif

SPI initialization has been configured in SYSCONFIG, but we still need to prepare SPI read/write steps. To ensure successful sending and receiving of data, when sending, you need to ensure the data in the sending buffer is sent, i.e., the sending buffer is empty, before sending the next data; when receiving, you need to ensure there is data in the receiving buffer before receiving.

bsp_spi.c (only partial excerpt shown here, see project source code for details)

xxxxxxxxxx
#include "bsp_spi.h"


uint8_t spi_read_write_byte(uint8_t dat)
{
        uint8_t data = 0;

        // Sending Data
        DL_SPI_transmitData8(SPI_INST,dat);
        // Wait for the SPI bus to be idle
        while(DL_SPI_isBusy(SPI_INST));
        // Receiving Data
        data = DL_SPI_receiveData8(SPI_INST);
        // Wait for the SPI bus to be idle
        while(DL_SPI_isBusy(SPI_INST));

        return data;
}
...

Then in the empty.c file, write the following code

xxxxxxxxxx
#include "ti_msp_dl_config.h"
#include "board.h"
#include "lcd_init.h"
#include "lcd.h"
#include "pic.h"
#include "bsp_spi.h"
#include <stdint.h>
#include <stdio.h>


int main(void)
{
    unsigned char buff[10] = {0};

    // Development board initialization
    board_init();

    delay_ms(100);// Waiting for deployment

    // Read the ID of W25Q32
    printf("ID = %X\r\n",W25Q32_readID());

    // Read 5 bytes of data from address 0 to buff
    W25Q32_read(buff, 0, 7);

    // Serial port outputs the read data
    printf("buff = %s\r\n",buff);

    // Write 5 bytes of data ABCD to address 0
    W25Q32_write("Yahboom", 0, 7);
    delay_ms(100);

    // Read 5 bytes of data from address 0 to buff
    W25Q32_read(buff, 0, 7);

    // Serial port outputs the read data
    //  printf("buff = %s\r\n",buff);

    SYSCFG_DL_init();

    LCD_Init();// LCD Initialization
    LCD_Fill(0,0,LCD_W,LCD_H,WHITE);
    LCD_ShowPicture(20,45,120,29,gImage_pic1);
    LCD_ShowString(10,0,"Hello!",BLACK,WHITE,16,0);
    LCD_ShowChinese(50,20,"亚博智能",BLACK,WHITE,16,0);

     // Display the contents of buff on the same line
    int x = 54;  // Starting x coordinate
    for (int i = 0; i < 7; i++)
        {
        char str[2] = {buff[i], '\0'};  // Take one character at a time
        LCD_ShowString(x, 35, str,BLACK, WHITE, 16, 0);  // Display Characters
        x += 8;  // Each character is 8 wide and has an x-coordinate offset to the right.
    }

    while (1)
    {

    }
}

6. Compile

image-20241127155238783

Compilation was successful. You can now download the program to the development board.

4. Program Analysis

  • lcd.c

image-20241128210926030

The LCD_ShowPicture function draws a picture at the specified starting point (x, y). It sets the display area according to the given length and width, and by iterating through the picture array, writes each pixel's color data to the LCD, completing the picture display.

image-20241128211007947

The LCD_ShowString function displays a string at the specified coordinates (x, y). It calls the LCD_ShowChar function to draw each character in the string, adjusting character spacing according to font size. It supports overlay and non-overlay display modes.

image-20241128211055384

The LCD_ShowChinese function displays Chinese character strings at the specified coordinates (x, y). It draws each Chinese character by calling the LCD_ShowChinese16x16 function, adjusting the next Chinese character's display position according to font size. It supports overlay and non-overlay display modes.

  • bsp_spi.c

image-20241130085215556

The W25Q32_read function reads data from the W25Q32 flash chip. The function first starts SPI communication by pulling the CS pin low, then sends the read command (0x03) and the high, middle, and low bytes of the read address. Then, according to the specified read length, it reads data byte by byte and stores it in the provided buffer (buffer). Finally, the function restores the CS pin to high level, ending the data transfer. This process ensures reading the specified length of data from the specified address.

image-20241130085328525

The W25Q32_write function writes data to the W25Q32 flash chip. First, the function erases the sector data at the target address. Then, it enables write operation and checks if the chip is busy. Next, the function sends the write command (0x02) and data address (24-bit address) to the chip through the SPI interface, and writes data byte by byte according to the specified write length. Finally, the function waits for the write operation to complete and restores the CS pin to high level, ensuring data is correctly written and the chip is in idle state.

  • empty.c

image-20241128210813735

The main function of this program is to initialize the development board, read and write data to the W25Q32 flash chip, and display the read content on LCD. First, the program initializes the development board and related hardware. Then, it reads the W25Q32 chip ID and outputs it through the serial port. Next, the program reads 7 bytes of data from the flash memory starting address (0 address) to the buff array and outputs this data through the serial port. Then, it writes the string "Yahboom" to flash address 0 and reads and displays the data again. Finally, the program initializes the LCD screen, displays welcome information and pictures, and displays the read buff data character by character on the same line on the screen.

5. Experimental Phenomena

After the program is downloaded, the LCD display screen will show "Hello!", "亚博智能", flash data, and the Yahboom logo on separate lines.

image-20241126182011363

Get MPU6050 data (I2C)
MSPM0 Robot Expansion Board Introduction

COMPANY

  • About us
  • Team Style
  • Blog

LEARNING & EXPLORATION

  • Tutorials
  • Edge AI hardware
  • Educational robots
  • Embedded intelligent hardware

WHERE TO BUY

  • Yahboom Online Store
  • Amazon
  • Alibaba
  • AliExpress
  • Mercado

TECHNOLOGY SUPPORT

  • Email: support@yahboom.com

BE A DISTRIBUTOR

  • Email: sales@yahboom.com
QR Code

Copyright © 2017-2026 Yahboom. All Rights Reserved.

EN/中文