1.11.12.18 1.12.12.18 1.13.11.18 1.15.11.18 1.16.9.18 1.17.9.18 1.18.10.18 1.19.9.18 1.20.9.18 1.21.10.18 1.22.14.18 1.23.13.18 1.24.11.18 I2C_SLAVE_CALLBACK Typedef
C
/* I2C slave in interrupt mode */ typedef bool (*I2C_SLAVE_CALLBACK) (I2C_SLAVE_TRANSFER_EVENT event, uintptr_t contextHandle);
Summary
Defines the data type and function signature for the I2C Slave callback function.
Description
This data type defines the function signature for the I2C Slave callback function. The I2C peripheral will call back the client's function with this signature to report I2C slave events. The I2C clock will be stretched thereby allowing the application ample time to handle the I2C event in the callback. The I2C clock is released when the callback execution is complete.
Precondition
I2Cx_Initialize must have been called for the given I2C peripheral instance and I2Cx_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 hasbeen 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 currently ignored by the I2C PLIB. Application can return true.
Example
bool APP_I2C_SLAVE_Callback ( I2C_SLAVE_TRANSFER_EVENT event, uintptr_t contextHandle ) { switch(event) { case I2C_SLAVE_TRANSFER_EVENT_ADDR_MATCH: // Handle address match event break; case I2C_SLAVE_TRANSFER_EVENT_RX_READY: // Read the received data byte rxData = I2C1_ReadByte(); break; case I2C_SLAVE_TRANSFER_EVENT_TX_READY: // Provide data to I2C master I2C1_WriteByte(txData); break; case I2C_SLAVE_TRANSFER_EVENT_STOP_BIT_RECEIVED: // Handle stop bit received event break; } } // Register Callback function which is defined above I2C1_CallbackRegister(APP_I2C_SLAVE_Callback, 0);
Remarks
None