1.28.6.73 FLEXCOM_TWI_SLAVE_CALLBACK Typedef

C

/* TWI slave in non-blocking/interrupt mode */

typedef bool (*FLEXCOM_TWI_SLAVE_CALLBACK) ( FLEXCOM_TWI_SLAVE_TRANSFER_EVENT event, uintptr_t contextHandle );

Summary

Defines the data type and function signature for the FLEXCOM TWI Slave callback function.

Description

This data type defines the function signature for the FLEXCOM TWI Slave callback function. The FLEXCOM TWI peripheral will call back the client's function with this signature to report FLEXCOM TWI slave events.

Precondition

FLEXCOMx_TWI_Initialize must have been called for the given FLEXCOM TWI peripheral instance and FLEXCOMx_TWI_CallbackRegister must have been called to set the function to be called. The callback register function should have been called before any transfer is initiated by the I2C master.

Parameters

Param Description
event Indicates the data transfer event for which the callback function has been called.
contextHandle Allows the caller to provide a context value (usually a pointerto the callers context for multi-instance clients).

Returns

bool - The return value is ignored by the TWI slave PLIB

Example

void APP_FLEXCOM_TWI_Callback ( FLEXCOM_TWI_SLAVE_TRANSFER_EVENT event, uintptr_t contextHandle )
{
    switch(event)
    {
        case FLEXCOM_TWI_SLAVE_TRANSFER_EVENT_ADDR_MATCH:
        // Handle address match event
        break;
        
        case FLEXCOM_TWI_SLAVE_TRANSFER_EVENT_RX_READY:
        
        // Read the received data byte
        rxData = FLEXCOM1_TWI_ReadByte();
        
        break;
        case FLEXCOM_TWI_SLAVE_TRANSFER_EVENT_TX_READY:
        
        // Provide data to TWI master
        FLEXCOM1_TWI_WriteByte(txData);
        
        break;
        
        case FLEXCOM_TWI_SLAVE_TRANSFER_EVENT_TRANSMISSION_COMPLETE:
        // Handle stop bit received event
        break;
    }
}

// Register Callback function which is defined above
FLEXCOM1_TWI_CallbackRegister(APP_FLEXCOM_TWI_Callback, 0);

Remarks

None