Jump to main content

##

# 1.1.2.4.9 DRV_I2C_ReadTransferAdd Function

## C

    void DRV_I2C_ReadTransferAdd(
        const DRV_HANDLE handle,
        const uint16_t address,
        void * const buffer,
        const size_t size,
        DRV_I2C_TRANSFER_HANDLE * const transferHandle
    )

## Summary

Queues a read operation.

## Description

This function schedules a non-blocking read operation. The function returns with a valid transfer handle in the transferHandle argument if the read request was scheduled successfully. The function adds the request to the driver instance transfer queue and returns immediately. While the request is in the queue, the application buffer is owned by the driver and should not be modified.

The function returns DRV_I2C_TRANSFER_HANDLE_INVALID in the transferHandle argument:

- if a buffer could not be allocated to the request
- if the input buffer pointer is NULL
- if the buffer size is 0
- if the driver handle is invalid

If the requesting client registered an event callback with the driver, the driver will issue a DRV_I2C_TRANSFER_EVENT_COMPLETE event if the buffer was processed successfully of DRV_I2C_TRANSFER_EVENT_ERROR event if the buffer was not processed successfully.

## Precondition

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

## Parameters

Param | Description
--- | ---
handle | A valid open-instance handle, returned from the driver's open routine DRV_I2C_Open function.
address | Slave address
buffer | buffer where the read data will be stored.
size | Transfer size in bytes.
transferHandle | Pointer to an argument that will contain the return transfer handle. This is DRV_I2C_TRANSFER_HANDLE_INVALID if the request was not successful.

## Returns

None

## Example

    uint8_t myBuffer[MY_BUFFER_SIZE];
    DRV_I2C_TRANSFER_HANDLE transferHandle;

    // 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

    DRV_I2C_ReadTransferAdd(myI2CHandle, slaveAddress, myBuffer, MY_BUFFER_SIZE, &transferHandle);

    if(transferHandle == DRV_I2C_TRANSFER_HANDLE_INVALID)
    {
        // Error handling here
    }

    // Event is received when the buffer is processed.

## Remarks

This function is thread safe in a RTOS application. It can be called from within the I2C Driver Transfer Event Handler that is registered by the client. It should not be called in the event handler associated with another I2C driver instance. It should not be called directly in an ISR. This function is available only in the asynchronous mode.