How to use 24FC1025

Hi, I made this code:

/* 
 
  #include <Wire.h> //I2C library


  void i2c_eeprom_write_byte(unsigned int eeaddress, byte data ) {
    int rdata = data;
    Wire.beginTransmission(0xA0);
    Wire.send((int)(eeaddress >> 8)); // MSB
    Wire.send((int)(eeaddress)); // LSB
    Wire.send(rdata);
    Wire.endTransmission();
    delay(5);
  }
  
  byte i2c_eeprom_read_byte(unsigned int eeaddress ) {
    byte rdata = 0xFF;
    Wire.beginTransmission(0xA0);
    Wire.send((int)(eeaddress >> 8)); // MSB
    Wire.send((int)(eeaddress)); // LSB
    Wire.endTransmission();
    Wire.requestFrom(0xA1,1);
    if (Wire.available()) rdata = Wire.receive();
    return rdata;
  }

  void setup() 
  {
    delay(2000);
    char somedata = 'C'; // data to write
    Wire.begin(); // initialise the connection
    Serial.begin(9600);
    i2c_eeprom_write_byte(0,somedata); // write to EEPROM 

    delay(10); //add a small delay

    Serial.println("Memory written");
  }

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

    Serial.print((char)b); //print content to serial port
    Serial.println(" ");
    delay(2000);

  }

but it does not function. I read something here: Electronics: A micro-controller 24FC1025 EEPROM is a single integrated circuit

datasheet: http://docs-europe.electrocomponents.com/webdocs/0db5/0900766b80db5902.pdf

Thank’s all!!

but it does not function.

What does it do that you don't want it to do? What does it not do that you want it to do?

This is a simple test sketch to see if I can write and read correctly data on EEPROM, but I read always "y"

The code you posted starts off with an open comment marker. There is no matching close comment marker. That makes all the "code" you posted a comment, which won't do anything, including compile.

Posting non-working code seems useless.

The y you are printing is actually a y with two dots over it, right? The y with the two dots is what you get when you print a character variable that contains the value 255 (0xFF), which is the value you return from your function when there is no reply from the device.

Your function to read a byte should not return a byte. Doing so means that there is no way for you to return an error flag, because every value that fits in a byte is a valid value.

Instead, the read function should return an int. Then, return -1 if the function fails, and the byte read, in the int, if it succeeds.

As to why the read fails, I have no idea.

PaulS: The code you posted starts off with an open comment marker. There is no matching close comment marker. That makes all the "code" you posted a comment, which won't do anything, including compile.

Posting non-working code seems useless.

Sorry, it was a drag and drop mistake

The y you are printing is actually a y with two dots over it, right?

Yes

The y with the two dots is what you get when you print a character variable that contains the value 255 (0xFF), which is the value you return from your function when there is no reply from the device.

Your function to read a byte should not return a byte. Doing so means that there is no way for you to return an error flag, because every value that fits in a byte is a valid value.

This is what I think

Instead, the read function should return an int. Then, return -1 if the function fails, and the byte read, in the int, if it succeeds.

As to why the read fails, I have no idea.

The EEPROM memory need appropriate programming. I have read the datasheet, something on the web, I tried to follow instructions, but without result!!

I find some post of similar EEPROM

http://arduino.cc/forum/index.php/topic,46914.0.html http://arduino.cc/forum/index.php/topic,12413.0.html http://arduino.cc/forum/index.php/topic,19158.0.html

The Wire Library uses the 7 bit version of the address, and adds the 0 or 1 eighth bit based on whether you are reading or writing.

Therefore, instead of using 0xA0 and 0xA1 use 0x50 in both beginTransmission and requestFrom.

I know this is a dead thread, but I came across it, had the same problem, realized I should actually read the arduino documentation.

I'm having a slight problem. The chip has 128Kbytes and according to the data sheet, and other comments, needs to be addressed as two chips. I've got the first 64Kbytes working fine at address 0x50, but what is the address for the next 64Kbytes ? I've tried 0x51, 0x52, 0x54 and 0x58 and none seem to work. The data sheet gives the chip address word as

| 1 | 0 | 1 | 0 |A16| C | C |R/W|

hence my original (failed) guess of 0x54

here is the code I'm using to initiate both read and write ...

byte I2Cram_begin(long addr) {
  byte id = (addr & 0x00010000)? 0x54: 0x50;
  int alo = addr & 0x0000FFFF;
  Wire.beginTransmission(id);
  Wire.write((int) highByte(alo));
  Wire.write((int) lowByte(alo));
  return id;
}

Incidentally, with version 1.0.1, does the Wire library now support more than a 32 byte burst ? And does someone have a code fragment showing the protocol for writing a burst: it would be nice to be able to use the full 128byte buffer (mentioned elsewhere in these fora).

This is the kind of thing I really hate. For background, I've been using Margolis' Arduino Cookbook (ISBN 978-1-449-31387-6): a really handy reference. There on page 437 is a neat diagram showing how to tie pins A0-A2 to ground to get address 0x50. BUT... if you check out the data sheet it tells you to tie A2 to Vcc, otherwise it doesn't work. Well, it didn't and now I've read the data sheet carefully, it does. As all good engineers say: RTFM.

Got the I2C memory working fine one byte at a time, but can't figure out exactly how to read and write 32 bytes at a time... is there an example somewhere ?