5781 views|1 replies

6818

Posts

11

Resources
The OP
 

[Qinheng RISC-V core CH582] SPI driver ST7735 [Copy link]

 

[Qinheng RISC-V core CH582] I2C lights up the OLED screen - Domestic chip exchange - Electronic Engineering World - Forum (eeworld.com.cn)

After I2C driving the OLED screen, today we tested the hardware SPI0 driving the ST7735LCD screen.

1. The CH582 chip provides SPI0, and its features are as follows:

  • SPI0 supports master mode (Master) and slave mode (Slave).
  • Compatible with the Serial Peripheral Interface (SPI) specification.
  • Supports Mode 0 and Mode 3 data transmission methods.
  • 8-bit data transmission mode, data bit order can be selected: low byte first or high byte first.
  • The clock frequency can be up to half of the system main frequency Fsys.
  • 8-byte FIFO.
  • SPI0 slave mode supports first byte as command mode or data stream mode.
  • SPI0 supports DMA, which makes data transmission more efficient.

2. SPI initialization:

The IO of SPI0 are PA12 (NSS), PA13 (SCK), PA14 (MOSI). Today I will drive ST7735 and do not need to receive data, so PA15MISO does not need to be configured.

GPIOA_ModeCfg( GPIO_Pin_12 | GPIO_Pin_13 | GPIO_Pin_14, GPIO_ModeOut_PP_5mA );

SPI0_MasterDefInit();

3. Initially, the DC, RES, and BL corners of ST7735 are all configured to 20mA output mode:

GPIOA_ModeCfg(RES_PIN | DC_PIN | CS_PIN, GPIO_ModeOut_PP_20mA);

4. Define the high and low levels of DC, RES, and BL as follows:

#define RES_PIN  GPIO_Pin_0
#define DC_PIN   GPIO_Pin_1
#define BLK_PIN  GPIO_Pin_3
#define SCK_PIN  GPIO_Pin_13
#define MOSI_PIN GPIO_Pin_14
#define CS_PIN   GPIO_Pin_12
//-----------------LCD端口定义----------------

#define LCD_CS_Clr()   GPIOA_ResetBits(CS_PIN)//CS
#define LCD_CS_Set()   GPIOA_SetBits(CS_PIN)

#define LCD_RES_Clr()  GPIOA_ResetBits(RES_PIN)//RES
#define LCD_RES_Set()  GPIOA_SetBits(RES_PIN)

#define LCD_DC_Clr()   GPIOA_ResetBits(DC_PIN)//DC
#define LCD_DC_Set()   GPIOA_SetBits(DC_PIN)

#define LCD_BLK_Clr()  GPIOA_ResetBits(BLK_PIN)//BLK
#define LCD_BLK_Set()  GPIOA_SetBits(BLK_PIN)

After the above four steps, ST7735 hardware initialization is OK. Compared with STM32, its statement is concise. I transplanted ST7735 from N32G45 project in just a few steps and it took a few minutes to complete.

I put other ST7735 driver libraries in the attachment. Download the project, unzip it to the EXAM directory and you can test it directly.

main.c is:

/********************************** (C) COPYRIGHT *******************************
 * File Name          : Main.c
 * Author             : 刘建华
 * Version            : V1.0
 * Date               : 2022/02/27
 * Description        : 演示ST7735 硬件SPI驱动
 *******************************************************************************/

#include "CH58x_common.h"
#include "lcd_init.h"
#include "lcd.h"
__attribute__((aligned(4)))   UINT8 spiBuff[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6 };
__attribute__((aligned(4)))   UINT8 spiBuffrev[16];

void DebugInit( void )
{
  GPIOA_SetBits( GPIO_Pin_9 );
  GPIOA_ModeCfg( GPIO_Pin_8, GPIO_ModeIN_PU );
  GPIOA_ModeCfg( GPIO_Pin_9, GPIO_ModeOut_PP_5mA );
  UART1_DefInit();
}

int main()
{
  UINT8 i;

  SetSysClock( CLK_SOURCE_PLL_60MHz );

  /* 配置串口调试 */
  DebugInit();
  PRINT( "Start @ChipID=%02X\n", R8_CHIP_ID );

  LCD_Init();
  LCD_Fill(0,0,LCD_W,LCD_H,WHITE);
  LCD_ShowString(10,0,"CH582M",BLUE,WHITE,32,0);
  LCD_ShowString(16,36,"HELLO WORLD",RED,WHITE,16,0);
  LCD_ShowString(16,54,"ST7735",RED,WHITE,16,0);
  while( 1 )
    ;

}

SPI_ST7735.7z

192.87 KB, downloads: 93

This post is from Domestic Chip Exchange

Latest reply

Okay, thumbs up.   Details Published on 2022-2-27 12:16
 
 

2926

Posts

0

Resources
2
 

Okay, thumbs up.

This post is from Domestic Chip Exchange
 
 
 

Just looking around
Find a datasheet?

EEWorld Datasheet Technical Support

Featured Posts
Studying Things to Gain Knowledge 05: Dimensions and Elementary Functions

What is dimension? It is usually taught in middle school physics courses and again in university physics courses. Howev ...

【McQueen Trial】Comparison of the accuracy of several ultrasonic sensor programs of McQueen

Purpose Compare the test accuracy of several ultrasonic sensors to provide a reference for everyone's use. Methods Write ...

[Project source code] Digital tube companion - binary to BCD

This article and design code were written by FPGA enthusiast Xiao Meige. Without the author's permission, this article ...

Design of real-time image test device based on LVDS technology

Design of real-time image test device based on LVDS technology

C language uses binary tree to parse polynomials and evaluate

It mainly realizes the analysis of polynomial data calculation. If there is a need to make a simple calculator based on ...

LPS27HHTW MEMS Pressure Sensor

The LPS27HHTW MEMS pressure sensor is an ultra-compact piezoresistive absolute pressure sensor that can be used as a dig ...

Raspberry Pi Bluetooth Basics - Use of bluezero library

This post was last edited by lb8820265 on 2021-8-8 22:50 There are many libraries for operating Bluetooth in Linux s ...

CC2500 Migration Instructions

Be applicable : Applicable to TI chip CC2500 full series modules How to transplant ? The parts to be ported are in rf_ ...

Embedded Qt-Make a stopwatch

This post was last edited by DDZZ669 on 2022-8-7 15:55 Previous article: Embedded Qt - Write and run your first ARM-Qt ...

Successfully deployed deep learning gait recognition algorithm on Allwinner V853 platform

Xin Zhe, a student from the Communication Research Group of Beijing Institute of Technology, successfully transplanted t ...

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

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