Ask to change the i2c buffer size

Hi, Friends,

i have question to about i2c buffer size on Mega.

i want to i2c buffer size to 256. but... can't

show to down.

Wire.beginTransmission(i2cAddr);
  Wire.write(byte(0x00 & 0xff));
  Wire.write(byte(0x00 & 0xff));
  for(int i = 0; i < 256; i++)
  {
    Wire.write(byte(i & 0xff));
  }
  Wire.endTransmission();
  delay(20);

if i input "256" arduino buffer send data to 0xfe, 0xff.

so i find library (="Wire" library), that funtion is 'uint8_t'...

i think to have to change to funtion.

but i can't. (i don't know method, i changed funtion , but continue appear error... T.T)

could you help me that solve problem?

Welcome to the forum.

Why do you want to do that ?
I hope you are not trying to use the I2C bus to send data to a Raspberry Pi for example.

There is a function that tells how many free spots are available: Wire.availableForWrite().
The basic Arduino boards have a buffer of 32 bytes.
Most newer boards (such as the MKR Zero) have a buffer of 256 bytes.

It is possible to change the library and make it 256 bytes, but then you have to do that every time that you update the Arduino IDE.
You could also copy the files of the Wire library into your project, but then you don't get the bug fixes with a new version of the Arduino IDE.
You might also run into memory problems, because there is not a single buffer, but a few.

Look for the define for the buffer length, they are here and here. Please don't change them :pleading_face:

One solution would to create your own buffer. Then modify your read loop every say 16 bytes and move them into your buffer. This is much simpler and easier to maintain.

The I2C Master library allows you to set the buffer to any size you like.

So you can use that.

Why do you want to have a buffer of 256?
You code shows you try to send 1+1+256 = 258 bytes.

if you check the links from Koepel you will see that the library internally initializes a RX and a TX buffer with the same #define. So if you rise the buffer from 32 (*2) to 258(?) * 2 you will block 452 additional memory.

Do you believe your code will be stable with this add on?

Follow the advice from @gilshultz.

Dear Friend, Thank you for advice to me.
anyway, i test change library to "270", but same problem.


that can be try 253byte. but more byte, can't
please more advice to me.
thank you.


++add arduino firmware download warning.

i think so too.
but, i can't to edit library code.
can you teach me? i supposed to change the "uint8" code...
but, i change the code... all situation appear error... T.T

Can you tell us why you want to do this ?
What is your project about ?

Do you want more speed ? Then you could increase the clock to 400kHz.

Hi, Koepel,
Sorry i late reply your question.
i test to write data in EEPROM.
i2c write process is "Slave Addres + Data", but i test "Slave Address + Data1 + Data2 + ... + DataN".
that process is more reduce the time to same clock speed.
and i want to know to arduino limits.
i test 255(Address High&LOW&Data253) is good, but i setting to more is error.
so i find solution.

Why not?
There is a variable that holds the number of bytes in the buffer. This even on the master library ( have you got that then ) you have to change this variable to an int ( a 16 bit one).

Dear Mike,
i back up wire.h and test change the code.
but at that firmware compile, continue error.
if you guide to me that 16bit, but that's error.
so i don't know how edit wire.h file.

your right, but i don't know how to make library...;;;

No need for a library, create it in your program variable space.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.