Skip to main content
Visitor II
January 2, 2024
Question

Sending message from slave to master (SPI)

  • January 2, 2024
  • 2 replies
  • 3792 views

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!

    This topic has been closed for replies.

    2 replies

    Technical Moderator
    January 2, 2024

    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 

    JordalicAuthor
    Visitor II
    January 2, 2024

    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.

    Graduate II
    January 2, 2024

    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.

    JordalicAuthor
    Visitor II
    January 2, 2024

    Are you referring to Full Duplex SPI?