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.

1 ACCEPTED SOLUTION

Accepted Solutions
SofLit
ST Employee

Hello,

What do you mean by this? the maximum clock frequency that the SPI can generate?


@SMusc.1 wrote:

but what aboout the SCK that the stm32 board transmit on the SPI pin? 


But you need also to know the maximum frequency that your FPGA can sustain as SPI clock.

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/support.

View solution in original post

14 REPLIES 14

@SMusc.1 wrote:

 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 .


The SCK clock is essential to any SPI operation - you can't have SPI without SCK - so it's not clear what you mean by this?

You cannot have SPI with just MOSI and CS.

https://en.wikipedia.org/wiki/Serial_Peripheral_Interface

The whole SPI interface - MOSI, MISO, and SCK - is managed by the STM32's SPI hardware (with CS, you have the option of doing it in hardware or software)

https://wiki.st.com/stm32mcu/wiki/Getting_started_with_SPI 

 

See the Datasheet and Reference Manual for your specific chip for full details.

https://www.st.com/en/microcontrollers-microprocessors/stm32u575zi.html#documentation

The examples in STM32CubeMX (whether standalone or integrated in the CubeIDE) include SPI.

 

PS:

Application Note AN5543 Guidelines for enhanced SPI communication on STM32 MCUs and MPUs:

https://www.st.com/resource/en/application_note/an5543-guidelines-for-enhanced-spi-communication-on-stm32-mcus-and-mpus-stmicroelectronics.pdf

SofLit
ST Employee

Hello,

What do you mean by this? the maximum clock frequency that the SPI can generate?


@SMusc.1 wrote:

but what aboout the SCK that the stm32 board transmit on the SPI pin? 


But you need also to know the maximum frequency that your FPGA can sustain as SPI clock.

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/support.

Hi Andrew, it know that SCK is essential but as i know, the sck is a frequency that need to read some value on the varius setting mode (SPI Mode 0 for example), so every rising edge of the sck the slave read the data line of the MOSI. Question: the sck is auto set by selecting SPI setting (this my doubt) or i need to set some timer on some pin as sck? Since i am using stm32 board as master and FPGA board as slave, i think i need to know the sck to say to FPGA when read the data on MOSI line.  


@SMusc.1 wrote:

 Question: the sck is auto set by selecting SPI setting (this my doubt) or i need to set some timer on some pin as sck? .  


SCK clock is generated by the SPI peripheral itself in master mode. No need to take care of its generation!

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/support.

Yes, the SCK frequency is a parameter you set; eg, in CubeMX.

ST refer to it as "Baud Rate"

AndrewNeil_1-1737977947091.png

 

In general, you can pick any value you like up to the maximum which the slowest Slave supports.

As it sounds like you have only 1 slave - your FPGA - you can pick any value you like up to the maximum which the FPGA implementation supports.

@SMusc.1 Did you wrongly accepted the answer? or you are convinced?

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/support.

Okay Andrew, 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.

I am counfused on the : SCK frequency and on the data speed? Which is the difference beetwae them?

Data speed reflects the clock frequency.

1Mb/s data -> 1MHz of the clock frequency. Each bit transferred corresponds to a period of the clock: 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/support.