SPI driver OLED of STM32F103RCT6

Publisher:翩翩轻舞Latest update time:2018-10-08 Source: eefocusKeywords:STM32F103RCT6 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

Hardware conditions: Use Zhongjingyuan Electronics 0.96-inch OLED, 7 lines are as follows:

VCC-------->Power Supply

GND-------> Ground

D0--------->SCK, connected to SCK of SPI1, PA5

D1--------->MOSI, MCU as host output, OLED as slave receiver, connected to PA7

RST-------->Reset interface, very important, PC0

DC--------->Command or data control line, connected to PC1

CS---------->PC2 chip select

The above is the wiring of OLED and STM32103. You can also use other SPI interfaces. Here, as long as D0 and D1 correspond to the SPI interface, the other lines are customized and can be used as ordinary IO port outputs.

Correctly configure the following interfaces to light up the OLED:

1. SPI interface initialization:

SPI is also a type of serial port, which is similar to the USART configuration. It initializes IO port multiplexing and IO and SPI clocks. If interrupts are required, it is necessary to configure interrupt priority, write interrupt functions, etc.

The sending and receiving are the same as USART. The data is first sent/received to a DR buffer, and then waits for sending/receiving, and uses the flag bit of the SR register to determine whether to send/receive.

2. Reading, writing and initialization operations of OLED.

There are many OLED initialization operations on the Internet. When you buy it, you will definitely be given all the initialization command processes, so just write it out. However, there is one thing, during initialization, you need to pull RST low first, then hold it for 50ms, and then pull it high.

Then comes the write command and write data operation. Write data and write command are determined by DC, high level writes data, low level writes command. Note that you also need to pull down the CS chip select. Then write the data to the DR buffer via SPI. There is another point here, OLED can only be used as a slave, you can only write to OLED, not read.

3. There are two important points: the polarity of OLED's CPOL. The one I use is 0, which means a high level in idle state; and the clock phase, which should be sampled at the first transition edge.

Then comes the screen clearing operation, which is actually lighting up each pixel. Just write 0XFF for all. What needs to be noted here is that the commands for reading and writing coordinates are written correctly. The OLED coordinates are 0-7 in the vertical axis and 0-127 in the horizontal axis.

If all the above configurations are correct, then the OLED can be lit up, and the rest is to figure out how to display characters, etc. I have always believed that as long as the screen is lit up, the rest is a matter of thinking. As long as the point drawing function is written, the points form lines, and the lines form surfaces. That's the reason.


Keywords:STM32F103RCT6 Reference address:SPI driver OLED of STM32F103RCT6

Previous article:Keil compilation error about the use of __use_no_semihosting_swi
Next article:What can a microcontroller do?

Latest Microcontroller Articles
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号