Home » Science & Technology » Getting Started with STM32 and Nucleo Part 5: How to Use SPI | Digi-Key Electronics

Getting Started with STM32 and Nucleo Part 5: How to Use SPI | Digi-Key Electronics

Written By DigiKey on Monday, Aug 03, 2020 | 09:30 AM

 
In this tutorial, Shawn shows you how to use the STMicroelectronics STM32CubeIDE to configure and use the Serial Peripheral Interface (SPI) communication bus on an STM32 Nucleo board. If you are not familiar with STM32CubeIDE, we recommend watching this video first: https://www.youtube.com/watch?v=hyZS2p1tW-g We first go over the basics of SPI communication, which includes how to connect devices in a variety of configurations on the bus. We additionally look at the different operating modes and how CPOL and CPHA can be adjusted for different devices. After, we look at a real logic analyzer capture of a SPI signal and analyze it as a timing diagram. Then, we connect a SPI EEPROM chip to the Nucleo board so we can test SPI functionality. The plan is to write several bytes to the EEPROM and then read them back. If they match, then we know SPI and the EEPROM are working. Next, we use STM32CubeIDE to configure one of the SPI buses on the STM32 microcontroller. From there, we write several lines of C code, using the HAL library, to read and write bytes to and from the SPI bus. Bytes read from the EEPROM are written to the serial terminal. Finally, we provide a demo on how to use SPI with interrupts to create non-blocking SPI communication. Please note that we are using the Nucleo-L476RG for this video, which can be found here: https://www.digikey.com/product-detail/en/stmicroelectronics/NUCLEO-L476RG/497-15881-ND/5347711?WT.mc_id=frommaker.io Product Links: Nucleo-L476RG - https://www.digikey.com/product-detail/en/stmicroelectronics/NUCLEO-L476RG/497-15881-ND/5347711 Microchip 25AA040A-I/P EEPROM - https://www.digikey.com/product-detail/en/microchip-technology/25AA040A-I-P/25AA040A-I-P-ND/1212469 Related Videos: Getting Started with STM32 and Nucleo Part 1: Introduction to STM32CubeIDE and Blinky https://www.youtube.com/watch?v=hyZS2p1tW-g Getting Started With STM32 and Nucleo Part 2: How to Use I2C to Read Temperature Sensor TMP102 https://www.youtube.com/watch?v=isOekyygpR8 Getting Started With STM32 and Nucleo Part 3: FreeRTOS - How To Run Multiple Threads w/ CMSIS-RTOS https://www.youtube.com/watch?v=OPrcpbKNSjU Getting Started With STM32 & Nucleo Part 4: Working with ADC and DMA https://www.youtube.com/watch?v=EsZLgqhqfO0 Programming the Adafruit Feather STM32F405 Express with STM32CubeIDE https://www.youtube.com/watch?v=gOjzs4y5hWA TinyML: Getting Started with STM32 X-CUBE-AI https://www.youtube.com/watch?v=crJcDqIUbP4 Related Project Links: Getting Started with STM32 - How to Use SPI - https://www.digikey.com/en/maker/projects/getting-started-with-stm32-how-to-use-spi/09eab3dfe74c4d0391aaaa99b0a8ee17 Related Articles: Making a Temperature Logger with the Adafruit Feather STM32F405 Express - https://www.digikey.com/en/maker/projects/making-a-temperature-logger-with-the-adafruit-feather-stm32f405-express/11ea860d54074a19bb75cb6425e6d0b0 TinyML: Getting Started with STM32 X-CUBE-AI - https://www.digikey.com/en/maker/projects/tinyml-getting-started-with-stm32-x-cube-ai/f94e1c8bfc1e4b6291d0f672d780d2c0