
Originally Posted by
Burgerga
I'm getting 258 bytes, not 255 so it would seem that it should be reading the Buffer Length setting correctly but doesn't seem to change when I edit the header.
NUM_LEDS is 720 and I'm sending the second half (360 LEDs) of the FastLED array to the slave.
The LED array on the slave is of size 360.
Using this code I only receive through the red byte of leds[51] which is the 258th byte, and Serial.print(len) in the receive code gives 258.
There seems to be some conversions between signed and unsigned types going on. Try first working exclusively with unsigned types, and avoid int if possible. The original Arduino Wire lib annoyingly uses int, which is signed 16-bit, for what is fundamentally an unsigned 8-bit operation (uint8_t).
I'm not sure if this will change anything, but I'll try to code the examples below this way. I don't have my setup with me at the moment, so hopefully this code is working.
I also added more diagnostic prints to both routines, so Master and Slave prints can be compared with each other. Master should print LED data it is sending with a final buffer length. Slave should print buffer length received with LED data.
Master code:
Code:
Wire.beginTransmission(8); // transmit to device #8
for(size_t i = NUM_LEDS/2; i < NUM_LEDS; i++) {
Wire.write((i>>8) & 0xFF);
Wire.write(i & 0xFF);
Wire.write(leds[i].r); // Send LED data
Wire.write(leds[i].g);
Wire.write(leds[i].b);
Serial.printf("LED Addr: %d RGB = %02X %02X %02X\n", i, leds[i].r, leds[i].g, leds[i].b);
}
Serial.printf("Length to send: %d\n", Wire.i2c->txBufferLength); // check buffer size before sending
Wire.endTransmission(); // send data
Slave code:
Code:
void receiveEvent(size_t len) {
Serial.printf("Data receive size: %d\n", len);
while (Wire.available()) {
uint8_t msb = Wire.readByte();
size_t addr = ((msb << 8) | Wire.readByte()) - 360;
leds[addr].r = Wire.read(); // Assign LED data received to above address
leds[addr].g = Wire.read();
leds[addr].b = Wire.read();
Serial.printf("LED Addr: %d RGB = %02X %02X %02X\n", addr, leds[addr].r, leds[addr].g, leds[addr].b);
}
}
Also, just to check, you are changing the Tx/Rx buffer lengths on both the Master and Slave devices right? What you describe could happen if one or the other is compiled at 259 bytes Tx/Rx.