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.
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)
- Popular Resources
- Popular amplifiers
- Learn ARM development(16)
- Learn ARM development(17)
- Learn ARM development(18)
- Embedded system debugging simulation tool
- A small question that has been bothering me recently has finally been solved~~
- Learn ARM development (1)
- Learn ARM development (2)
- Learn ARM development (4)
- Learn ARM development (6)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- LED chemical incompatibility test to see which chemicals LEDs can be used with
- Application of ARM9 hardware coprocessor on WinCE embedded motherboard
- What are the key points for selecting rotor flowmeter?
- LM317 high power charger circuit
- A brief analysis of Embest's application and development of embedded medical devices
- Single-phase RC protection circuit
- stm32 PVD programmable voltage monitor
- Introduction and measurement of edge trigger and level trigger of 51 single chip microcomputer
- Improved design of Linux system software shell protection technology
- What to do if the ABB robot protection device stops
- Detailed explanation of intelligent car body perception system
- How to solve the problem that the servo drive is not enabled
- Why does the servo drive not power on?
- What point should I connect to when the servo is turned on?
- How to turn on the internal enable of Panasonic servo drive?
- What is the rigidity setting of Panasonic servo drive?
- How to change the inertia ratio of Panasonic servo drive
- What is the inertia ratio of the servo motor?
- Is it better for the motor to have a large or small moment of inertia?
- What is the difference between low inertia and high inertia of servo motors?
- EEWORLD University - Texas Instruments Deep Learning (TIDL) Overview
- Can the transmission speed of Zigbee be achieved on a small car?
- How to read and write CSRs of RISC-V processors using J-Link and Embedded Studio?
- Oscilloscope probe problems
- Applying Over-the-Air Firmware Upgrades to MSP 430 Microcontrollers
- Seeking help for the solution of the platform on the rising edge of BUCK type DCDC
- Please help me, teachers, the communication problem.
- Some notes on 28335 performance testing
- Altium Designer 21.0.7
- [Summary] EEWorld invites you to disassemble (Part 4): Disassembly of popular power banks