Can multiple write be used between a pair of begin and end Transmissions

Hello,

I have gone through many sample codes, almost all of them use only one write in a pair of begin and end transmissions, if two writes are needed, they repeat the code as below

Wire.beginTransmission(addr);
Wire.write(reg_addr_1);
Wire.endTransmission();

Wire.beginTransmission(addr);
Wire.write(reg_addr_2);
Wire.endTransmission();

I would like to know if multiple write can be used between a pair of begin and end transmission as below.

Wire.beginTransmission(addr);
Wire.write(reg_addr_1);
Wire.write(reg_addr_2);
Wire.endTransmission();

Thanks,
Gu

Yes but you can't write more than 32 bytes at a time due to the hard coded buffer sizes in the Wire library.

Nothing gets transferred until you call endTransmission() the bytes are buffered up. The buffer size in Wire is 32 bytes that is why you can't send more than 32 bytes at a time.

Transferring multiple data bytes in a single i2c message block will be much faster than sending each byte separately as you avoid the additional I2C start, address and end overhead for the subsequent bytes.

--- bill

Thanks
Gu

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