Question on EEPROM

I have a 4Kbits EEPROM, and I am trying to interface the EEPROM with teensy 3.2.

The datasheet I used can be found here.

My hardware connections are as follow.

teensy <-----------> EEPROM
+3.3V <-----------> VCC
GND <-----------> GND
GND <-----------> A0
GND <-----------> A1
GND <-----------> A2
GND <-----------> WP
SDA <-----------> SDA
SDL <-----------> SDL

I tried using a code to interact with the EEPROM through the I2C interface.

My code used are as follows:

#include <Wire.h>

int i2c_eeprom_read_byte( int deviceaddress, unsigned int eeaddress ) {
    int 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;
}

void setup()
{
    Wire.begin(); // initialise the connection
    Serial.begin(9600);
}

void loop()
{
    int addr=0; //first address
    int b = i2c_eeprom_read_byte(0x50, 0); // access the first address from the memory

    while (addr!=512)
    {
        Serial.print(b); //print content to serial port
        addr++; //increase address
        b = i2c_eeprom_read_byte(0x50, addr); //access an address from the memory
    }
    Serial.println(" ");
    delay(2000);
}

However, I am only getting 255 printed from all location of the EEPROM. I am quite certain that the EEPROM contain data in it.

I checked through the code, and is not able to pinpoint any reason for the print out.
May I seek your opinion on what may be causing this program to only print 255.

Thank you.

Do you have a hard copy record of the data that are present in your EEPROM? If not, perform read-after-write verification -- write 0x75 into location 0x0000; read it back and display on Serial Monitor.

Have you run the i2c bus scan sketch to verify you are successfully talking to the EEPROM?

GolamMostafa:
Do you have a hard copy record of the data that are present in your EEPROM? If not, perform read-after-write verification -- write 0x75 into location 0x0000; read it back and display on Serial Monitor.

Hi I would like to do a read to backup the EEPROM before I do any modification to the contents. Thanks for your suggestion, but I am unable to do any modification to the EEPROM currently due to the need of backup.

You have said that the EEPROM contains data; but, what data you don't know. You have no hard copy of the data, then how are you going to decode the binary codes (if any in the EEPROM) to be read from the EEPROM?

Please, tell the type number of your EEPROM.

GolamMostafa:
You have said that the EEPROM contains data; but, what data you don't know. You have no hard copy of the data, then how are you going to decode the binary codes (if any in the EEPROM) to be read from the EEPROM?

Please, tell the type number of your EEPROM.

Hi, the EEPROM is 24c04a.

The datasheet is here.

Hope that there is no useful data at location 0x01FF (511) of the EEPROM. If so, try to write a data byte (say: 0x75) at this location and read it back. This is to verify that your setup and coding are correct. In the meantime, you can execute the following codes to check that the chip is seen by UNO.

Wire.beginTransmission(0x50);
byte busStatus = Wire.endTransmission();
if(busStatus !=0)
{
   Serial.print("The chip is not found...!"(;
   while(1);  //wait for ever
}
Serial.print("The chip is found.");

GolamMostafa:
Hope that there is no useful data at location 0x01FF (511) of the EEPROM. If so, try to write a data byte (say: 0x75) at this location and read it back. This is to verify that your setup and coding are correct. In the meantime, you can execute the following codes to check that the chip is seen by UNO.

Wire.beginTransmission(0x50);

byte busStatus = Wire.endTransmission();
if(busStatus !=0)
{
  Serial.print("The chip is not found...!"(;
  while(1);  //wait for ever
}
Serial.print("The chip is found.");

Hi,

let me update you what I have tried.

I tried you scanner code, and it returned 0x50 as expected.

I also tried to use the I2C scanner here here.

Apparently, there is some weird result from the I2c scanner.

It returns more than 1 address, when I am should only get 0x50. I am not really sure why this happen, is there something wrong with the library used or is it a normal result? Example

i2c scanner. scanning ...
Found address : 80(0x50)
Found address : 81(0x51)

I also tried to command out the MSB Wire.write((int)(eeaddress >> 8)); // MSB in the 2c_eeprom_read_byte function, and the code is able to print some value other than FF.

int i2c_eeprom_read_byte( int deviceaddress, unsigned int eeaddress ) {
    int 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;
}

Now, I starting to doubt if i am actually coding the read function accordingly to the datasheet. Is there a start/stop bit that is missing somewhere, or is there some bits that I am not inputting in? Is my code wrong? Any thoughts on this is greatly appreciated. Thank you.

Nick_Jensen:
It returns more than 1 address, when I am should only get 0x50. I am not really sure why this happen, is there something wrong with the library used or is it a normal result? Example

i2c scanner. scanning ...
Found address : 80(0x50)
Found address : 81(0x51)

Please, follow this description to know why you are getting four I2C addresses: 0x50, 0x51, 0x52, 0x53.
1. The following diagram (Fig-1) depicts the organizational structure of 24C04 EEPROM.
24c04.png
Figure-1:

2. The EEPROM is organized as 4 blocks: BLK-0, BLK-1, BLK-2, and BLK-3. Each block as its own I2C address; that's why the scanner finds 4 addresses.

3. Each block is composed of 8 pages; each page is again composed of 16 byte oriented locations.

4. Now, upload the following sketch to see what data you are getting from 16 locations of Page-0 of BLK-0.

#include<Wire.h>
byte memAddrs = 0;
byte x;

void setup()
{
    Serial.begin(9600);
    Wire.begin();
    //------------------------
    Wire.beginTransmissiom(0x50);
    Wire.write(memAddrs);              //pointing 1st location of Page-0 of BLK-0
    Wire.endTransmission();
    //---------------------------------
    byte m = Wire.requestFrom(0x50, 16);  //requesting 16-byte data from EEPROM (00 - 0F)
    for(byte i=0; i<m; i++)
    {
       x = Wire.read();
       if(x <0x10)
       {
          Serial.print('0');     //shows: leading 0 on Serial Monitor
       }
       Serial.print(x, HEX);
       Serial.print(' '):        //insert space
    }   
}

void loop()
{

}

Please, post the data that you have got from the EEPROM after executing Step-4.

If you have any more query on the 24C04 EEPROM (say; the functions of A2, A1, A0 signals), do not hesitate to ask.

24c04.png