I'm using the Wire library with an Arduino Nano Every, as I2C master.
I realized that the byte sent count returned by the .write() method is incorrect. Example:
Wire.beginTransmission(address); n = Wire.write(buffer, buffer_size); Wire.endTransmission();
the n variable, as documentation states, gets the number of bytes sent. But if the I2C lines are disconnected and there's no slave to respond, so no bytes are sent, the .write() method returns the same buffer size value meaning that all the payload has been sent.
On the oscilloscope I see that the address byte is sent, there's no ack on the 9th bit, and the bus goes back to the idle state; this means that the Wire library handles properly the missing ack skipping on sending the payload but fails to report back the problem. I'm expecting the .write() method to return 0, meaning no payload bytes transmitted.
Why? What I'm missing? How can I properly handle a communication problem?