Wire Library 32 byte limit

I started to mess around with the Wire library, and quickly noticed that there's a 32 byte limit.

Looking at Wire.h, right off the bat there's:

#define BUFFER_LENGTH 32

Can I just boost that up? I'd guess it affects things between a start and end transmission, but without an 'offset' parameter, I can't even write further into the memory, AFAIK.

It seems that even if I change the buffer (do I need to recompile the library somehow?) I would still be limited to 255 bytes by the code which has uint8s everywhere. But I have 2k EEPROMs to read!

Is this just not a library I can use? Seems like I need at least a 16 bit offset.


Bruce Wheaton

Dont tell me your trying to read all 2k in one go? The Arduino's RAM is only 1k.

You should be reading in smaller chunks. Preferably only what you need.

Well, the wire documents say that they can read 255 bytes per, but it's actually 32. The problem is, that's 32 ever, ever. The next read will get that same 32. So, one fix would be to increase that. I'm not sure if the extra 200 odd bytes would be a big memory problem.

Meanwhile, it seems that I2C EEProms have an extra write cycle that prefaces a read or write to set the base for subsequent actions. I'm not 100% sure, but that doesn't seem to be a standard write, so it would need to happen in the lib.

Does the lib need to be re-compiled after changes? How would I add an extra method/function?


Atmega168 has 1kbyte SRAM which is very scarce... You have to be careful! Changing that 32 bytes to much more might eat up too much useful RAM. But I think you could change it to be a bit bigger.

About the I2C EEPROM, I have some code/functions here. Actually, you can only write 30 bytes, because 2 bytes are the offset. http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1192425904/3#3

For other types of flash, look in the Playground/wiki (Dataflash)

Great, that looks like it would do it. I could find all the stuff about the 2 byte address up front, but it looked like out of band data, not just a couple of bytes up front (albeit one pushed out of the ASCII range).

Thanks John