1.1.2.4.15 DRV_I2C_ReadTransfer Function

C

bool DRV_I2C_ReadTransfer(
    const DRV_HANDLE handle,
    uint16_t address,
    void* const buffer,
    const size_t size
)

Summary

This is a blocking function that performs a I2C read operation.

Description

This function does a blocking read operation. The function blocks till the read is complete or error has occurred during read. 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
bufferDestination buffer where read data is stored.
sizeSize in bytes of data to be read.

Returns

true - read is successful

false - error has occurred

Example

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_ReadTransfer(myI2CHandle, slaveAddress, 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.