In Arduino I2C we have the following lines of code:

wire. beginTransmission(slave addrress)
wire.write(the byte want to send)
wire. endTransmission()

As we know in I2C the master must verifies the presence of the slave address and making it sure by getting an ack by the slave. Among the three function listed, who does this job? Is it wire. beginTransmission? in their website it's just mentioned it initializes communication with the slave. I want to know what happens during the execution of wire. beginTransmission from I2C perspective.

Also wire.endTransmission() releases the buffer data which was created by wire. write. So who examines the presence of the slave? The first function or the 3rd?


1 Answer 1


All the actual I2C communication is done in Wire.endTransmission(). Before that nothing is done on the I2C lines.

Wire.beginTransaction() only initializes the libraries buffer and saves the slave address in an internal variable. Wire.write() puts data into the internal buffer.

Wire.endTransmission() can then follow the I2C protocol. It generates a start condition on the bus, sends the address byte, checks for the slaves acknowledgement on the address byte, then sends the data bytes, each followed by the slaves acknowledgement. Finally it generates a stop condition.

  • it means suppose i forgot to write wire. beginTransmission, does that mean I can't execute wire.endTransmission? Because it looks like the latter is depended on the first? That is, wire. endTransmission isn't an independent function.
    – Sayan
    Commented Jan 23, 2022 at 17:26
  • 2
    Wire.beginTransmission() primes the library for a master write transaction. So you need it before calling Wire.endTransmission(). What makes you think that any of these functions are independent? They are working for the same hardware interface. You need to call them just as the library supposes you to.
    – chrisl
    Commented Jan 23, 2022 at 17:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.