Hello all, I have a problem with using the wire library. I have an arduino mega talking to an arduino mini via I2C, I'm using arduino-0022.
If I beginTransmission, send a byte and endTransmission, my requestFrom returns all wrong data (mostly FF).
If I don't send the byte, the requestFrom works fine. I can fix it by adding in an extra endTransmission and delay, but I don't see other people doing this.
Any ideas? Thanks!
#include "Wire.h"
byte message[9];
#define FAIL
//#define FIX
void setup()
{
Wire.begin();
Serial.begin( 9600 );
Serial.println( "started" );
delay( 1000 );
}
void loop()
{
#ifdef FAIL
Wire.beginTransmission(4); // transmit to device #4
Wire.send(1);
byte status = Wire.endTransmission();
if( status != 0 )
Serial.println( "i2c problem" );
delay( 500 );
#endif
#ifdef FIX
Wire.endTransmission();
delay(50);
#endif
Wire.requestFrom(4, 9);
delay( 20 );
int i = 0;
while(Wire.available())
{
message[i++] = Wire.receive();
Serial.print(message[i],HEX); //this prints
Serial.print(",");
}
Serial.println();
delay( 500 );
}