STC8 MCU OLED is driven by SPI hardware interrupt (middle)

Publisher:天涯拾遗Latest update time:2022-08-05 Source: csdn Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

We have already talked about how to initialize SPI. Next, let's talk about the sending function. First, the code


void OLED_Writ_Bus(uint8_t _data)

{

Delay20us();

if (SPI_Busy == 0)

{

SPI_Busy = 1;

OLED_CS_Clr();

SPDAT = _data;

}

 

}


SPI_Busy is a state machine that determines whether SPI is busy. In the OLED routine, software simulates SPI. The simulated clock cannot keep up with the speed of the hardware, so we only need to change the software simulation to the hardware driver. Let's see the speed difference between the two. The software simulation is about 400k, the hardware driver (interrupt) can reach about 3M, and the polling is about 1M. Pulling down the CS (SS) pin can select the slave. A small delay is added here, otherwise the OLED will display garbled characters. You can try to use the scheduler to adjust this problem (will be discussed in future articles)


So when the host sends, it needs to pull down the SS pin, and then write the data into the SPDAT register. In fact, it is a shift register, which is why the SPI transmission rate is relatively high.


The interrupt mode must have interrupt. The interrupt number of SPI1 is 9. Next, let's see how to handle the interrupt.


void SPI_Isr() interrupt 9

{

  SPSTAT = 0XC0; // Clear the interrupt flag

SPI_Busy = 0; // Clear SPI busy status bit

OLED_CS_Set(); //Pull up the slave ss pin

 

}


An interrupt means that 8 bits of data have been sent once, that is, one byte of data has been sent.


Read the chapters I ignored before.

In the interrupt, the status register must be written to 1 to clear it, so in the interrupt, SPSTAT = 0XC0; clear the busy bit, and the interrupt is written. 

Reference address:STC8 MCU OLED is driven by SPI hardware interrupt (middle)

Previous article:STC8 MCU OLED is driven by SPI hardware interrupt (Part 2)
Next article:STC8 MCU OLED is driven by SPI hardware interrupt (Part 1)

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号