3340 views|0 replies

274

Posts

8

Resources
The OP
 

[Qinheng RISC-V core CH582] 5-SPI drive OLED [Copy link]

 This post was last edited by manhuami2007 on 2022-3-13 20:20

The SPI provided by CH582 supports mode 0 and mode 3, can be configured as 3-wire or 2-wire mode, supports master and slave modes, and supports DMA. SPI also supports FIFO, which is equivalent to 8 data registers. When sending and receiving small amounts of data, even in polling mode, it can improve CPU efficiency. The official SPI library function is quite convenient to use.

The OLED used this time uses the SPI interface, and the pins are:

  • MOSI-PA14
  • CLK-PA13
  • CS-PA12
  • RES-PA3
  • DC-PA1

When porting the OLED driver, you only need to modify 3 functions:

  1. Initialization of peripherals
  2. Data Bytes Send
  3. Sending command byte

Initialization of peripherals

void oled_spi_init()
{
  GPIOA_SetBits( GPIO_Pin_12 );
  GPIOA_ModeCfg( GPIO_Pin_12 | GPIO_Pin_13 | GPIO_Pin_14, GPIO_ModeOut_PP_5mA );
  SPI0_MasterDefInit();

  GPIOA_ModeCfg(GPIO_Pin_1|GPIO_Pin_3,GPIO_ModeOut_PP_5mA);
  GPIOA_SetBits( GPIO_Pin_1 );
  GPIOA_SetBits( GPIO_Pin_3 );
}

Data and command bytes are sent

void OLED_WR_Byte(uint8_t dat,uint8_t cmd)
{
  uint8_t i;
  if(cmd)
    GPIOA_SetBits(OLED_DC_PIN);
  else
    GPIOA_ResetBits(OLED_DC_PIN);

  GPIOA_ResetBits(OLED_CS_PIN);
  SPI0_MasterSendByte( dat );
  GPIOA_SetBits(OLED_DC_PIN);
}

void OLED_Write_Multi_Data(uint8_t* data,uint16_t len)
{
  uint16_t i;
  GPIOA_SetBits(OLED_DC_PIN);
  GPIOA_ResetBits(OLED_CS_PIN);
  SPI0_MasterTrans( data, len );
  GPIOA_SetBits(OLED_CS_PIN);
}

void OLED_Write_Multi_Cmd(uint8_t* data,uint16_t len)
{
  uint16_t i;
  GPIOA_ResetBits(OLED_DC_PIN);
  GPIOA_ResetBits(OLED_CS_PIN);
  SPI0_MasterTrans( data, len );
  GPIOA_SetBits(OLED_CS_PIN);
  GPIOA_SetBits(OLED_DC_PIN);
}

display image

oled.c

31.98 KB, downloads: 13

oled.h

196 Bytes, downloads: 9

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

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