I'm trying to interface the arduino with a microchip 24LC00, and I'm getting screwy results.
Here is an example of my code (I have everything in the setup() method because I only need the info once):
#include Wire.h
#define CHIP B1010000
void setup()
{
Wire.begin();
Serial.begin(115200);
Wire.beginTransmission(CHIP);
Wire.send(0); // moving to memory pointer to address 00
Wire.endTransmission();
Wire.requestFrom(CHIP, 16);
while(Wire.available())
{
char c = Wire.receive();
Serial.print(c, DEC);
Serial.print(", ");
}
Serial.println();
}
}
This is all well and good, and I get the following output in my Serial window:
0, 0, 0, 5, 5, 5, 10, 10, 10, 15, 15, 15, 20, 20, 20, 25
Which is also all well and good.
The problem raises its ugly head when I try to write AND read the chip. When I add the following code after the Serial.begin(115200); line:
Wire.beginTransmission(CHIP);
Wire.send(0); // moving the pointer to 00
Wire.send(2);
Wire.send(2);
Wire.send(2);
Wire.endTransmission();
I get the following gibberish on my Serial window:
0, 2, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
Stranger still - if I remove the code that writes to the device, and only read from it I now get:
0, 0, 0, 2, 2, 2, 10, 10, 10, 15, 15, 15, 20, 20, 20, 25
It is as though the write operation succeeded but somehow corrupted the subsequent read operation, but I have no idea how.
Any and all assistance would be appreciated.