cancel
Showing results for 
Search instead for 
Did you mean: 

How to perform SPI communication within a board (master and slave)

pass3master
Senior

How to perform SPI communication within a board (master and slave)

We are trying to loop back SPI communication within the board, and perform transmission by the slave and reception by the master on one board.

The master's SPI CLK is connected to the slave's CLK,
but when the master is receiving, does the master not generate a CLK?
(In other words, the slave never transmits.)
Does the slave's CLK need a separate CLK input?

 

Sorry for our poor English.

5 REPLIES 5

This is basic SPI operation.

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

https://learn.sparkfun.com/tutorials/serial-peripheral-interface-spi/all

It is always and only the Master which generates clocks

 


@pass3master wrote:

We are trying to loop back SPI communication within the board, .


Not sure what you mean by that?

SPI is inherently a full-duplex link; ie transmission & reception happen simultaneously - that's why there are separate MOSI and MISO lines ...

"SPI is inherently a full-duplex link; ie transmission & reception happen simultaneously - that's why there are separate MOSI and MISO lines ..."
understand the above content. However, I have no choice but to create it at the request of our customers.
Is it possible to have the master receive and the slave transmit at the same time?
If I do that, the master will generate a CLK when it receives, and the slave will receive a CLK when it transmits.
Can I solve this by using DMA or something?


@pass3master wrote:

Is it possible to have the master receive and the slave transmit at the same time?


Of course - that is what full-duplex means!

While data is being clocked Out of the master on MOSI, it is simultaneously being clocked In to the Master on MISO

MOBEJ
ST Employee

Hello @pass3master  , 

I recommend checking out this article Getting started with SPI - stm32mcu , It explains SPI and provides examples for using it with STM32 microcontrollers. This should be very helpful for your project.

Best regards,

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.

@Andrew Neil wrote:

 

While data is being clocked Out of the master on MOSI, it is simultaneously being clocked In to the Master on MISO

See the diagram & animation in this post for an illustration of how this works:

https://www.avrfreaks.net/s/topic/a5C3l000000UacsEAC/t154582?comment=P-1246580

 

In the STM32 HAL, there is a HAL_SPI_TransmitReceive() function to perform this simultaneous transmit & receive.

 

Perhaps tell what peripheral you are trying to communicate with? Give a link to its datasheet...