2947 views|1 replies

6818

Posts

11

Resources
The OP
 

【GD32F310G-START】SPI driver ST7735 [Copy link]

【GD32F310G-START】HELLO WORLD - GD32 MCU - Electronic Engineering World - Forum (eeworld.com.cn)

【GD32F310G-START】OLED HELLO EEWORLD——Hardware I2C - GD32 MCU - Electronic Engineering World-Forum

After driving I2C, the next is SPI. This time the actual combat is the soft SPI driving screen ST7735. The main code is the transplantation of my previous practical st7735 code.

1. IO definition:

/*****************
 作  者  : 刘建华
 生成日期  : 2022-5-6
 最近修改  :
 功能描述  :GD32F320G SPI—7735
       说明:
       ----------------------------------------------------------------
       GND  电源地
       VCC  3.3v电源
       SCL  PA5(SCLK)
       SDA  PA7(MOSI)
       RES  PA1
       DC  PA2
       CS  PA4
       BLK  PA3
       ----------------------------------------------------------------
修改历史  :
日  期  : 2022-5-7
All rights reserved
******************************************************************************/

2. GPIO initialization:

/******************************************************************************
   函数说明:GPIO初始化
   入口数据:无
   返回值: 无
******************************************************************************/
void LCD_GPIO_Init(void)
{
 rcu_periph_clock_enable(RCU_GPIOA);
 gpio_mode_set(GPIOA, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE, GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_3 | GPIO_PIN_5 | GPIO_PIN_6 | GPIO_PIN_7 | GPIO_PIN_4);
 gpio_output_options_set(GPIOA, GPIO_OTYPE_PP, GPIO_OSPEED_50MHZ, GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_3 | GPIO_PIN_5 | GPIO_PIN_6 | GPIO_PIN_7 | GPIO_PIN_4);
 gpio_bit_set(GPIOA, GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_3 | GPIO_PIN_5 | GPIO_PIN_6 | GPIO_PIN_7 | GPIO_PIN_4);

}


3. Simulate SPI write data

/******************************************************************************
   函数说明:LCD串行数据写入函数
   入口数据:dat 要写入的串行数据
   返回值: 无
******************************************************************************/
void LCD_Writ_Bus(uint8_t dat)
{ 
 uint8_t i;
 LCD_CS_Clr();
 for(i=0;i<8;i++)
 {    
  LCD_SCLK_Clr();
  if(dat&0x80)
  {
    LCD_MOSI_Set();
  }
  else
  {
    LCD_MOSI_Clr();
  }
  LCD_SCLK_Set();
  dat<<=1;
 } 
 LCD_CS_Set(); 
}

4. Write one bit:

/******************************************************************************
   函数说明:LCD写入数据
   入口数据:dat 写入的数据
   返回值: 无
******************************************************************************/
void LCD_WR_DATA8(uint8_t dat)
{
 LCD_Writ_Bus(dat);
}

5. Write command:

/******************************************************************************
      函数说明:LCD写入命令
      入口数据:dat 写入的命令
      返回值:  无
******************************************************************************/
void LCD_WR_REG(uint8_t dat)
{
	LCD_DC_Clr();//写命令
	LCD_Writ_Bus(dat);
	LCD_DC_Set();//写数据
}

6. Macro definition:

#define SOFTWARE_SPI_ENABLE    1
	
#define LCD_RES_Clr()   gpio_bit_reset(GPIOA,GPIO_PIN_1)//RES  rst
#define LCD_RES_Set()  gpio_bit_set(GPIOA,GPIO_PIN_1)

#define LCD_DC_Clr()    gpio_bit_reset(GPIOA,GPIO_PIN_2)//DC  data command select
#define LCD_DC_Set()   gpio_bit_set(GPIOA,GPIO_PIN_2)
 		     
#define LCD_BLK_LOW()   gpio_bit_reset(GPIOA,GPIO_PIN_3)//BLK
#define LCD_BLK_Set()  gpio_bit_set(GPIOA,GPIO_PIN_3)

#define LCD_CS_Clr()    gpio_bit_reset(GPIOA,GPIO_PIN_4)//CS
#define LCD_CS_Set()   gpio_bit_set(GPIOA,GPIO_PIN_4)

#if SOFTWARE_SPI_ENABLE

#define LCD_SCLK_Clr()  gpio_bit_reset(GPIOA,GPIO_PIN_5)//SCL=SCLK
#define LCD_SCLK_Set() gpio_bit_set(GPIOA,GPIO_PIN_5)

#define LCD_MOSI_Clr()  gpio_bit_reset(GPIOA,GPIO_PIN_7)//SDA=MOSI
#define LCD_MOSI_Set() gpio_bit_set(GPIOA,GPIO_PIN_7)

#endif

I packaged the rest of the code into the attachment: ST7735.7z (11.02 KB, downloads: 16)




This post is from GD32 MCU

Latest reply

Thank you for sharing, the review is very careful.   Details Published on 2022-6-16 22:31
 

1w

Posts

204

Resources
2
 

Thank you for sharing, the review is very careful.

This post is from GD32 MCU
Add and join groups EEWorld service account EEWorld subscription account Automotive development circle
 
Personal signature

玩板看这里:

http://en.eeworld.com/bbs/elecplay.html

EEWorld测评频道众多好板等你来玩,还可以来频道许愿树许愿说说你想要玩的板子,我们都在努力为大家实现!

 
 

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