1.1.2.4.13 DRV_I2C_WriteTransfer Function

C

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

Summary

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

Description

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

  • Invalid input parameters

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
bufferSource buffer containing data to be written.
sizeSize in bytes of data to be written.

Returns

true - write is successful

false - error has occurred

Example

uint8_t myTxBuffer[MY_TX_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_WriteTransfer(myI2CHandle, slaveAddress, myTxBuffer, MY_TX_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.