I tried using the example program of EEPROM writing and reading my own EEPROM.
I have two EEPROM on my boards, one of them is 24LC512, the PIN address A2A1A0 is set as 110;
the other is 24LC256, the PIN address is set as 111. I used the following code to test them.
However, I found I can use the address 0x56 and 0x 57 to Write and read either of them. it seems that the A0 has no use in address setting.
Does anyone meet this issue before? I read the manual of EEPROM carefully, but I can not find the answer for them.
#include <Wire.h>
#define disk1 0x56 //Address of 24LC256 eeprom chip in Board
//#define disk1 0x57
unsigned int i;
unsigned int address;
unsigned int datain;
void setup(void)
{
Serial.begin(9600);
Wire.begin();
for (i=1;i<20;i++)
{
address = i;
datain = 2*i;
writeEEPROM(disk1, address, datain);
}
//Serial.print(readEEPROM(disk1, address), DEC);
}
void loop()
{
for (i=1;i<20;i++)
{
address =i;
Serial.print(readEEPROM(disk1, address), DEC);
}
Serial.println("end");
delay(1000);
}
void writeEEPROM(int deviceaddress, unsigned int eeaddress, byte data )
{
Wire.beginTransmission(deviceaddress);
Wire.write((int)(eeaddress >> 8)); // MSB
Wire.write((int)(eeaddress & 0xFF)); // LSB
Wire.write(data);
Wire.endTransmission();
delay(5);
}
byte readEEPROM(int deviceaddress, unsigned int eeaddress )
{
byte rdata = 0xFF;
Wire.beginTransmission(deviceaddress);
Wire.write((int)(eeaddress >> 8)); // MSB
Wire.write((int)(eeaddress & 0xFF)); // LSB
Wire.endTransmission();
Wire.requestFrom(deviceaddress,1);
if (Wire.available()) rdata = Wire.read();
return rdata;
}