Go Down

Topic: Better 24LC256 EEPROM Read/Write library? (Read 1 time) previous topic - next topic

WilliamK Govinda

Guys, I'm using the 24LC256 EEPROM on a project, but the 2Wire (TWI) library uses a fixed 5ms delay for each byte write, which slows down the whole process up. The chip datasheet explains that you can check to know if the chip finished up the write process, instead of just waiting a fixed time. This would help me out a lot, as it would speed up the whole thing up. Not to mention that the chip can handle 400khz, not just 100khz as stated in the TWI library. The idea is to make a small lib that reads and writes single bytes, or 64 bytes as it already does right now, making it easier to update the code with the product.

If you want to know what the project is, just follow my signature. ;-)

And thanks for any help in advance.  8)

Best Regards, WilliamK @ Wusik Dot Com

WilliamK Govinda

Here's the code I'm currently using with the Wire Library.

Code: [Select]
void writeEEPROM(int deviceaddress, unsigned int eeaddress, byte data )
{
  Wire.beginTransmission(deviceaddress);
  Wire.send((int)(eeaddress >> 8));   // MSB
  Wire.send((int)(eeaddress & 0xFF)); // LSB
  Wire.send(data);
  Wire.endTransmission();
  delay(5);
}
byte readEEPROM(int deviceaddress, unsigned int eeaddress )
{
  byte rdata = 0xFF;
  Wire.beginTransmission(deviceaddress);
  Wire.send((int)(eeaddress >> 8));   // MSB
  Wire.send((int)(eeaddress & 0xFF)); // LSB
  Wire.endTransmission();
  Wire.requestFrom(deviceaddress,1);
  if (Wire.available()) rdata = Wire.receive();
  return rdata;
}

WilliamK Govinda

Actually, by thinking it over again, what I really need is to change the code above and add a check for "is the write process done" instead of the 5ms delay. That would resolve my latency problems. ;-)

Wk

marcdavidson

William,
What does your "write check" look like?
Thanks

WilliamK Govinda

Actually, after reading the EEPROM Chip 24LC256 Datasheet, it turns out that sending one byte or 64 bytes takes the same 5ms delay to write. So, I used the TWI lib to send 64 bytes and them I wait 5ms. Now its 64 times faster. ;-)

Wk

Go Up