1

I have been working with the wire library (I2C) to send data from one Arduino to another. I read that the Arduino can only send 6 bytes per cycle, but I have been able to transfer much larger strings. This code works without error:

  Wire.beginTransmission(4); // transmit to device #4

  for(int i = 0; i < 20; i ++){
    char rand = random(65, 100);
    Wire.write(rand); 
  }

  Wire.endTransmission();    // stop transmitting

How is this possible? It seams that 32 characters can be sent without trouble.

I read this here: http://arduino.cc/en/Tutorial/MasterReader

Arduino 1, the Master, is programmed to request, and then read, 6 bytes of data sent from the uniquely addressed Slave Arduino.

Now that I look at this again (after reading the responses) I think that the limit was set in the code sample.

3
  • Please post the code that doesn't work.
    – Gerben
    Commented Mar 6, 2015 at 21:27
  • Can you link to where it says the arduino can only handle 6 bytes per cycle? And, by 'per cycle' I assume you meant between the 'beginTransmission and endTransmission'. I couldn't find reference to the 6 byte limitation in the wire reference ( arduino.cc/en/Reference/Wire )
    – krol
    Commented Mar 6, 2015 at 22:03
  • Can you give the sample code for it Commented Oct 11, 2017 at 11:53

1 Answer 1

3

There is no reason to believe there is a 6 byte limit.

The Arduino Reference makes no mention of a 6 byte limit.

The Wire.cpp defines 'txBuffer[BUFFER_LENGTH];' where BUFFER_LENGTH = 32 (defined in Wire.h). The maximum is 32 bytes, just as you noticed.

4
  • in the wire code examples, the master uses beginTransmission() and endTransmission(), but the slave does not. The slave only uses write(). why is this? How does the Slave know when to end the transmission?
    – Hoytman
    Commented Mar 7, 2015 at 15:40
  • @Hoytman I'm actually not sure why the library handles i2c that way. I would expect that it has its roots in making a generic i2c/twi interface, but I don't understand i2c/twi well enough to give a correct answer.
    – krol
    Commented Mar 8, 2015 at 15:04
  • 1
    In the Wire library, beginTransmission() "primes" (starts) collecting data for a transmission. Then Wire.write() simply adds data to an internal buffer (which is 32 bytes long). Finally the endTransmission() actually does the sending of the buffer. As for the slave, in a "requestFrom" function as soon as you do a Wire.write() it is sent (or at least, it commences to be sent). You cannot (successfully) do more than one. If you attempt to, the second one overwrites the buffer used to return the data to the master.
    – Nick Gammon
    Commented Jun 28, 2015 at 22:32
  • The Arduino Wire implementation is synchronous (blocking) but still requires an intermediate buffer. As the answer about states the buffer is limited to max 32 bytes. This alternative I2C (Two-Wire) library does not have this limit and supports both software and hardware bus manager implementation. github.com/mikaelpatel/Arduino-TWI Device drivers written using this library can be used with the AVR/SAM hardware support or with any GPIO pin. Commented Oct 11, 2017 at 12:42

Your Answer

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

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