Two wire I2C and st eeprom

Dear,

I ame trying programming a st eeprom M24LR16Ehttp://www.google.fr/url?sa=t&rct=j&q=M24LR16E&source=web&cd=2&cad=rja&ved=0CC4QFjAB&url=http%3A%2F%2Fwww.st.com%2Finternet%2Fcom%2FTECHNICAL_RESOURCES%2FTECHNICAL_LITERATURE%2FDATASHEET%2FDM00031737.pdf&ei=aixbUM2iA6mg0QXw2oHoCA&usg=AFQjCNGlQFduFRDRPHq5eYOdAtwnh9R6tw memory on my arduino uno.

The code of the device right connected on the A4 and A5 pin of the arduino is : 1010 111 R/W.
memory is structured in sector and memory slot are numeroted from 0 to 2048 => So 16-bits adress format.

So the 7bit adress is 0x57. Doesn't it ?

To write data on the chip, according to the datasheet, I need.

  • Starting the communication
  • Sending the 7-bits adres
  • sending the 1 bit read/write : 1 to read, 0 to write
  • Sending the adress (and the data)

I think it is a classical but, I can't read/write anything

My code is like that

#include <Wire.h>

void M24LR16E_read(int adress){
  Wire.beginTransmission(0X57);
    Wire.write((int)(adress >> 8));   // MSB
  Wire.write((int)(adress & 0xFF));
  Wire.endTransmission();

  Wire.requestFrom(0X57,1);

  int c = 0;
  for ( c = 0; c < 1; c++ ){
    if (Wire.available()){ 
      Serial.print(Wire.read());}
  }
 
}

void  M24LR16E_write(int adress){


int ad=2304;

    Wire.beginTransmission(0x57);
    Wire.write((int)(adress >> 8));   // MSB
  Wire.write((int)(adress & 0xFF));
   Wire.write((byte)0xFF);
  Wire.endTransmission();
  }



void setup(){
  Wire. begin();
  Serial.begin(9600); 
}

void loop(){


   M24LR16E_write(0);
   delay(10);
   M24LR16E_read(0);
  
  Serial.print("....\n\r");

  delay(10);
}

Any idea about how read/write correctly in this chip ?

Regards,

GM

Edit: I have 2 10K ohm pull-up resistors on sda and scl. I work with 5 V dc.

"To access the user memory, the device select code used for any I2C command must have the E2 Chip Enable address at 0."

I think that may mean you are supposed to use address 0x53 instead of 0x57.

Hello johnwasser !

Thank your for your reply.

If I change the adress 0x57 to 0x53 I have no reply from my device.

with 0x57

255...
255...
255...

In that case, the write function do not work.
I have already changed my function to integrate the write protection. If I present the password (Redirect Notice)

void  M24LR16E_write(int adress){


int ad=2304;

    Wire.beginTransmission(0x53);
    Wire.write((int)(ad >> 8));   // MSB
  Wire.write((int)(ad & 0xFF));


  Wire.write((byte)0x00);
  Wire.write((byte)0x00);
  Wire.write((byte)0x00);
  Wire.write((byte)0x00);

  Wire.write((byte)0x09);

  Wire.write((byte)0x00);
  Wire.write((byte)0x00);
  Wire.write((byte)0x00);
  Wire.write((byte)0x00);
  Wire.endTransmission(); 
  
    Wire.beginTransmission(0x53);
    Wire.write((int)(adress >> 8));   // MSB
  Wire.write((int)(adress & 0xFF));
   Wire.write((byte)0x00);
  Wire.endTransmission();
  }

But read at adress 0 still reply 255
with 0x53

...
...
...