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()
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?
:-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
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?
14:18 - You send command to read data from address 5. How EEPROM chip knows that you're expecting 3 bytes to receive, not 7 or 10? I assume that HAL_SPI_Receive command simply waits for data coming in or it is send some short commands as well to EEPROM? Thank you
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
OK, I'm using the STM32F100RB and the file is: \Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_spi.c and the function to use is: HAL_SPI_TransmitReceive().
Anyone else having problems using HAL_SPI_Transmit() and HAL_SPI_Receive() functions for STM32H753 (HAL version 1.11) ? The combined HAL_SPI_TransmitReceive() function works for me but not the individual ones
I am still confused. How do we use SPI2 and SPI3? How can we use them at the same time as SPI1? All my attempts seem to fail miserably, whereas SPI1 seems easy.
Why didn't you set the peripheral to automatically control CSN, instead of manually via GPIO? Is it because the CSN line goes goes tri-state when not in use, so without an external pull-up, the only workaround is to manually disable the hardware NSS and manually control it via a GPIO? And so if you are controlling CSN independently, when 'HAL_SPI_Transmit' returns is guaranteed that the transfer has completely finished, or is it possible that it returns, but the peripheral could still be clocking out data? I've also seem some very strange behavior in CubeMX entering User Labels.. after every entry, the caret seems to jump to the character before!
This is my 2 cents answer: 1. The hardware CSN is more for when your MCU in slave mode rather than master mode. Because you would get into scenario that needs to control multiple slaves with one SPI peripherals and obviously one hardware CSN is not enough. 2. The function is a polling function with a time wait arguments. It will returns HAL_OK if the peripherals is successfully transmitted the data and HAL_ERROR or HAL_BUSY otherwise (I think). So using this requires setting time good enough to wait the peripherals transmit the data. In basic scenerio like testing out the peripheral, using HAL_MAX_DELAY would suffice. Otherwise adding a bit of waiting would do too or even better, interrupts :))
Apologies, as it looks like it's buried. It's labeled as "Related Project Link:" www.digikey.com/en/maker/projects/getting-started-with-stm32-how-to-use-spi/09eab3dfe74c4d0391aaaa99b0a8ee17
The interrupt version never works because the state machine is wrong. The codes always switch to state 1 and never goes to state 2, 3, 4 and 5. And the plus signs are missing here: for (int i = 0; i < 10; i ) { spi_buf[2 i] = i; } I think the code is never tested.
Shawn will absolutely go down in the history books.
These are the best tutorials I have ever come across. You are doing a great contribution to the embedded community. Respect🙌
Love this series Shawn and digikey. Keep 'em coming!
This series is gold, thank you for making this
OMG Shawn, I'm just using this now at work, you're a life saver!
what do u work as?
@@abutaymiyyahlectures mad scientist - Great Scott!
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()
Wow! I subscribed instantly after I watched your video. It´s amazing how you explain everything and so clear!
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?
Excellent tutorial. Thanks Shawn
This is an EXCELLENT video. Bravissimo!
Thanks this helped me!
I was able to eventually read a RTC chip in half duplex mode based off this example
Very helpful, especially because you show us how to print to the serial terminal in debug. Thank you!
My problem is solved form this clip many thanks.
These videos are excellent, thank you!
Very informative. Thank you.
very nice video, Thanks a lot!!!!!
Can you show how to use I2C Slave using interruption or DMA in STM32 (non blocking method)
informative and simple to use
:-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
for some reason when I use this code and setup on my g474re using lpuart putty always displays nothing at all
i've got the same issue
@@varulven5143 the baud rate was not set correctly in putty, check in cube MX what tje baud rate is set to and put the same into putty
Excellent tutorial ! Thanks a lot !
Excellent video ! Thanks much Shawn. Is there any tutorial on the interrupt structure of STM32F103xxx ?
Very useful again any recommendations on which STM32 nucleo board which can be use with your trading demos / future videos CAN bus hint hint....😬
Please do a video for CAN as well using HAL.
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?
14:18 - You send command to read data from address 5. How EEPROM chip knows that you're expecting 3 bytes to receive, not 7 or 10? I assume that HAL_SPI_Receive command simply waits for data coming in or it is send some short commands as well to EEPROM?
Thank you
The eeprom will keep sending out bites starting from the address you gave it, as long as you keep the clock pulsing (and keep cs low)
You have better video than stm
Why does Fritzing diagram show 25LC040 but you paste in constants for 25AA040A?
every dude i know named shawn is a fucking genius
how to do uart configuration manually? in my ide it doesn't come prepared
There are random spikes in my CS pin signal during HAL_SPI_Transmit operation. Do you know why?
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
I get 2 extra clock pulses on my very first transmit, all other transmits are fine. Do you have any idea, why this happens?
Can you make a video about Can Bus?
Thank you! It is useful!
Can you explain how you can send dummy data and get garbage data via "Hal Function " ?
Can I send and receive data to 2 microcontroller ??
I do not know why, but STM32CubeIDE 1.3.1 it does not show the baud rate when I select the prescaler.
I want to use it with CRC, even I enabled it and then I'm intentionally writing wrong values but CRCERR flag is not set
How do you get CubeMX to generate the SPI transmit/receive functions? It only generates to init.
OK, I'm using the STM32F100RB and the file is: \Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_spi.c and the function to use is: HAL_SPI_TransmitReceive().
Very good.
Anyone else having problems using HAL_SPI_Transmit() and HAL_SPI_Receive() functions for STM32H753 (HAL version 1.11) ? The combined HAL_SPI_TransmitReceive() function works for me but not the individual ones
I am still confused. How do we use SPI2 and SPI3? How can we use them at the same time as SPI1? All my attempts seem to fail miserably, whereas SPI1 seems easy.
Yes!
continue from 13:30
i am not able to read more than 256 bytes in externnal spi
Why didn't you set the peripheral to automatically control CSN, instead of manually via GPIO? Is it because the CSN line goes goes tri-state when not in use, so without an external pull-up, the only workaround is to manually disable the hardware NSS and manually control it via a GPIO?
And so if you are controlling CSN independently, when 'HAL_SPI_Transmit' returns is guaranteed that the transfer has completely finished, or is it possible that it returns, but the peripheral could still be clocking out data?
I've also seem some very strange behavior in CubeMX entering User Labels.. after every entry, the caret seems to jump to the character before!
This is my 2 cents answer:
1. The hardware CSN is more for when your MCU in slave mode rather than master mode. Because you would get into scenario that needs to control multiple slaves with one SPI peripherals and obviously one hardware CSN is not enough.
2. The function is a polling function with a time wait arguments. It will returns HAL_OK if the peripherals is successfully transmitted the data and HAL_ERROR or HAL_BUSY otherwise (I think). So using this requires setting time good enough to wait the peripherals transmit the data. In basic scenerio like testing out the peripheral, using HAL_MAX_DELAY would suffice. Otherwise adding a bit of waiting would do too or even better, interrupts :))
Every time it transmits, does it transmit data to all the slaves one after the another?
fine!!!
and the code link is?
Apologies, as it looks like it's buried. It's labeled as "Related Project Link:" www.digikey.com/en/maker/projects/getting-started-with-stm32-how-to-use-spi/09eab3dfe74c4d0391aaaa99b0a8ee17
Found it I was expecting a GIT link
// Print out bytes read
uart_buf_len = sprintf(uart_buf,
"0xx 0xx 0xx
",
(unsigned int)spi_buf[0],
(unsigned int)spi_buf[1],
(unsigned int)spi_buf[2]);
HAL_UART_Transmit(&huart2, (uint8_t *)uart_buf, uart_buf_len, 100);
The code on your website is broken, note the hex value characters. :)
LOL here I thought SPI was a simple protocol.
It's a pain in the ass
The interrupt version never works because the state machine is wrong. The codes always switch to state 1 and never goes to state 2, 3, 4 and 5. And the plus signs are missing here:
for (int i = 0; i < 10; i )
{
spi_buf[2 i] = i;
}
I think the code is never tested.