I2CMaster_Write Function

Header: #include <applibs/i2c.h>

Performs a write operation on an I2C master interface. This function provides the same functionality as the POSIX write() function, except it specifies the address of the subordinate I2C device that is the target of the operation.

ssize_t I2CMaster_Write(int fd, I2C_DeviceAddress address, const uint8_t *data, size_t length);

Parameters

  • fd The file descriptor for the I2C master interface.

  • address The address of the subordinate I2C device that is the target for the operation.

  • data The data to transmit to the target device. This value can be NULL if length is 0.

  • length The size of the data to transmit. This value can be 0.

Errors

Returns -1 if an error is encountered and sets errno to the error value.

  • EBUSY: the interface is busy or the I2C line is being held low.

  • ENXIO: the operation didn't receive an ACK from the subordinate device.

  • ETIMEDOUT: the operation timed out before completing; you can call the I2CMaster_SetTimeout function to adjust the timeout duration.

Any other errno may also be specified; such errors aren't deterministic and the same behavior might not be retained through system updates.

Return value

Returns the number of bytes successfully written, or -1 for failure, in which case errno will be set to the error value. A partial write, including a write of 0 bytes, is considered a success.

Application manifest requirements

To access an I2c interface, your application must identify it in the I2cMaster field of the application manifest.