Рет қаралды 31,631
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:
github.com/Z-T...)
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