1.37.18.81 SERCOM_I2C_SLAVE_CALLBACK Typedef

C

/* x = SERCOM instance number */

/* I2C slave in interrupt mode */

typedef bool (*SERCOM_I2C_SLAVE_CALLBACK) ( SERCOM_I2C_SLAVE_TRANSFER_EVENT event, uintptr_t contextHandle );

Summary

Defines the data type and function signature for the SERCOM I2C Slave callback function

Description

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

Precondition

SERCOMx_I2C_Initialize must have been called for the given SERCOM I2C peripheral instance and SERCOMx_I2C_CallbackRegister must have been called to set the function to be called. The callback register function should have been called before a transfer is initiated.

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 indicates to the SERCOM PLIB, whether to send ACK or NAK to the I2C master. The return value is valid only during the address match event or when the I2C slave is receiving data from the I2C master (SERCOM_I2C_SLAVE_TRANSFER_EVENT_RX_READY); that is during the I2C master write operation. The return value is ignored by the PLIB when the I2C slave is providing data to the I2C master (SERCOM_I2C_SLAVE_TRANSFER_EVENT_TX_READY); that is during the I2C master read operation.

Example

bool APP_SERCOM_I2C_Callback ( SERCOM_I2C_SLAVE_TRANSFER_EVENT event, uintptr_t contextHandle )
{
    switch(event)
    {
        case SERCOM_I2C_SLAVE_TRANSFER_EVENT_ADDR_MATCH:
        
        // Handle address match event
        
        break;
        
        case SERCOM_I2C_SLAVE_TRANSFER_EVENT_RX_READY:
        
        // I2C master is writing to data to I2C slave.
        // Read the received data byte.
        
        rxData = SERCOM0_I2C_ReadByte();
        
        break;
        case SERCOM_I2C_SLAVE_TRANSFER_EVENT_TX_READY:
        
        // I2C master is reading data from I2C slave.
        // Provide data to I2C master.
        
        SERCOM0_I2C_WriteByte(txData);
        
        break;
        
        case SERCOM_I2C_SLAVE_TRANSFER_EVENT_STOP_BIT_RECEIVED:
        
        // Handle stop bit received event
        
        break;
    }
}

// Register Callback function which is defined above
SERCOM0_I2C_CallbackRegister(APP_SERCOM_I2C_Callback, 0);

Remarks

None