Electronic – SPI: Receiving bytes from slave


For a couple of days I have been learning about SPI and decided to give it a go with 2 small devices.

  • DEVICE 1: Atmega328p (MASTER)

As far as I understand:

  • master sets SS pin low
  • master moves data to SPDR
  • as soon as data gets in to SPDR clock starts transmitting and data shift out
  • at the same time SLAVE shift data out too
  • so by the end of 8 clock pulses SLAVE received 1 byte and master received 1 byte too
  • SS pin goes high again

Scenario #1

I am sending the address byte to MFRC522 from Atmega328p, and expecting a reply. According to the documentation, the first response from SLAVE is "X" I take it as 0x00.

On the next byte sent to the SLAVE, I receive the response from the first byte I sent, and so on until the end.

Since it has some kind of offset would I need to send 0x00 to the slave to read that last byte of information?

Best Answer

Table 6 on p.11 of the datasheet is pretty explicit:

Yes, to receive the Nth data byte, you need to transmit 00 in the (N+1)th transfer.