2025-01-03 05:34 PM - edited 2025-01-03 05:50 PM
I am using this dev board: NUCLEO-F411RE for developing SPI communication protocol considering it as a SLAVE device. My firmware will receive data over SPI sent by Host machine and acts on it.
I have following requirement:
How to transmit data packets via host PC to MCU using SPI to test whether my firmware working correctly or not ?
Option A: To use Raspberry Pi as a Host machine device and send data over SPI to MCU :
-> This one so far seems best option for me as I can easily write test python application using open source spidev package python-spidev and easily connect Raspberry Pi and NUCLEO board as both supports SPI interface.
Option B : I have also found this USB-SPI-bridge converter to directly connect Host PC (Windows, Linux) to Nucleo-Board based on SPI interface
pdf: FTDI-MULTI-SLAVE
Also found this Adafruit-FT232H for same USB-to-SPI bridge converter
Is thee any other similar dongle available which are cost effective and easy to use ?
Can anyone suggest which one is the best options to achieve this communication setup for testing SPI communication between Host Machine and MCU ?
2025-01-03 06:06 PM
You can always connect a 2nd SPI bus on the same Nucleo board as a master to your slave SPI bus. Use the VCP to receive some data and pass that data over the master SPI. Then you can see if your slave SPI works correctly.
2025-01-03 06:44 PM
Yes, you would need a SPI Master which you can control from PC host (e.g. Windows OS, Linux OS, ....).
Yes, Raspberry would be a good option: with the Python library it should be possible.
Yes, there are also boards (and chips) for SPI, e.g. FTDI, Silicon Labs, even Aardvark (TotalPhase).
It should work (we use TotalPhase very often, sometimes also FTDI).
Just to make sure to configure properly:
Where is your problem?
Sure, you can also configure another SPI as Master on MCU and try a "loopback" test (to make sure your SPI Slave implementation works).
If you ask about how to implement a SPI Master on PC side (Windows or Linux OS) - yes, some solutions there as you have mentioned. FTDI and TotalPhase are good options (and coming with C/Python sample code).
You can also create a second MCU with FW running as "UART over USB" and acting as a SPI Master: connect both SPIs and let receive what you send.
2025-01-03 07:58 PM
Looks like you are trying to simulate spi master. Your selection depends on the maximum clock rate, voltage levels etc. Lowest possible expensive solution would be esp32 using arduino or Raspberri pico board. Both are easy to be set-up and you can make changes and update easily.
2025-01-04 01:59 AM - edited 2025-01-04 03:15 AM
@ercjethava1992 wrote:Is there any other similar dongle available which are cost effective and easy to use ?
I don't think you're going to find anything more cost effective than a simple FTDI chip!
eg, Total Phase have a great range of products, but they are orders of magnitude more expensive:
https://www.totalphase.com/protocols/spi/
As @Karl Yamashita said, you could use another SPI port on the same microcontroller.
You could also use another, separate microcontroller - it needn't be an STM32; eg, an Arduino...
@ercjethava1992 wrote:setup for testing SPI communication between Host Machine and MCU ?
The key thing you'll need is something to enable you to see what's happening on the wires - an oscilloscope and/or a logic analyser.
Without that, you're in the dark!
Low-cost (~$10) logic analysers are widely available on the likes of Amazon, ebay, et al ...
PS:
Don't make the classic mistake of trying to do both ends of the link at once!
Otherwise you're just testing your unproven slave against an unproven master:
I suggest that you start by getting your Host/Master to work with some well-known standard slaves:
2025-01-06 05:04 PM - edited 2025-01-06 05:10 PM
@Andrew Neil @tjaekel
Have further question based on considering Raspberry Pi(As Master SPI) for testing MCU SPI SLAVE firmware which I am developing
MCU board : (SLAVE)
https://www.st.com/en/evaluation-tools/nucleo-f411re.html
Q.1. where I can find SPI pins voltage ratings for MCU used in this board which is :STM32F411RE
to determine whether level shifter required or not to connect SPI pins between RaspberryPi and MCU
Raspberry Pi:(MASTER) https://www.sparkfun.com/products/15446?src=raspberrypi
SPI: https://www.raspberrypi.com/documentation/computers/raspberry-pi.html#spi-overview
GPIO voltage ratings on Raspberry Pi: (3.3V)
https://www.raspberrypi.com/documentation/computers/raspberry-pi.html#outputs
From MCU datasheet I found following Speed supported by SPI:
stm32f411re-datasheet
Q2. Description mentioned into section 3.23 and Table-60, I am confused about actual Speed Supported by SPI in slave mode :
What is difference between Slave Mode vs Slave Full duplex Mode ? as both defined with different Clock rate as 25Mhz vs 38 MHz
Then I cant use Master supported Max SPI clock settings if slave doesn't support it and have to use same clock setting as supported by Slave Am I correct ?
SPI interface characteristics:
2025-01-06 05:26 PM
@ercjethava1992 wrote:Q.1. where I can find SPI pins voltage ratings for MCU
That will be in the MCU's datasheet
2025-01-07 04:55 PM
My interpretations...
1. RPi SPI and 3V3:
The Raspberry Pi should be all as 3V3, also the SPI pins. So connecting a RPi SPI master with an STM32 MCU slave, all as 3V3 systems - should work (no level shifters needed).
2. Slave Mode vs. Slave Full duplex Mode:
I think "Slave Full duplex Mode" is just related to the topic, when you use SPI as I2S slave:
SPI is (usually) always "full duplex", unless you configure SPI in "receiver only".
I guess, this line in datasheet as "Slave transmitter/full duplex mode" belongs to SPI as I2S (slave, full duplex).
"slave mode" is also for regular SPI, as slave.
3. Datasheet and "50 MHz vs. 25 MHz":
The 'general statement' about SPIs with 50 MHz, some other as 25 MHz is related to the "guaranteed" speed, with all voltage levels, and covering "all" SPIs.
See in the table, that different voltage ranges are mentioned: in 1.8V mode - the speed is reduced to 25 MHz. Therefore, as "general statement": "always 25MHz at least" (on lowest voltage included, but it can be faster on higher voltage or even some other SPIs).
4. Why Slave Mode just 1/2 of Master Mode speed?
Usually, a Slave is always slower as a Master. The reason is potentially: as a slave the SPI SCLK is received. This external clock goes through clock synchronizers, to avoid clock glitches. The synchronizer needs (at least) one external clock cycle to be "considered" as stable.
In master mode the internally generated clock is used also to sample the slave response (MISO), which does not need a clock synchronizer.
Summary:
Take it as this:
I think, the datasheet makes sense and is correct (the confusion about "Slave full duplex mode" seems to come from the intention to mention also I2S modes (possible to configure on SPIs).)
With 3V3 I/O voltage you should be able to generate 50 MHz (as master), use 25 MHz as slave (minimum guaranteed)
Isn't this fast enough?
Even Raspberry Pi fits as 3V3 - are you sure you can configure and generate 50 MHz (ore even 25 MHz) with Raspberry Pi? Play with RPi, configure and use SPI on it, check with scope...
STM32 MCU as a slave should "follow" any clock speed generated if RPi is the SPI master, even with "pauses/gaps" in SCLK, as long as it is not faster as your STM32 SPI slave is specified for (25 MHz).
What do you think would not work?
2025-01-08 01:05 AM
@tjaekel wrote:1. RPi SPI and 3V3:
The Raspberry Pi should be all as 3V3
I think (at least some) of it is 1.8V ?