1.1.2.4.7 DRV_I2C_WriteTransferAdd Function

C

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

Summary

Queues a write operation.

Description

This function schedules a non-blocking write 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 transfer buffer could not be allocated to the request

  • if the input buffer pointer is NULL

  • if the 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
bufferData to be written.
sizeTransfer size 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 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_WriteTransferAdd(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 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.