2

For a project I'm using 2 Arduino Uno's, where Arduino#1 (master) sends raw data to Arduino#2 (slave). The slave should receive and encrypt the data and afterwards send the encrypted data back to the master. I'm building my project from the sketch found at arduino.cc.

How can I make the slave send back data, if he's the only one listening on incoming data, should both arduinos be listening to each other, and how to achieve this?

1 Answer 1

1

The I2C protocol is both read and write. Master/Slave depends on who initiates the communication. Typically the master will issue a read command to the slave to retrieve the results.

Cheers!

5
  • As the master I can use beginTransmission() and write() to send, and requestFrom() to receive, am I right? and on the slave side I use 2 eventhandlers for this, right?
    – Edito
    Feb 18, 2016 at 10:08
  • Yes that is correct! All transmissions are initiated by the master with write() to send to the slave, and requestFrom() to read. Feb 18, 2016 at 10:32
  • Thanks, that works now, only challenge now is to predict how long the return message is going to be. i.e. I use requestFrom(8,50) and the return message is 40 chars long instead of 50 then it gets filled with strange chars.
    – Edito
    Feb 18, 2016 at 10:40
  • Typically you would have a number of "commands" or "registers" that you would issue or read from. One might be "Get buffer length" which returns the number of bytes in the "message" that are available for reading. Then you use that to get the right number of bytes. So it's "Get Buffer Length => 40 => Get Buffer(40) => 40 chars"
    – Majenko
    Feb 18, 2016 at 10:45
  • I think the transmission size is limited to 32 bytes in the Arduino AVR Wire I2C driver implementation. Obviously there is no such limitation in Cosa :). Feb 18, 2016 at 11:35

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.