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

preview_player
Показать описание
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.

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.

Product Links:

Related Videos:
Getting Started with STM32 and Nucleo Part 1: Introduction to STM32CubeIDE and Blinky

Getting Started With STM32 and Nucleo Part 2: How to Use I2C to Read Temperature Sensor TMP102

Getting Started With STM32 and Nucleo Part 3: FreeRTOS - How To Run Multiple Threads w/ CMSIS-RTOS

Getting Started With STM32 & Nucleo Part 4: Working with ADC and DMA

Programming the Adafruit Feather STM32F405 Express with STM32CubeIDE

TinyML: Getting Started with STM32 X-CUBE-AI

Related Project Links:

Related Articles:
Рекомендации по теме
Комментарии
Автор

Shawn will absolutely go down in the history books.

BohrKid
Автор

These are the best tutorials I have ever come across. You are doing a great contribution to the embedded community. Respect🙌

sumeetbhanjadeo
Автор

Love this series Shawn and digikey. Keep 'em coming!

LOLukeJamieson
Автор

Very helpful, especially because you show us how to print to the serial terminal in debug. Thank you!

paulrudman
Автор

Wow! I subscribed instantly after I watched your video. It´s amazing how you explain everything and so clear!

javibaeza
Автор

Thanks this helped me!
I was able to eventually read a RTC chip in half duplex mode based off this example

danpommerening
Автор

These videos are excellent, thank you!

michaelallport
Автор

Great video. Good pace and explanations. Alot better than the guides ST offers.
As for future videos something showing how to find and include 3rd party libraries would be good. And maybe combine that with a small graphic i2c OLED display to print text?

ErikLevholt
Автор

This is an EXCELLENT video. Bravissimo!

antonello
Автор

Thank you for this useful tutorial.
Maybe you do another one on Octo-SPI ?

Some bookmarks:
1:51 3 lines SPI configuration!
2:53 daisy chain connection
8:41 note that you can use any gpio pin for your chip select line
9:55 full duplex master
10:45 the spi configuration.
12:44 read status register
13:58 wait until WIP bit is cleared
14:59 a way to do the code non-blocking
17:02 using: HAL_SPI_Transmit_IT()
18:38 HAL_SPI_TxCpltCallback()

yosefgreen
Автор

My problem is solved form this clip many thanks.

Auddy_s
Автор

OMG Shawn, I'm just using this now at work, you're a life saver!

AlexEduardoRR
Автор

:-D :-D I am really glad you made that a simple explanation :-) :-).
Sorry I was reminded of some small book from my past entitled RS232 Made Easy. It was 400 pages thick.
Forgive me I need to go over it a few more times. Maybe I will want to use the SPI afterwards, maybe not. I also need to get some previous background material. I do not NEED to do these things od course, I am just curious.
Regarding burning an EPROM: I made and partially wrote the program for a 2708 and 2716 eprom and to speed things up we used a more rapid burn cycle followed by a read for each bit, maybe byte untill the received equalled the sent then sent a few more burn cycles to make sure. The overall result was a MUCH shorter burn time. Please don't ask me for details it is 40+ yrs ago and more accomplished people did the majority of the work. I think I have come across the comercial version in my junk now and then. Not something Magpies throw away

jamesgoacher
Автор

Excellent video ! Thanks much Shawn. Is there any tutorial on the interrupt structure of STM32F103xxx ?

mumbaiverve
Автор

Very useful again any recommendations on which STM32 nucleo board which can be use with your trading demos / future videos CAN bus hint hint....😬

ordnanceant
Автор

Thanks for the useful tutorial. I just want to ask, what are the best options for TFT display (of at least 4" size) that I can interface with my STM32F401 Nucleo-64 board? Which interface would be better, SPI or parallel?

rajeshn
Автор

very nice video, Thanks a
Can you show how to use I2C Slave using interruption or DMA in STM32 (non blocking method)

alfredorabago
Автор

Great video thanks a lot.
And if you get stuck like me where you keep getting 0 for your status register.
Make sure you are using a pointer.
e.g uint8_t spi_test2;
HAL_SPI_Receive(&hspi1, (uint8_t *)&spi_test2, 1, 100);

I forgot the &, and it caused some pain ;p

RenegadeFury
Автор

There are random spikes in my CS pin signal during HAL_SPI_Transmit operation. Do you know why?

dajianghe
Автор

every dude i know named shawn is a fucking genius

Bravo_L