Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
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
fdThe file descriptor for the I2C master interface.addressThe address of the subordinate I2C device that is the source for the read operation.bufferThe output buffer that receives data from the subordinate device. This buffer must contain enough space to receivemaxLengthbytes. This can be NULL ifmaxLengthis 0.maxLengthThe 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.