MENU

Fun & Interesting

How To Write An STM32 SPI Driver (Full-Duplex Master Mode)

Z-The-Programmer 42,291 3 years ago
Video Not Working? Fix It Now

This tutorial demonstrates how to write a full-duplex SPI driver for an STM32 microcontroller without any hardware abstraction layers (bare metal) to communicate over the Serial Peripheral Interface (SPI) with other SPI devices with the microcontroller being the master on the bus. The tutorial covers the necessary SPI theory, STM32 SPI registers required and includes a coded example developed throughout the tutorial. After the code is fully developed, the SPI driver is tested by getting the microcontroller to communicate with the MPU9250 and reading data from its registers. The microcontroller used is the STM32L432KC but the registers, programming, and configuration are the same (or similar) across the stm32 boards. The tutorial covers the MPU9250 IMU to provide context for configuration choices of the SPI peripheral in the microcontroller. Source code for this tutorial is available at: https://github.com/Z-The-Programmer/STM32-Code/tree/main/How%20To%20Write%20An%20STM32%20SPI%20Driver%20(Full-Duplex%20Master%20Mode)) Timestamps: 00:00 - Introduction 00:31 - SPI Theory 02:57 - Picking SPI Pins 03:13 - Peripheral Clocks 04:06 - SPI Pin Configuration 05:35 - SPI Peripheral Configuration: Control Register 1 12:19 - SPI Peripheral Configuration: Control Register 1 Code 13:01 - SPI Peripheral Configuration: Control Register 2 15:58 - SPI Peripheral Configuration: Control Register 2 Code 17:08 - SPI Transfer Function 23:09 - SPI Communication Test 24:23 - SPI Reconfiguration (V2) 27:04 - SPI Communication Test (V2) 27:22 - End

Comment