PDA

View Full Version : Wire/I2C doesn't allow more than 32 bytes written at one time (24LC1026 problem)



el_supremo
01-30-2013, 01:35 AM
I've spent much of today trying to figure out why I couldn't erase a 24LC1026 eeprom properly. The abbreviated story is that the page size on those eeproms is 128 bytes and the chip can handle 128 bytes in one begin/end transmission cycle so I was writing 128 bytes in one go. But it only ever erased the first 32 bytes of each page.
I thought it was a timing issue but it finally dawned on me that the Wire library might be the problem.
Sure enough, in teensy's \arduino-1.0.3\libraries\Wire\Wire.h we have:

#define BUFFER_LENGTH 32
I changed it to 128 and all is now well. The Arduino Wire library also sets the buffer length to 32.

Pete

el_supremo
02-03-2013, 06:36 PM
Boink.
Does anyone know if this is actually a problem or did I miss something obvious in handling I2C?
The reason I wanted to use a write of 128 chars in one go is that whether you write one byte or all 128 bytes to a page, the 24LC1026 will refresh the whole page. So if I write the 128 byte page in 4 blocks of 32bytes it means that the page will be refreshed 4 times instead of once.

Pete

Jp3141
02-03-2013, 07:44 PM
Boink.
Does anyone know if this is actually a problem or did I miss something obvious in handling I2C?
The reason I wanted to use a write of 128 chars in one go is that whether you write one byte or all 128 bytes to a page, the 24LC1026 will refresh the whole page. So if I write the 128 byte page in 4 blocks of 32bytes it means that the page will be refreshed 4 times instead of once.

Pete

Perhaps it is partial compatibility with SMBus which only allows 32 byte transfers ?

el_supremo
02-03-2013, 10:23 PM
The Arduino code is also 32 bytes and I suspect that it was chosen partly because of the limited sram on Arduinos and when the code was first written perhaps EEPROMs and other I2C devices couldn't do 128 bytes at a time anyway.
In my wire.h I have changed the code to this:

#if defined(__MK20DX128__)
#define BUFFER_LENGTH 128
#else
#define BUFFER_LENGTH 32
#endif



Pete