Arduino Stack Exchange is a question and answer site for developers of open-source hardware and software that is compatible with Arduino. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|improve this question
    
Please post the code that doesn't work. – Gerben Mar 6 '15 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 Mar 6 '15 at 22:03
up vote 2 down vote accepted

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.

share|improve this answer
    
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 Mar 7 '15 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 Mar 8 '15 at 15:04
    
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 Jun 28 '15 at 22:32

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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