1.1.2.4.16 DRV_I2C_WriteReadTransfer Function

C

bool DRV_I2C_WriteReadTransfer (
    const DRV_HANDLE handle,
    uint16_t address,
    void* const writeBuffer,
    const size_t writeSize,
    void* const readBuffer,
    const size_t readSize
)

Summary

This is a blocking function that performs a I2C write followed by a I2C read operation.

Description

This function does a blocking write and read operation. The function blocks till the write and read is complete or error has occurred during data transfer. Function will return false to report failure. The failure will occur for the following reasons:

  • Invalid input parameters

  • Hardware error

Precondition

DRV_I2C_Open must have been called to obtain a valid opened device handle.

Parameters

ParamDescription
handleA valid open-instance handle, returned from the driver's open routine DRV_I2C_Open function.
addressSlave Address
writeBufferSource buffer containing data to be written.
writeSizeSize in bytes of data to be written.
readBufferDestination buffer where read data is stored.
readSizeSize in bytes of data to be read.

Returns

true - transfer is successful

false - error has occurred

Example

uint8_t myTxBuffer[MY_TX_BUFFER_SIZE];
uint8_t myRxBuffer[MY_RX_BUFFER_SIZE];

// myI2CHandle is the handle returned
// by the DRV_I2C_Open function.

// slaveAddress is address of I2C slave device
// to which data is to be written

if (DRV_I2C_WriteReadTransfer(myI2CHandle, slaveAddress, myTxBuffer, MY_TX_BUFFER_SIZE, myRxBuffer, MY_RX_BUFFER_SIZE) == false)
{
    // Error handling here
}

Remarks

This function is thread safe in a RTOS application. This function should not be called from an interrupt context. This function is available only in the synchronous mode.