1.1.2.4.8 DRV_I2C_ForcedWriteTransferAdd Function
C
void DRV_I2C_ForcedWriteTransferAdd(
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
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 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
Param | Description |
---|---|
handle | A valid open-instance handle, returned from the driver's open routine DRV_I2C_Open function. |
address | Slave address |
buffer | Data to be written. |
size | Transfer size in bytes. |
transferHandle | Pointer 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_ForcedWriteTransferAdd(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 API is generated only if the underlying peripheral and the peripheral library supports forced write feature that ignore the NACK from a slave during transfer and the forced write feature is enabled in one of the connected periphreal library.
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 an invalid transfer handle (DRV_I2C_TRANSFER_HANDLE_INVALID).
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.