0

I hope you can help me :)

I am communicating between Raspberry Pi 3 and Arduino Uno with SPI. I am using the Arduino as slave and it works pretty fine. The only problem that i have, is the following:

For receiving data from the Arduino, my Raspi sends a byte. But i always have to send 2 bytes for the correct response. Is it even possible for the Arduino to response on the first byte?

Sorry for my english

  • Can you please post the full code you're using? – Avamander Jul 19 '17 at 12:06
1

Because of the way SPI works, the slave cannot respond to the first byte in a meaningful way. It can send something (eg. 0x00) but not a response.

See my page about SPI. During an SPI transfer each bit is sent, and a bit received, simultaneously, as in this graphic:

SPI transferring bits

You can see that as the first bit is received by the slave, it also has to send a response. There is no way that this response can react to the 8 bits, 7 of which haven't been received yet, by the time it has to send the first bit of response.

But i always have to send 2 bytes for the correct response.

You don't have to send 2 bytes all the time. For example, you can send one byte (eg. "send me the temperature") and then send zeroes after that, while you read back a (say) 4-byte temperature. So in this case you send 5 bytes to get a 4-byte response.

0

The only way you can respond on the first byte is if the Arduino already knows, and is primed, what to send on that byte before it begins to be clocked into the Arduino.

It is normal to have to send at least 2 bytes - the first is often used as either a register address, or a "read register" command.

0

Is it even possible for the Arduino to response on the first byte?

Yeah. There is nothing preventing your slave to respind on the first byte, so long as your code allows it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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