I2CMaster_Read Function

Header: #include <applibs/i2c.h>

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

ssize_t I2CMaster_Read(int fd, I2C_DeviceAddress address, uint8_t *buffer, size_t maxLength);

Parameters

  • fd The file descriptor for the I2C master interface.

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

  • buffer The output buffer that receives data from the subordinate device. This buffer must contain enough space to receive maxLength bytes. This can be NULL if maxLength is 0.

  • maxLength The maximum number of bytes to receive. The 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 clock line (SCL) 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 use 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 read; or -1 for failure, in which case errno will be set to the error value. A partial read operation, including a read 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.