I'm pretty sure it's a minor mistake I've done, but I couldn't figure it out. I'm trying to use an M24256 EEPROM with Arduino Mega2560 via I2C protocol. The datasheet states that the address is 1010(E2)(E1)(E0)(R/W). I left all E pins unconnected, which means it should be A0 for writing and A1 for reading. I grounded the /WC pin so it's not write protected. I checked the device with the I2C scanner sketch and for some reason it was seen as 0x50. What's strange that I can read from it by using any address (I tried 0x50, 0xA1 and some random addresses), but I can't write to it - every time I get the default 0xFF as readback.
The code I tried:
#define memoryRead 0xA0
#define memoryWrite 0xA1
byte in=0x00;
#include <Wire.h>
void setup() {
Serial.begin(9600);
Wire.begin();
Serial.println("writing");
for(int i=0;i<100;i++){
Wire.beginTransmission(memoryWrite);
Wire.write(byte(i >> 8)); // first the MSB (8-bits)
Wire.write(byte(i));
Wire.write(byte(i));
Wire.endTransmission();
}
Serial.println("reading");
Wire.beginTransmission(memoryWrite); //this should be resetting the pointer //to 0 if I got it well from the datasheet
Wire.write(0x00);
Wire.write(0x00);
Wire.beginTransmission(memoryRead);
for(int i=0;i<100;i++){
in=Wire.read();
Serial.println(in,HEX);
}
Wire.endTransmission();
Serial.println("done");
}
void loop() {
}
What am I doing wrong? I double checked the wiring and the write protection, so it must be code.
Thanks in advance.