Well I can't reproduce your problem. I changed the two defines I mentioned, and then amended your code slightly. This is the slave:
#include <Wire.h>
#define I2C_Address 2
char command;
char buf [131] = "";
void setup()
{
Wire.begin(I2C_Address);
Wire.onRequest(requestEvent);
Wire.onReceive(ReceiveCommand);
for (int i = 0; i < 13; i++)
strcat (buf, "0123456789");
}
void loop()
{
if(command == 'C')
{
command = 'N';
}
}
void ReceiveCommand(int howMany)
{
command = Wire.receive();
}
void requestEvent()
{
Wire.send ((uint8_t*) buf, 128);
}
And this is the master:
#include <Wire.h>
#define I2C_Address 2
#define AMOUNT 128
void setup(){
Wire.begin();
Serial.begin(115200);
}
void loop(){
Wire.beginTransmission(I2C_Address);
Wire.send('C');
Wire.endTransmission();
delay(200);
Wire.requestFrom(I2C_Address, AMOUNT);
if (Wire.available () == AMOUNT)
{
for ( int i=0; i<AMOUNT; i++ )
Serial.print(Wire.receive(), BYTE);
}
else
Serial.println (Wire.available (), DEC);
Serial.println();
}
And this is the debug output:
01234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567
01234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567
01234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567
01234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567
01234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567
As you can see, 128 bytes of the correct data.
From your code:
void loop(){
Wire.beginTransmission(2);
Wire.send('C');
Wire.endTransmission();
delay(200);
Wire.beginTransmission(2);
Wire.requestFrom(2,40);
for ( int i=0; i<40; i++ ) Serial.print(Wire.receive());
Serial.println();
}
The second Wire.beginTransmission is not correct - you don't do another beginTransmission before a requestFrom.