cancel
Showing results for 
Search instead for 
Did you mean: 

Sending message from slave to master (SPI)

Jordalic
Associate II

Hello,

I'm trying to send a message from slave to master using spi (I'm using only one stm board) and so far nothing I tried has worked. AFAIK for the slave to send data to master, the master has to initiate communication first by sending clock signals, and dummy bytes. 

1) To be able to send data from slave to master, is Full Duplex is a must (for purpose of Master to send dummy bytes while simultanously receiving bytes)? 

2) I tried using HAL_SPI_TransmitRecieve() in Master size but I'm not sure what function should I use with the slave, and what is the order of function calls.

 

I would appreciate your help, 

Thanks!

4 REPLIES 4
STTwo-32
ST Employee

Hello @Jordalic 

I suggest you to start from an example that use SPI for master to slave communication between 2 boards. Than use the master configuration for the spi master (spi 1 for example) and the slave configuration for the spi slave (spi 2 for example).

Best Regards.

STTwo-32 

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.

The slave would also use HAL_SPI_TransmitRecieve() 

But you'll be one byte behind, so typically you'd initially respond with a dummy byte, and then receive a "register" or "command" type byte, or bytes, from the Master indicating what it is you're trying to communicate. This allows the Slave to determine what type of response is expected.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

Actually I tried sending messages from master to slave with no problem at all. I find that the otherway around is more tricky because slave cannot initiate transactions and the master need to send dummy data first and only than read the data of the slave.

Are you referring to Full Duplex SPI?