1.1.11.13 I2CSMBx_CallbackRegister Function
C
/* x = I2C SMBUS peripheral instance number */ /* I2C master mode */ void I2CSMBx_CallbackRegister(I2C_CALLBACK callback, uintptr_t contextHandle) /* I2C slave mode in non-blocking/interrupt mode */ void I2CSMBx_CallbackRegister(I2C_SLAVE_CALLBACK callback, uintptr_t contextHandle)
Summary
Sets the pointer to the function (and it's context) to be called when the given I2C's transfer events occur.
Description
This function sets the pointer to a client/application function to be called "back" when the given I2C's transfer events occur. It also passes a context value (usually a pointer to a context structure) that is passed into the function when it is called. The specified callback function will be called from the peripheral interrupt context.
Precondition
I2CSMBx_Initialize must have been called for the associated I2C instance.
Parameters
Param | Description |
---|---|
callback | A pointer to a function with a calling signature defined by the I2C_CALLBACK (in I2C master mode) or I2C_SLAVE_CALLBACK (in I2C slave mode) data type. Setting this to NULL disables the callback feature. |
context | A value (usually a pointer) which is passed (unused) into the function identified by the callback parameter |
Returns
None
Example
I2C master mode
void I2CSMB0_Callback(uintptr_t context) { if(I2CSMB0_ErrorGet() == I2C_ERROR_NONE) { //Transfer is completed successfully } else { //Error occurred during transfer. } } // Register Callback function which is defined above I2CSMB0_CallbackRegister(I2CSMB0_Callback, (uintptr_t)NULL);
I2C slave in non-blocking/interrupt mode
bool I2CSMB0_Callback ( I2C_SLAVE_TRANSFER_EVENT event, uintptr_t context ) { uint8_t rxData; uint8_t txData; switch(event) { case I2C_SLAVE_TRANSFER_EVENT_ADDR_MATCH: // Handle address match event break; case I2C_SLAVE_TRANSFER_EVENT_RX_READY: // I2C master is writing data to I2C slave. // Read the received data byte. rxData = I2CSMB0_ReadByte(); break; case I2C_SLAVE_TRANSFER_EVENT_TX_READY: // I2C master is reading data from I2C slave. // Provide data to I2C master. I2CSMB0_WriteByte(txData); break; } } // Register Callback function which is defined above I2CSMB0_CallbackRegister(I2CSMB0_Callback, 0);
Remarks
None