endI2CTransmission()

[Inter Integrated Circuit]
int endI2CTransmission(bool send_stop = false);

Description

Ends an I2C transmission from a Leader Device.

This function should be called after all the data has been sent to the follower chip. And to release the I2C bus, the endI2CTransmission() function can be called with the parameter send_stop set to true.

Parameters

send_stop: a boolean value that determines whether to send a stop condition on the I2C bus. This parameter is optional.

Returns

The error status of the transmission, 0 if successful, 1 if the transmission failed.

Example Code

The code initializes the I2C communication with the SDA pin connected to pin 4, and the SCL pin connected to pin 5.

Then begins an I2C transmission to the follower chip with the address 0x20.

Ends the I2C transmission and sends a stop condition on the I2C bus.

void setup() {
    beginI2C(4, 5);  // initializes the I2C communication with the SDA pin connected to pin 4, the SCL pin connected to pin 5
}

void loop() {
    beginI2CTransmission(0x20);  // begins an I2C transmission to the follower chip with the address 0x20
    write("x is ");              // sends the string "x is " to the follower chip
    write(42);                   // sends the value 42 to the follower chip
    endTransmission(true);       // ends the I2C transmission
}

Notes and Warnings

If the send_stop parameter is set to true, the I2C bus will not be released.