Pages: [1]   Go Down
Author Topic: Better 24LC256 EEPROM Read/Write library?  (Read 1263 times)
0 Members and 1 Guest are viewing this topic.
Brazil
Offline Offline
God Member
*****
Karma: 3
Posts: 616
Wusik Dot Com
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.  smiley-cool

Best Regards, WilliamK @ Wusik Dot Com
Logged


Brazil
Offline Offline
God Member
*****
Karma: 3
Posts: 616
Wusik Dot Com
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Code:
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;
}
Logged


Brazil
Offline Offline
God Member
*****
Karma: 3
Posts: 616
Wusik Dot Com
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged


0
Offline Offline
Newbie
*
Karma: 0
Posts: 14
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Brazil
Offline Offline
God Member
*****
Karma: 3
Posts: 616
Wusik Dot Com
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged


Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 211
Posts: 13531
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset


Hi William,

You can only write 64 bytes at once if they are all in the same page or the address counter will wrap around !!  I tackled this issue in my EEPROM lib - http://arduino.cc/playground/Main/LibraryForI2CEEPROM -  In the lib I used a blocksize of 16 to keep the footprint [internal buffer] rather small, but it could be 32 or 64. Finally the lib also takes care of writes larger than pagesize automatically.

These features might be usefull.

Rob



Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Brazil
Offline Offline
God Member
*****
Karma: 3
Posts: 616
Wusik Dot Com
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Ah, indeed, sorry I forgot to mention that. In my code I have a 132 byte buffer, as for reading there's no limitations, and for writing I always write in blocks of 64 bytes anyway. ;-)

Wk
Logged


Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 211
Posts: 13531
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
and for writing I always write in blocks of 64 bytes anyway
And you allways start at page boundaries ?  132 is not a multiple of 64?
« Last Edit: July 04, 2011, 12:59:15 pm by robtillaart » Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Brazil
Offline Offline
God Member
*****
Karma: 3
Posts: 616
Wusik Dot Com
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Yes, 0, 64, 128, ... I forgot to mention that too.  smiley-red

Wk
Logged


Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 211
Posts: 13531
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

OK that makes life quite a bit easier smiley-wink
Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Pages: [1]   Go Up
Jump to: