An issue about using Arduino Due reading and writing EEPROM

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;
}

Hi yb273,

Are you using the 24LC256/512 EEPROM in a MSOP package?

In the MSOP package option the address lines A0 and A1 are not connected.

ybs273:
Does anyone meet this issue before?

You haven't said what the issue is... :confused:

I use the 24LC256/512 EEPROM in a SOIC-8 package.

The issue is: When I connect A2 A1 to 3.3V, A0 to Ground. I can both 0x56 and 0x 57 to Write and read this EEPROM. It suppose to be only works for address 0x56.
Thanks a lot!

Oh, I see. Your test code doesn't identify the device, so how do you know one device is using two addresses?

Do you have manufacturer part numbers for the devices, because they can be slightly different?

Hi ybs273,

I ran a small test, first with the Arduino Uno and then the Due connected to a 24LC256 EEPROM in a DIP package.

In both cases the results were consistent with the datasheet, in that A0 is used to correctly address the device.

Here's the test code:

#include <Wire.h>    
 
void setup(void)
{
  Serial.begin(115200);
  Wire.begin();  
  writeEEPROM(0, 123);
  Serial.print(readEEPROM(0), DEC);
}
 
void loop(){}
 
void writeEEPROM(unsigned int eeaddress, byte data) 
{
  Wire.beginTransmission(0x56);
  Wire.write((int)(eeaddress >> 8));   // MSB
  Wire.write((int)(eeaddress & 0xFF)); // LSB
  Wire.write(data);
  Wire.endTransmission();
 
  delay(6);
}
 
byte readEEPROM(unsigned int eeaddress) 
{
  byte rdata = 0xFF;
 
  Wire.beginTransmission(0x56);
  Wire.write((int)(eeaddress >> 8));   // MSB
  Wire.write((int)(eeaddress & 0xFF)); // LSB
  Wire.endTransmission();
 
  Wire.requestFrom(0x56, 1);
 
  if (Wire.available()) rdata = Wire.read();
 
  return rdata;
}

The readEEPROM() function returns 123 (decimal) when the 24LC245 is addressed correctly, otherwise it returns 255.