Hi everyone,
Been trying to use I2C in my acquisition setup but can't figure out what the problem is...
(this is actually extracted from this post http://forum.arduino.cc/index.php?topic=295146.new#new but I think the title doesn't reflect the content anymore so I'm opening a new thread).
I narrowed it to very basic functions that I can't even make work, basically I'm trying to send 4 bytes over I2C (onRequest from a master) and retrieve them and print them to the serial.
Nothing really exotic, isn't it?
Here's the function for the slave that gets called onRequest:
void I2Csend()
{
int p=591;
Wire.write(byte(T[8]));
Serial.println(byte(T[8]));
byte x=lowByte(p);
Wire.write(x);
Serial.println(x);
byte y=highByte(p);
Wire.write(y);
Serial.println(y);
Wire.write(byte(7));
Serial.println(byte(7));
}
And if I look at the console, I do get : 24, 79, 2, 7 (by heart).
And this code on the master reader (that I trigger every 150mS) :
void I2C()
{
if(millis()>TKperiod)
{
TKperiod=millis()+150;
Wire.requestFrom(0x47, 4);
while(Wire.available()>0)
{
T[8]=Wire.read();
h=Wire.read();
l=Wire.read();
m=Wire.read();
T[m]=word(h,l);
}
}
While the I2C on the slave gets requested (since I get the serial.print in the console and they show the right figures), on the Master I get these :
7 255 255 255 0
which is in order : T[8], h, l, m, T[m]
So first of all, it seems the I2C buffer is LIFO and not FIFO (anyone can confirm me on that?).
But also, I really don't understand why only the 7 gets transmitted and none of the others...????
Oh and just one thing : on the slave arduino, there is a delay(100) in the loop due to some conversions from a thermocouple MUX shield that requires it, but as someone pointed out earlier, I2C got it's own hardware so it shouldn't be a problem... right? (seeking confirmation there ;D )
Thanks for your help!
Marc