ℹ️ Document Conversion Notice: This page was converted from the original file for easier reading. Diagrams/images may appear only in the original PDF below.
Document preview
File info: application/pdf · 37 pages · 1.69MB

0.96inch OLED SPI Module MSP096X User Manual

Brand: LCDWIKI

Document ID: CR2019-MI4911

Version: Rev1.0

Introduction to OLED

OLED (Organic Light-Emitting Diode) display technology offers advantages such as self-illumination, wide viewing angles, nearly infinite contrast, low power consumption, high reaction speed, flexible panels, and a wide operating temperature range. It represents an emerging flat panel display technology.

Unlike traditional LCD displays, OLED displays do not require a backlight as they self-illuminate, resulting in thinner displays with superior visual quality.

Product Description

The OLED module features a 0.96-inch display with a 128x64 resolution. It supports three-wire, four-wire SPI, and IIC communication modes, utilizing the SSD1306 driver IC. Modules are available in black, blue, or yellow and blue color combinations.

Product Features

  • 0.96-inch OLED screen with black and white, black or blue, or yellow and blue color display options.
  • 128x64 resolution for clear display and high contrast.
  • Wide viewing angle: greater than 160°, offering one of the widest viewing angles in display technology.
  • Wide voltage supply (3V~5V), compatible with 3.3V and 5V logic levels, eliminating the need for a level shifting chip.
  • Default 4-wire SPI bus, with options for 3-wire or IIC bus.
  • Ultra-low power consumption: normal display consumes only 0.06W, significantly less than TFT displays.
  • Manufactured to military-grade process standards for long-term stable operation.
  • Provides sample programs for STM32, C51, Arduino, Raspberry Pi, and MSP430 platforms.
  • Offers underlying driver technical support.

Product Parameters

Name Description
Display Color White, blue, yellow and blue
SKU MSP096B
MSP096W
MSP096Y
Screen Size 0.96(inch)
Type OLED
Driver IC SSD1306
Resolution 128*64(Pixel)
Module Interface 3-line, 4-line SPI, IIC interface
Active Area 21.744x10.864 (mm)
Touch Screen Type have no touch screen
Touch IC have no touch IC
Module PCB Size 27.3x27.8 (mm)
Angle of view >160°
Operating Temperature -20°C~60°C
Storage Temperature -30°C~70°C
Operating Voltage 3.3V/5V
Power Consumption TBD
Product Weight(With packaging) 8(g)

Interface Description

The module features pins for GND, VCC, DO, DI, RES, DC, and CS. The image 'Picture1. Module pin Label picture' shows these labels printed on the PCB near the corresponding pins.

Interface Configuration and Notes

The rear view of the module ('Picture 2. Rear view of the module') shows resistors R1 through R8. These resistors are used to configure the interface mode:

  • IIC: Requires R1, R4, R6, R7, R8.
  • 3-SPI: Requires R2, R3.
  • 4-SPI: Requires R3, R4.

NOTE:

  1. This module supports IIC, 3-wire SPI, and 4-wire SPI interface bus modes. The specific configuration is as follows:
    • A. 4-wire SPI (default): Solder 4.7K resistance to R3 and R4 only.
    • B. 3-wire SPI: Solder 4.7K resistance to R2 and R3 only.
    • C. IIC: Solder 4.7K resistance to R1, R4, R6, R7, and R8 only.
  2. After switching the interface bus mode, select the corresponding software and wiring pins for normal operation.

Important:

  1. Pin numbers 1-7 refer to the module's pin numbers on the PCB. For bare screens, refer to the bare screen specification for pin definitions. Wiring should follow the signal type, not just the pin number.
  2. The OLED display module can be connected to 3.3V or 5V power supply (VCC).

Pin Description Table:

Number Module Pin Pin Description
1 GND OLED power ground
2 VCC OLED power positive (3.3V~5V)
3 D0 OLED SPI and IIC bus clock signals
4 D1 OLED SPI and IIC bus data signals
5 RES OLED reset signal, low level reset (connect to high level, e.g., VCC, when selecting IIC bus)
6 DC OLED command / data input select signal; high level for data, low level for command (not required/connectable when selecting 3-wire SPI; connect to GND when selecting IIC bus)
7 CS OLED chip select signal, low level enable (connect to GND when selecting IIC bus)

Hardware Configuration

The OLED module does not have a backlight control circuit due to its self-illuminating nature. It features an OLED display control circuit and a bus mode switching control circuit. The display control circuit manages chip selection, reset, and data/command transmission. The bus mode switching circuit selects between 3-wire SPI, 4-wire SPI, and IIC modes. The module defaults to 4-wire SPI and is configured with 7 pins, with different pins used depending on the selected communication method.

Working Principle

1. Introduction to SSD1306 Controller

The SSD1306 is an OLED/PLED controller supporting a maximum resolution of 128x64 pixels and 1024 bytes of GRAM. It supports 8-bit 6800 and 8-bit 8080 parallel interfaces, as well as 3-wire and 4-wire SPI serial and I2C buses. Due to the high IO port requirement of parallel control, SPI and I2C are more commonly used. It supports vertical scrolling and is suitable for small portable devices like mobile phones and MP3 players. The SSD1306 controller uses 1 bit per pixel, allowing each pixel to display black or white, or black and blue. The display RAM is divided into 8 pages, with 8 lines per page and 128 pixels per line. Pixel data is set by specifying page address, column low address, and column height address. Software first maps pixel data to a global array, then ORs or operates it for writing to GRAM, ensuring data integrity before display.

2. Introduction to SPI Communication Protocol

The document describes SPI communication protocols with timing diagrams. The 4-wire SPI bus write mode timing shows signals CS#, D/C#, SDIN/SCLK, and SCLK. The 3-wire SPI bus write mode timing shows CS#, SDIN/SCLK, SCLK, and D/C# (integrated into SDIN). The key difference is that the 3-wire SPI lacks a dedicated D/C# signal; this function is multiplexed with the SDIN line, requiring an initial bit to indicate command or data. CS# is the chip select signal, active low. D/C# (or its equivalent in 3-wire SPI) controls data/command. SCLK is the clock, and SDIN is the data line. SPI communication involves clock polarity (CPOL) and clock phase (CPHA). SPI mode 0 (CPHA=0, CPOL=0) is commonly used.

Instructions for Use

Arduino Instructions

Wiring Instructions:

Refer to the interface description for pin assignments. The following tables show wiring for Arduino UNO and MEGA2560:

Arduino UNO microcontroller test program wiring instructions
Number Module Pin Corresponding to UNO development board wiring pins
1 GND GND
2 VCC 5V/3.3V
3 D0 13
4 D1 11
5 RES A4
6 DC A3
7 CS A5
Arduino MEGA2560 microcontroller test program wiring instructions
Number Module Pin Corresponding to MEGA2560 development board wiring pins
1 GND GND
2 VCC 5V/3.3V
3 D0 53
4 D1 51
5 RES A4
6 DC A3
7 CS A5

Operating Steps:

  1. Connect the OLED module and the Arduino MCU according to the wiring instructions and power on.
  2. Select the desired test program. Refer to the test program description document for details. The document shows a file explorer view with various test program folders (e.g., 0.96inch_OLED_Demo_Mega2560_Hardware_4-wire_SPI) and documentation files (e.g., 0.96inch_OLED_SPI_Arduino_Demo_Instructions_EN.pdf).
  3. Open the selected sample project, compile, and download. Specific operation methods for library-based programs can be found at: http://www.lcdwiki.com/res/PublicFile/Arduino IDE Use Illustration EN.pdf
  4. If the OLED module displays characters and graphics correctly, the program has run successfully.

RaspberryPi Instructions

Wiring Instructions:

Refer to the interface description for pin assignments. Note the different pin coding schemes: Physical pin, BCM encoding, and WiringPi coding. The correct scheme must be used based on the library in the code. A GPIO map table is provided for reference.

wiringPi 编码 BCM 编码 功能名 物理引脚 BOARD编码 功能名 BCM 编码 wiringPi 编码
3.3V 1 2 5V
8 2 SDA.1 3 4 5V
9 3 SCL.1 5 6 GND
7 4 GPIO.7 7 8 TXD 14 15
GND 9 10 RXD 15 16
0 17 GPIO.0 11 12 GPIO.1 18 1
2 27 GPIO.2 13 14 GND
3 22 GPIO.3 15 16 GPIO.4 23 4
3.3V 17 18 GPIO.5 24 5
12 10 MOSI 19 20 GND
13 9 MISO 21 22 GPIO.6 25 6
14 11 SCLK 23 24 CEO 8 10
GND 25 26 CE1 7 11
30 0 SDA.0 27 28 SCL.0 1 31
21 5 GPIO.21 29 30 GND
22 6 GPIO.22 31 32 GPIO.26 12 26
23 13 GPIO.23 33 34 GND
24 19 GPIO.24 35 36 GPIO.27 16 27
25 26 GPIO.25 37 38 GPIO.28 20 28
GND 39 40 GPIO.29 21 29
Raspberry Pi test program wiring instructions
Number Module Pin Corresponding to development board wiring pin
1 GND GND
(Physical pin: 6,9,14,20,25,30,34,39)
2 VCC 5V/3.3V
(Physical pin: 1,2,4)
3 D0 Physical pin: 23
BCM coding: 11
wiringPi coding: 14
4 D1 Physical pin: 19
BCM coding: 10
wiringPi coding: 12
5 RES Physical pin: 5
6 DC BCM coding: 3
wiringPi coding: 9
Physical pin: 3
7 CS BCM coding: 2
wiringPi coding: 8
Physical pin: 24

Operating Steps:

  1. Enable the SPI function on Raspberry Pi using sudo raspi-config, selecting Interfacing Options -> SPI -> YES. Start the SPI kernel driver.
  2. Install necessary libraries (bcm2835, wiringPi, python). Detailed methods are available at: http://www.lcdwiki.com/res/PublicFile/Raspberrypi Use Illustration EN.pdf
  3. Select the test example. The document shows a file explorer view with various test program folders (e.g., 0.96inch_OLED_Demo_bcm2835_Hardware_4-wire_SPI) and documentation files.
  4. bcm2835 instructions (4-wire hardware SPI):
    a) Connect the module to the Raspberry Pi.
    b) Copy the test program directory (e.g., 0.96inch_OLED_Demo_bcm2835_Hardware_4-wire_SPI) to the Raspberry Pi.
    c) Navigate to the directory and run make, then execute sudo ./0.96_SPI_OLED. A command-line output example is provided.
  5. wiringPi instructions (4-wire hardware SPI):
    a) Connect the module.
    b) Copy the test program directory (e.g., 0.96inch_OLED_Demo_wiringPi_Hardware_4-wire_SPI).
    c) Navigate to the directory and run make, then execute sudo ./0.96_SPI_OLED.
  6. python instructions (4-wire hardware SPI):
    a) Install the PIL image processing library. Installation guide: http://www.lcdwiki.com/res/PublicFile/Python Image Library Install Illustration EN.pdf
    b) Connect the module.
    c) Copy the test program directory (e.g., 0.96inch_OLED_Demo_python_Hardware_4-wire_SPI).
    d) Navigate to the source subdirectory and run the test programs: sudo python show_graph.py, sudo python show_char.py, sudo python show_bmp.py. Command-line output examples are provided.

STM32 Instructions

Wiring Instructions:

Wiring instructions for various STM32 development boards are provided in the following tables:

STM32F103RCT6 microcontroller test program wiring instructions
Number Module Pin Corresponding to MiniSTM32 development board wiring pin
1 GND GND
2 VCC 3.3V/5V
3 D0 PB13
4 D1 PB15
5 RES PB12
6 DC PB10
7 CS PB11
STM32F103ZET6 microcontroller test program wiring instructions
Number Module Pin Corresponding to Elite STM32 development board wiring pin
1 GND GND
2 VCC 3.3V/5V
3 D0 PB13
4 D1 PB15
5 RES PB12
6 DC PB10
7 CS PB11
Explorer STM32F4 development board wiring pin
Number Module Pin Corresponding to Explorer STM32F4 development board wiring pin
1 GND GND
2 VCC 3.3V/5V
3 D0 PB3
4 D1 PB5
5 RES PB12
6 DC PB14
7 CS PB15
STM32F429IGT6 microcontroller test program wiring instructions
Number Module Pin Corresponding to Apollo STM32F4/F7 development board wiring pin
1 GND GND
2 VCC 3.3V/5V
3 D0 PF7
4 D1 PF9
5 RES PD12
6 DC PD5
7 CS PD11
STM32F767IGT6 and STM32H743IIT6 microcontroller test program wiring instructions
Number Module Pin Corresponding to Apollo STM32F4/F7 development board wiring pin
1 GND GND
2 VCC 3.3V/5V
3 D0 PB13
4 D1 PB15
5 RES PD12
6 DC PD5
7 CS PD11

Operating Steps:

  1. Connect the module and the STM32 MCU according to the wiring instructions and power on.
  2. Select the test example based on the microcontroller model. The document shows a file explorer view with various test program folders (e.g., 0.96inch_OLED_Demo_STM32F103RCT6_Hardware_3-wire_SPI) and documentation files.
  3. Open the selected test program project, compile, and download. Detailed descriptions are available at: http://www.lcdwiki.com/res/PublicFile/STM32 Keil Use Illustration EN.pdf
  4. If the OLED module displays characters and graphics normally, the program runs successfully.

C51 Instructions

Wiring Instructions:

Wiring instructions for STC89C52RC and STC12C5A60S2 microcontrollers:

Number Module Pin Corresponding to STC89/STC12 development board wiring pin
1 GND GND
2 VCC 3.3V/5V
3 D0 P17
4 D1 P15
5 RES P33
6 DC P12
7 CS P13

Operating Steps:

  1. Connect the module and the C51 MCU according to the wiring instructions and power on.
  2. Select the C51 test program to be tested. Refer to the test program description document for details. The document shows a file explorer view with various test program folders (e.g., 0.96inch_OLED_Demo_STC12C5A60S2_Hardware_3-wire_SPI) and documentation files.
  3. Open the selected test program project, compile, and download. Detailed descriptions are available at: http://www.lcdwiki.com/res/PublicFile/C51 Keil%26stc-isp Use Illustration EN.pdf
  4. If the OLED module displays characters and graphics normally, the program runs successfully.

MSP430 Instructions

Wiring Instructions:

Wiring instructions for MSP430F149 microcontrollers:

Number Module Pin Corresponding to MSP430 development board wiring pin
1 GND GND
2 VCC 3.3V/5V
3 D0 P33
4 D1 P31
5 RES P22
6 DC P21
7 CS P20

Operating Steps:

  1. Connect the module and the MSP430 MCU according to the wiring instructions and power on.
  2. Select the MSP430 test program to be tested. Refer to the test program description document for details. The document shows a file explorer view with various test program folders (e.g., 0.96inch_OLED_Demo_MSP430F149_Hardware_3-wire_SPI) and documentation files.
  3. Open the selected test program project, compile, and download. Detailed descriptions are available at: http://www.lcdwiki.com/res/PublicFile/IAR IDE%26MspFet Use Illustration EN.pdf
  4. If the module displays characters and graphics normally, the program runs successfully.

Software Description

1. Code Architecture

A. Arduino code architecture description

The Arduino test program code consists of two main parts: the LCDWIKI library and application code. The LCDWIKI library is further divided into LCDWIKI_SPI (underlying library for hardware interaction) and LCDWIKI_GUI (middle-tier library for graphics and text). The application contains test examples that utilize these libraries. The LCDWIKI_SPI library handles hardware initialization, data/command transmission, and display settings. The LCDWIKI_GUI library provides APIs for drawing graphics and characters. The application code uses these APIs to create test examples.

B. RaspberryPi code architecture description

The Python test program code architecture includes the PIL image processing library, OLED initialization code, and test sample code. The PIL library is responsible for image drawing and character display. The OLED initialization code manages registers, hardware initialization, data transfer, and display configuration. The test example code uses APIs from these components to implement test functions. For bcm2835 and wiringPi, the architecture includes test code, GUI code, OLED code, main, and platform code, with SPI and GPIO libraries providing specific functionalities.

C. C51, STM32 and MSP430 code architecture description

The code architecture for C51, STM32, and MSP430 platforms typically includes test code, GUI code, LCD code, main, and platform code, with SPI code handling SPI communication and GPIO libraries managing GPIO operations. The Demo API code is part of the main runtime, OLED initialization is in the OLED code, and graphics/character display functions are in the GUI code. Platform-specific code varies.

2. Software SPI and Hardware SPI description

The module provides sample code for both software SPI and hardware SPI (except for STC89C52RC which lacks hardware SPI). While display content is the same, differences exist in:

  • Display Speed: Hardware SPI is significantly faster.
  • GPIO Definition: Software SPI allows flexible pin definition, while hardware SPI has fixed data and clock pins (platform-dependent), with other control pins being definable.
  • Initialization: Software SPI requires GPIO initialization. Hardware SPI requires initialization of control and data registers.

3. GPIO definition description

A. Arduino test program GPIO definition description

In Arduino, GPIO definitions are typically in application examples. For 4-wire software SPI, pins like CS, DC, D1, D0, RES, and LED can be defined and modified. If hardware SPI is used, D0 and D1 are fixed and cannot be modified. For 3-wire SPI, DC does not need to be defined.

//paramters define
#define MODEL SSD1306
#define CS A5
#define DC A3
#define D1 11
#define D0 13
#define RES A4
#define LED -1 //if you don't need to control

B. RaspberryPi test program GPIO definition description

Raspberry Pi uses hardware SPI. GPIO definitions are often in an oled.h file for bcm2835 and WiringPi, specifying OLED_CS, OLED_DC, and OLED_RST. Python test programs define GPIOs within each example. For example:

#RaspberryPi pin configuration:
DC=2
RES=3
CS=8

These can be modified according to the GPIO library. For 3-wire SPI, OLED_DC may not need definition.

C. STM32 test program GPIO definition description

STM32 GPIO definitions are split into control GPIO (in oled.h) and SPI GPIO (in spi.h). For software SPI, pins are modifiable. For hardware SPI, OLED_MOSI and OLED_CLK are fixed. For 3-wire SPI, OLED_DC is not needed. GPIO initialization is done via OLED_Init_GPIO.

//--- OLED端口定义 --
#define OLED_CS GPIO Pin 11 //片选信号 PB11
#define OLED_DC GPIO Pin 10 //数据/命令控制信号 PB10
#define OLED_RST GPIO Pin 12 //复位信号 PB12

//--- SPI总线引脚定义 --
#define OLED_MOSI GPIO Pin 15 //OLED屏SPI写数据信号
#define OLED_CLK GPIO Pin 13 //OLED屏SPI时钟信号

D. C51 test program GPIO definition description

C51 GPIO definitions are also split into control and SPI definitions, placed in oled.h and spi.h respectively. For software SPI, pins are modifiable. For hardware SPI, OLED_MOSI and OLED_CLK are fixed (STC12C5A60S2 has hardware SPI). For 3-wire SPI, OLED_DC is not needed.

//--- OLED端口定义 --
sbit OLED_CS = P1^3; //片选信号 P13
sbit OLED_DC = P1^2; //数据/命令控制信号 P12
sbit OLED_RST = P3^3; //复位信号 P33

//SPI的致估分解能人们的切碎化入卻可以壮起修以
sbit OLED_MOSI = P1^5; //OLED屏SPI写数据引脚 P15
sbit OLED_CLK = P1^7; //OLED屏SPI时钟引脚 P17

E. MSP430 test program GPIO definition description

MSP430's LCD non-SPI GPIO definition is in lcd.h. For software SPI, pins are modifiable. For 3-wire SPI, OLED_DC is not needed. The SPI GPIO definition is in spi.h.

//-- OLED端口定义 --
#define OLED_CS BIT0 //片选信号 P20
#define OLED_DC BIT1 //数据/命令控制信号 P21
#define OLED_RST BIT2 //复位信号 P22

//本测试程序使用的是软件SPI接口驱动
//SPI时钟信号以及SPI读、写信号引脚都可以更改
#define SPI_SCLK BIT3 //P33
#define SPI_MOSI BIT1 //P31

4. SPI communication code implementation

A. Arduino test program SPI communication code implementation

SPI communication is implemented in the LCDWIKI_SPI library. The 4-wire SPI implementation (software and hardware) is shown below:

//spi write for hardware and software
void LCDWIKI_SPI:: Spi_Write(uint8_t data)
{
  if(hw_spi)
  {
    SPI.transfer(data);
  }
  else
  {
    uint8_t val = 0x80;
    while(val)
    {
      if(data&val)
      {
        MOSI_HIGH;
      }
      else
      {
        MOSI_LOW;
      }
      CLK_LOW;
      CLK_HIGH;
      val >>= 1;
    }
  }
} << end Spi_Write >>

The 3-wire SPI implementation is shown below:

void LCDWIKI_SPI:: Spi_3_wire_Write(uint8_t data, uint8_t cmd)
{
  uint16_t txdata = 0;
  txdata = ((cmd<<15)|(data<<7));
  SPI.transfer16(txdata);
  if(hw_spi)
  {
  }
  else
  {
    uint16_t val = 0x8000;
    while(val>(1<<6))
    {
      if(txdata&val)
      {
        MOSI_HIGH;
      }
      else
      {
        MOSI_LOW;
      }
      CLK_LOW;
      CLK_HIGH;
      val >>= 1;
    }
  }
} << end Spi_3_wire_Write >>

A flag bit determines whether to use software or hardware SPI.

B. RaspberryPi test program SPI communication code implementation

SPI communication for bcm2835 and wiringPi test programs is implemented in spi.c. Python communication is in oled.py.

bcm2835 4-wire hardware SPI:

/******
* @name :void SPI_WriteByte(uint8_t byte)
* @date :2018-08-27
* @function :Write a byte of data using RaspberryPi hardware SPI
* @parameters: Byte: Data to be written
* @retvalue : Data received by the bus
****/ void SPI_WriteByte(uint8_t byte)
{
  bcm2835_spi_transfer(byte);
}

bcm2835 3-wire hardware SPI:

/****
* @name :void SPI_WriteByte (uint8_t byte, uint8_t cmd)
* @date :2018-08-27
* @function :Write a byte of data using RaspberryPi hardware SPI
* @parameters: Byte: Data to be written
cmd:0-command
1-data
* @retvalue : Data received by the bus
void SPI_WriteByte(uint8_t byte, uint8_t cmd)
{
  uint16_t data=0;
  char txbuf[2]={0};
  data=((cmd<<15)|(byte<<7));
  txbuf[0]=(char) (data>>8);
  txbuf[1]=(char) (data&0xFF);
  bcm2835_spi_transfern (txbuf,2);
}******
****/

wiringPi 4-wire hardware SPI:

* @name :void SPI_WriteByte(uint8_t byte)
* @date :2018-08-27
* @function :Write a byte of data using RaspberryPi hardware SPI
* @parameters: Byte: Data to be written
* @retvalue : Data received by the bus
****/ void SPI_WriteByte(uint8_t byte)
{
  wiringPiSPIDataRW(CHANNEL, &byte, 1);
}

Python 4-wire hardware SPI:

def writebyte (self,val,flag):
  """send one byte data to oled module"""
  if flag == OLED_COMMAND:
    GPIO.output(self.oleddc,GPIO.LOW)
  else:
    GPIO.output(self.oleddc,GPIO.HIGH)
  GPIO.output(self.oledcs,GPIO.LOW)
  self.oledspi.writebytes([val])
  self.oledspi.xfer((val),8000000)
  GPIO.output(self.oledcs,GPIO.HIGH)

Python 3-wire hardware SPI:

def writebyte (self,val,flag):
  """send two byte data to oled module"""
  data=((flag<<15)|(val<<7))
  txbuf=[(data>>8) &0xFF, data&0xFF]
  GPIO.output(self.oledcs,GPIO.LOW)
  self.oledspi.writebytes (txbuf)
  self.oledspi.xfer(txbuf, 8000000)
  GPIO.output(self.oledcs, GPIO.HIGH)

C. STM32 test program SPI communication code implementation

SPI communication is implemented in spi.c. The 4-wire SPI implementation is as follows:

Software SPI:

/**
* @name :void SPI WriteByte (u8 Data)
* @date :2018-08-27
* @function :Write a byte of data using STM32's Software SPI
* @parameters : Data:Data to be written
* @retvalue : None
**********************
*/
void SPI WriteByte (u8 Data)
{
  unsigned char i=0;
  {
    for(i=8;i>0;i--)
      if(Data&0x80)
      {
        OLED_MOSI_SET(); //写数据1
      }
      else
      {
        OLED_MOSI_CLR(); //写数据0
      }
      OLED_CLK_CLR();
      OLED_CLK_SET(); //发送1bit数据
      Data<<=1;
  }
}

Hardware SPI:

/**
* @name :u8 SPI WriteByte (SPI TypeDef* SPIx, u8 Byte)
* @date :2018-08-27
* @function :Write a byte of data using STM32's hardware SPI
* @parameters : SPIX: SPI type,x for 1,2,3
Byte: Data to be written
* @retvalue :Data received by the bus
****
*/
u8 SPI_WriteByte(SPI_TypeDef* SPIx,u8 Byte)
{
  //等待发送区空
  while((SPIx->SR&SPI_I2S_FLAG_TXE)==RESET);
  SPIx->DR=Byte; //发送一个byte
  //等待接收完一个byte
  while((SPIx->SR&SPI_I2S_FLAG_RXNE)==RESET);
  return SPIX->DR;
  //返回收到的数据
}

The 3-wire SPI implementation is as follows:

Software SPI:

* @name :void SPI WriteByte (u8 data, u8 Cmd)
* @date :2018-08-27
* @function :Write a byte of data using STM32's Software SPI
* @parameters : Data: Data to be written
Cmd:0-command
1-data
* @retvalue :None
**********************
*/
void SPI_WriteByte (u8 data,u8 Cmd)
{
  unsigned char i=0;
  u16 Data;
  Data = ((Cmd<<15) | (data<<7));
  for(i=9;i>0;i--)
  {
    if (Data&0x8000)
    {
      OLED_MOSI_SET(); //写数据1
    }
    else
    {
      OLED_MOSI_CLR(); //写数据0
    }
    OLED_CLK_CLR();
    OLED_CLK_SET(); //发送1bit数据
    Data<<=1;
  }
}

Hardware SPI:

/**
* @name :u8 SPI WriteByte (SPI TypeDef* SPIx, u8 Byte, u8 cmd)
* @date :2018-08-27
* @function :Write a byte of data using STM32's hardware SPI
* @parameters : SPIX: SPI type,x for 1,2,3
Byte: Data to be written
cmd:0-write command
1-write data
* @retvalue :Data received by the bus
***************************************
*/
u8 SPI WriteByte (SPI TypeDef* SPIx,u8 Byte,u8 cmd)
{
  //等待发送区空
  while((SPIX->SR&SPI_I2S_FLAG_TXE)==RESET);
  SPIX->DR=((cmd<<15)|(Byte<<7)); //发送两个byte
  //等待接收完两个byte
  while((SPIx->SR&SPI_I2S_FLAG_RXNE)==RESET);
  return SPIX->DR;
  //返回收到的数据
}

D. C51 test program SPI communication code implementation

SPI communication is implemented in spi.c. The 4-wire SPI implementation is as follows:

Software SPI:

* @name :void SPI WriteByte (u8 byte)
* @date :2018-08-09
* @function :Write a byte of data using C
* @parameters :byte:Data to be written
* @retvalue : None
********************
*/
void SPI WriteByte (u8 byte)
{
  u8 i;
  {
    for(i=0;i<8;i++)
      if (byte&0x80)
      {
        OLED_MOSI_Set();
      }
      else
      {
        OLED_MOSI_Clr();
      }
      OLED_CLK_Clr();
      OLED_CLK_Set();
      byte<<=1;
  }
}

Hardware SPI:

/**
* @name :void SPI WriteByte(u8 byte)
* @date :2018-08-09
* @function :Write a byte of data using C51's Hardware SPI
* @parameters :byte:Data to be written
* @retvalue : None
****************
*/
void SPI WriteByte (u8 byte)
{
  SPDAT = byte;
  while((SPSTAT & SPIF)==0); //等待发送完成
  SPSTAT = SPIF+WCOL; //清0 SPIF和WCOL标志
  //发送一个字节
}

The 3-wire SPI implementation is as follows:

Software SPI:

* @name :void SPI WriteByte (u8 byte, u8 cmd)
* @date :2018-08-09
* @function :Write a byte of data using C51's so
* @parameters : byte: Data to be written
cmd:0-command
1-data
* @retvalue :None
***
*/
void SPI_WriteByte (u8 byte, u8 cmd)
{
  u8 i;
  u16 Data=0;
  Data=((cmd<<15)|(byte<<7));
  for(i=0;i<9;i++)
  {
    if (Data&0x8000)
    {
      OLED_MOSI_Set();
    }
    else
    {
      OLED_MOSI_Clr();
    }
    OLED_CLK_Clr();
    OLED_CLK_Set();
    Data<<=1;
  }
}

Hardware SPI:

* @name :void SPI WriteByte(u8 byte, u8 cmd)
* @date :2018-08-09
* @function :Write a byte of data using C51's Hardware SPI
* @parameters : byte: Data to be written
cmd:0-command
1-data
* @retvalue :None
void SPI_WriteByte(u8 byte, u8 cmd)
{
  u8 i=0;
  u16 Data=0;
  Data=((cmd<<15)|(byte<<7));
  for(i=2;i>0;i--)
  {
    SPDAT = (Data>>((i-1)*8));
    //发送一个字节
    while((SPSTAT & SPIF)==0); //等待发送完成
    SPSTAT = SPIF+WCOL;
  }
} //清0 SPIF和WCOL标志

E. MSP430 test program SPI communication code implementation

Software SPI communication is implemented in spi.c. The 4-wire SPI implementation is as follows:

Software SPI:

******
* @name :void SPI WriteByte (u8 Data)
* @date :2018-08-09
* @function :Write a byte of data using STM32's hardvare SPI
* @parameters :SPIx: SPI type,x for 1,2,3
Byte:Data to be written
* @retvalue :Data received by the bus
*******
*/
void SPI_WriteByte (u8 Data)
{
  unsigned char i=0;
  for(i=8;i>0;i--)
  {
    if (Data&0x80)
      SPI_MOSI_SET; //输出数据
    else SPI_MOSI_CLR;
    SPI_SCLK_CLR;
    SPI_SCLK_SET;
    Data<<=1;
  }
}
********
******************
******************/

Hardware SPI:

* @name :u8 SPI_WriteByte (SPI_TypeDef* SPIx,u8 Byte)
* @date :2018-08-09
* @function :Write a byte of data using STM32's hardware SPI
* @parameters : SPIx: SPI type,x for 1,2,3
Byte: Data to be written
* @retvalue :Data received by the bus
u8 SPI_WriteByte (u8 Byte)
{
  while ((IFG1&UTXIFGO) ==0); // wait while not ready / for RX
  UOTXBUF = Byte;
  while ((IFG1&URXIFGO)==0); // wait for RX buffer (full)
  return (UORXBUF);
}

The 3-wire SPI communication code is implemented in spi.c.

Software SPI:

/**
* @name :void OLED WR Byte (unsigned dat, unsigned cmd)
* @date :2018-08-27
* @function :Write a byte of content to the OLED screen
* @parameters:dat:Content to be written
cmd:0-vrite command
1-data
*/
void OLED_WR_Byte (unsigned dat, unsigned cmd)
{
  u16 data=0;
  data=((cmd<<15) | (dat<<7));
  OLED_CS_Clr;
  SPI_WriteByte ((data>>8)&0xFF);
  SPI_WriteByte (data&0xFF);
  OLED_CS_Set;
}

Hardware SPI:

* @name :void SPI WriteByte (u8 val, u8 cmd)
* @date :2018-08-27
* @function :Write a byte of data using STM32's hardware SPI
* @parameters : val: Data to be written
cmd:0-command
1-data
* @retvalue :None
*/
void SPI_WriteByte (u8 val, u8 cmd)
{
  unsigned char i=0;
  u16 Data=0;
  Data = ((cmd<<15) | (val<<7));
  for(i=9;i>0;i--)
  {
    if (Data&0x8000)
      SPI_MOSI_SET; //输出数据
    else
      SPI_MOSI_CLR;
    SPI_SCLK_CLR;
    SPI_SCLK_SET;
    Data<<=1;
  }
}

Common Software

This section covers test examples for displaying Chinese, English, symbols, and pictures using the PCtoLCD2002 modulo software. The settings explained are specific to the test program.

PCtoLCD2002 Modulo Software Settings:

  • Dot matrix format: Select Dark code.
  • Modulo mode: Select progressive mode (determinant for C51 and MSP430 test programs).
  • Direction: Choose high position first (for C51 and MSP430 test programs, reverse/low position first is needed).
  • Output number system: Select hexadecimal number.
  • Custom format selection: C51 format.

For specific setting methods, refer to: http://www.lcdwiki.com/Chinese and English display modulo settings

www.lcdwiki.com

Original Document

If the viewer doesn’t load, open the PDF directly.