I2CMaster_WriteThenRead Function
Header: #include <applibs/i2c.h>
Performs a combined write-then-read operation on an I2C master interface. The operation appears as a single bus transaction with the following steps:
- start condition
- write
- repeated start condition
- read
- stop condition
ssize_t I2CMaster_WriteThenRead(int fd, I2C_DeviceAddress address, const uint8_t *writeData, size_t lenWriteData, uint8_t *readData, size_t lenReadData);
Parameters
fd
The file descriptor for the I2C master interface.address
The address of the target I2C device for this operation.writeData
The data to transmit to the targeted device.lenWriteData
The byte length of the data to transmit.readData
The output buffer that receives data from the target device. This buffer must contain sufficient space to receivelenReadData
bytes.lenReadData
The byte length of the data to receive.
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 did not 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 combined number of bytes successfully written and read, or -1 for failure, in which case errno
is set to the error value. A partial result, including a transfer 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.