cancel
Showing results for 
Search instead for 
Did you mean: 

SPI as master and FPGA as slave for some bits

SMusc.1
Associate III

Hello everybody. I asking now for some help on my new project. On my stm32 u575zit-q i want send some bits, as master, on the FPGA EP2C5T144C8N as slave. This FPGA board is very simple (have no other peripherals on it). So i want send by means SPI, four bits in one pin of the FPGA. I know how write code for the SPI in stm32 using MOSI, CS, but now i am focused on SCK (serial clock) that the FPGA need to use for read some bit. I tried to found some on the web but i didnt. Have some one things to help me? On CUBE IDE i see the baude rate (Mbits/s for example set to 1 Mbit/s), but what aboout the SCK that the stm32 board transmit on the SPI pin? I have one idea of how i can implement and i share this with you: on CUBE IDE, if i knew the sck frequency, then i can set some check on my FPGA for read on the rising edge of the sck line, the data sending on the MOSI line of the STM32 board and load this value in some interna register of my FPGA to use it as I need later.

 

I hope that my issue is clear and say thank to all in advance.

14 REPLIES 14

Okay easy. Now I will try to read in FPGA board, each clock period, the data send from stm32 board. Tks 


@SMusc.1 wrote:

since my FPGA board is very simple, it have no SPI interface on it. For this reason i wanted know the sck frequency and not the data speed in Mbit/s.


It seems you still haven't really understood how SPI works: exactly one bit is exchanged per clock cycle.

Therefore, the clock frequency (Hz)  is the data speed (bit/s).

Andrew I really appreciate your support and that of all the members here in this community. Now that the relationship between SCK and bauderate is clear, on my FPGA I can connect one pin to stm32 SCK, one pin to CS and last to MOSI for half duplex comunication (witout MISO line). Now when I go to read the various bits in the code from the FPGA I will do it on the MOSI line, so I will see all the transitions of the bits. This of course I will do at every rising edge of the clock on the SCK line and the bits will be present instead on the MOSI line. So if I connect an oscilloscope on the SCK line output from the stm32 board I expect to see a signal with a frequency equal to the bauderate set in the cube IDE interface as in the attached image right?

Setting_CUBE_IDE.jpg


@SMusc.1 wrote:

This of course I will do at every rising edge of the clock on the SCK line and the bits will be present instead on the MOSI line.


That depends on the polarity you set: https://en.wikipedia.org/wiki/Serial_Peripheral_Interface#/media/File:SPI_timing_diagram_CS.svg

To give better visibility on the answered topics, please click on "Accept as Solution" on the reply which solved your issue or answered your question.
PS:
1 - This is NOT an online support (https://ols.st.com) but a collaborative space.
2 - Please be polite in your reply. Otherwise, it will be reported as inappropriate and you will be permanently blacklisted from my help.

yes of course. Tks so much