You can access the source code files via this link.
This project aims to investigate the efficient implementation of SPI communication between two STM32 microcontrollers using various modes of communication, namely polling, interrupt, and DMA. The SPI protocol is widely used for communication between microcontrollers, and optimizing its implementation can greatly improve the overall performance of a system.
In polling mode, the microcontroller continuously checks the SPI status flags to determine if data has been received or if the transmit buffer is empty.
In interrupt mode, the microcontroller generates an interrupt when the SPI status flags indicate that data has been received or when the transmit buffer is empty. The interrupt service routine (ISR) processes the received data and fills the transmit buffer.
In DMA mode, the microcontroller transfers data between the SPI and memory without CPU intervention. The DMA controller manages the data transfer, freeing the CPU to perform other tasks.
The project will cover the implementation of each mode of communication using the SPI interface on the STM32 microcontroller and evaluate its performance in transferring data between the two STM32 boards (Master & Slave) using Proteus simulation. By simulating the system in Proteus, we can explore different scenarios and observe the behavior of the system under different conditions.
Step One:Master board Configuration:
- Open CubeMX & Create New Project Choose The Target MCU STM32F103C6 & Double-Click Its Name
- Go To The Clock Configuration & Set The System Clock To 8MHz
- Configure The GPIO Pins PB13, PB14 and PB15 as Input Pin
- Configure The GPIO Pins PB12and PA4 as Output Pin
- In the Categories tab, select the SPI1 & Full-Duplex Master
- Generate The Initialization Code & Open The Project In CubeIDE
- Write The Application Layer Code
Slave board Configuration:
- Open CubeMX & Create New Project Choose The Target MCU STM32F103C6 & Double-Click Its Name
- Go To The Clock Configuration & Set The System Clock To 8MHz
- Configure The GPIO Pins [PB9... PB15 ] & (PB0, PB1) as Ouput Pin
- Configure The GPIO Pins PB5, PB6 and PB7 as Intput Pin
- In the Categories tab, select the SPI1 & Full-Duplex Slave & Hardware NSS Input Signal
- Generate The Initialization Code & Open The Project In CubeIDE
- Write The Application Layer Code
The file names 'LiquidCrystal.h' and 'LiquidCrystal.c' can be found in the previous project STM32 LCD Interface.
Step Two:- Open Proteus & Create New Project and click next
- Click on Pick Device
- Search for STM32F103C6 & LCD 16*2, Button, LED, SW-SPDT
- Click on Virtual Instruments Mode then choose OSCILLOSCOPE
- Click on Terminal Mode then choose (DEFAULT & POWER &GROUND)
- finally make the circuit below and start the simulation
If you have any questions or suggestions don't hesitate to leave a comment below
Comments