1.5.25.71 SERCOMx_I2C_ErrorGet Function

C

/* x = SERCOM instance number */

/* I2C master mode */

SERCOM_I2C_ERROR SERCOMx_I2C_ErrorGet(void)			

/* I2C slave mode */
SERCOM_I2C_SLAVE_ERROR SERCOMx_I2C_ErrorGet(void)	

Summary

Returns the I2C error that occurred on the bus.

Description

This function returns the I2C error that occurred on the bus. The function can be called to identify the error cause.

Precondition

SERCOMx_I2C_Initialize must have been called for the associated SERCOM I2C instance.

Parameters

None.

Returns

Returns error of type SERCOM_I2C_ERROR (when I2C is in master mode) or SERCOM_I2C_SLAVE_ERROR (when I2C is in slave mode), identifying the error that has occurred.

Example

I2C in master mode:

if(SERCOM0_I2C_ErrorGet() == SERCOM_I2C_ERROR_NONE)
{
    //Transfer is completed successfully
}
else
{
    //Error occurred during transfer.
}

I2C in slave mode:

SERCOM_I2C_SLAVE_ERROR i2c_error;

i2c_error = SERCOM0_I2C_ErrorGet();

if(i2c_error)
{
    //Error occurred during transfer.
    if (i2c_error & SERCOM_I2C_SLAVE_ERROR_BUSERR)
    {
        // I2C Bus error has occured
    }
    if (i2c_error & SERCOM_I2C_SLAVE_ERROR_COLL)
    {
        // I2C bus collision error has occured
    }
    // Handle other error bits here ...
}
else
{
    //Transfer is completed successfully
}

Remarks

The return type of the API is SERCOM_I2C_ERROR when I2C is configured in master mode.

The return type of the API is SERCOM_I2C_SLAVE_ERROR when I2C is configured in slave mode