lpcware

I2c

Discussion created by lpcware Employee on Jun 15, 2016
Latest reply on Jun 15, 2016 by lpcware
Content originally posted in LPCWare by affonpign on Thu Oct 06 02:04:29 MST 2011
Hello everybody,

I use the Lib_MCU, which is a interface driver library Embedded Artists provides. I use the I2C driver. The I2C drivers can be found in the lpc17xx_i2c.c file. I copied the I2C_SendByte function right bellow:

/***********************************************************************
* Function: I2C_SendByte
* Purpose: Send a byte
* Parameters:
*     I2Cx: Pointer to I2C register
* Returns: value of I2C status register after sending
**********************************************************************/
static uint32_t I2C_SendByte (LPC_I2C_TypeDef *I2Cx, uint8_t databyte)
{
    /* Make sure start bit is not active */
    if (I2Cx->I2CONSET & I2C_I2CONSET_STA)
    {
        I2Cx->I2CONCLR = I2C_I2CONCLR_STAC;
    }
    I2Cx->I2DAT = databyte & I2C_I2DAT_BITMASK;
    I2Cx->I2CONCLR = I2C_I2CONCLR_SIC;

    while (!(I2Cx->I2CONSET & I2C_I2CONSET_SI));
    return (I2Cx->I2STAT & I2C_STAT_CODE_BITMASK);
}


The following command should clear the interrupt flag:

I2Cx->I2CONCLR = I2C_I2CONCLR_SIC;

But then the following line waits in the while loop until the interrupt flag SI is set. I do not understand that because we just cleared the interrupt flag.

If I check the status of the control register I see that the interrupt flag is still set after it is cleared by the stated command.

Does anyone can explain that behavior?

Regards,
Lucas

Outcomes