chipKIT® Development Platform

Inspired by Arduino™

SPI Slave>Master Transmit Example

Created Mon, 19 Nov 2012 18:22:43 +0000 by snovich


Mon, 19 Nov 2012 18:22:43 +0000

Hi all -

Would anyone be able to help explain to me the setup/what needs to be done to get an SPI slave device (Max32 in my case) to transmit back to a Master device (Arduino Uno in my case). I know how to put the Max32 in slave mode and receive (or Master mode and transmit), but not how to send data back. I do know that the Master also needs to somehow initiate the transmission...

I've been going through the PIC32 SPI manual, but haven't quite been able to figure it out.

Thanks! -S


Mon, 19 Nov 2012 19:28:09 +0000

The slave doesn't transmit. Only the master transmits.

When the master transmits data to the slave, it also receives back whatever the slave has in its outgoing buffer. You cannot initiate a transmission from a slave.

For bidirectional communication I usually use a packet based system, with several distinct phases.

The master sends commands and data to the slave, then keeps sending NULL bytes to the slave while waiting for and reading a response.

My usual packet format is basically:

  • Command - the command being sent to the slave

  • Checksum - simple checksum of the whole transmitted packet

  • Length - length of the data segment

  • Data - a number of bytes of data.

  • Keep sending 0 and read the incoming data. Expect data in a similar format as the transmitted command:

  • Response code,

  • Checksum

  • Length

  • Data

Once all the data has been received, stop sending 0 and process the response.


Mon, 19 Nov 2012 21:13:34 +0000

Got it, thanks!


Tue, 05 Feb 2013 04:49:05 +0000

It looks like you got your Max32 slave to work. Can you provide sample code?