1.1.2.4.14 DRV_I2C_ForcedWriteTransfer Function

C

bool DRV_I2C_ForcedWriteTransfer(
    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

I2C Master calls this function to transmit the entire buffer to the slave even if the slave ACKs or NACKs the address or any of the data bytes. This is typically used for slaves that have to initiate a reset sequence by sending a dummy I2C transaction. Since the slave is still in reset, any or all the bytes can be NACKed. In the normal operation of the driver if the address or data byte is NACKed, then the transmission is aborted and a STOP condition is asserted on the bus.

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_ForcedWriteTransfer(myI2CHandle, slaveAddress, myTxBuffer, MY_TX_BUFFER_SIZE) == false)
{
    // Error handling here
}

Remarks

This API must be used only if the underlying PLIB is enabled to generate the Forced write API. If the PLIB is not enabled to generate the Forced Write API, the API will return false.

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.