1.1.2.4.10 DRV_I2C_WriteReadTransferAdd Function

C

void DRV_I2C_WriteReadTransferAdd (
    const DRV_HANDLE handle,
    const uint16_t address,
    void * const writeBuffer,
    const size_t writeSize,
    void * const readBuffer,
    const size_t readSize,
    DRV_I2C_TRANSFER_HANDLE * const transferHandle
)

Summary

Queues a write followed by read operation.

Description

This function schedules a non-blocking write followed by read operation. The function returns with a valid transfer handle in the transferHandle argument if the write 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.

On returning, the transferHandle parameter may be DRV_I2C_TRANSFER_HANDLE_INVALID for the following reasons:

  • if a buffer could not be allocated to the request

  • if the input write or read buffer pointer is NULL

  • if the write or read buffer size is 0

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 or a 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

ParamDescription
handleA valid open-instance handle, returned from the driver's open routine DRV_I2C_Open function.
addressSlave address
writeBufferData to be written.
writeSizeSize of write buffer in bytes.
readBufferBuffer where data to be read is stored.
readSizeSize of the read buffer in bytes.
transferHandlePointer to an argument that will contain the return transfer handle. This will be DRV_I2C_TRANSFER_HANDLE_INVALID if the function was not successful.

Returns

None.

Example

uint8_t myTxBuffer[MY_TX_BUFFER_SIZE];
uint8_t myRxBuffer[MY_RX_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_WriteReadTransferAdd(myI2CHandle, slaveAddress, myTxBuffer, MY_TX_BUFFER_SIZE, myRxBuffer, MY_RX_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 this client. It should not be called in the event handler associated with another I2C driver instance. It should not otherwise be called directly in an ISR. This function is available only in the asynchronous mode.