Loading...
Pages: [1]   Go Down
Author Topic: I2C EEPROM Class on playground  (Read 3452 times)
0 Members and 1 Guest are viewing this topic.
Netherlands
Offline Offline
Tesla Member
***
Karma: 101
Posts: 9551
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset


While experimenting with an I2C EEPROM I encountered the problem that the Wire library only wrote in (relative) small chunks to EEPROM so I wrote a simple library to write and read objects of "any" size to an I2C EEPROM. The EEPROM used was a 24LC256 but it should work with other too (not confirmed).

The library and a small example can be found on - http://arduino.cc/playground/Main/LibraryForI2CEEPROM - and as allways remarks, comments and improvements are welcome.

Rob
Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -

Global Moderator
Melbourne, Australia
Offline Offline
Shannon Member
*****
Karma: 226
Posts: 14097
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I just want to draw to your attention that the 24LC256 "wraps around" its internal addressing on 64-bytes boundaries. So for example, if you write 4 bytes to address 62, it actually ends up writing to 62, 63, 0 and 1.

So any code that attempts to write "large buffers" needs to address this, otherwise you need to add a warning that not only can it simply not write more than 64 bytes at a time, it has to not cross a 64-byte boundary. So in my example, even writing 3 bytes to address 62 would not work as expected.

I should also point out that your test program writes 102 bytes to the chip, and then reads it back into a 100-byte array - so that is going to overwrite memory somewhere.

In principle the library is a great idea, you just need to handle the wrapping issue.
Logged


Netherlands
Offline Offline
Tesla Member
***
Karma: 101
Posts: 9551
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 Nick,

thanks for this insight, I will dive into it and come asap with an updated version. I understand that in my sample code I started at address 0 with chuncks of 16 which is a divider of 64 so it worked by accident.

Do you know if other EEPROMS have similar issues?

wrt the test program, it only reads 40 bytes from memory into the 100 byte buffer, but its a risk youre right.
« Last Edit: February 11, 2011, 03:28:46 am by robtillaart » Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -

Netherlands
Offline Offline
Tesla Member
***
Karma: 101
Posts: 9551
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Updated the code to be 1.0 compatible (Thanks Craig)

See - http://playground.arduino.cc//Main/LibraryForI2CEEPROM - for the latest version,

As always comments and improvements are welcome,
Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -

Pages: [1]   Go Up
Print
 
Jump to: