1
\$\begingroup\$

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)
  • DEVICE 2: MFRC522 (SLAVE)

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?

\$\endgroup\$

1 Answer 1

2
\$\begingroup\$

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.

\$\endgroup\$
2
  • \$\begingroup\$ 00 is 0b00000000 ? that what confused me:) thanks man \$\endgroup\$ Oct 25, 2018 at 14:34
  • 3
    \$\begingroup\$ Most often it doesn't actually matter what the master sends while the slave is replying with data words; all that is actually needed are the clock cycles. \$\endgroup\$ Oct 25, 2018 at 16:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.