Having a lockup in the I2C code

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Having a lockup in the I2C code

705 Views
jeffjacobson
Contributor I

I am using lpcopen_2_10_keil_iar_nxp_lpcxpresso_1769 and having random lockups in this code in bold:

/* Chip event handler interrupt based */
void Chip_I2C_EventHandler(I2C_ID_T id, I2C_EVENT_T event)
{
    struct i2c_interface *iic = &i2c[id];
    volatile I2C_STATUS_T *stat;

    /* Only WAIT event needs to be handled */
    if (event != I2C_EVENT_WAIT) {
        return;
    }

    stat = &iic->mXfer->status;
    /* Wait for the status to change */
    while (*stat == I2C_STATUS_BUSY) {}
}

My code will run sometimes minute, sometimes once. When it hangs it is always there. The fact that a library has a dead loop is bad enough.

Has anyone seen issues with these libraries? Any thoughts on could be hanging the I2C bus? I scoped the lines and power and all are very clean.

Any direction would be great.

Thanks, Jeff

0 Kudos
3 Replies

574 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi Jeff,

   When you scope the I2C lines, and the problem happens, any abnormal things? You also can insert your I2C bus wave.

  Please tell me your LPC1769 is the I2C master or the slave? Then I will do the test on my side.


Have a great day,
Kerry

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos

574 Views
asobralg1
Contributor I

Dear Community, specially Kerry: 

I still have this problem, the code is running on a loop during the while while (*stat == I2C_STATUS_BUSY).

I'm using a LPC1769. I'll attacht the configuration function, just to share, i think that the problem isn't there.

void Chip_I2C_EventHandlerPolling(I2C_ID_T id, I2C_EVENT_T event)
{
struct i2c_interface *iic = &i2c[id];
volatile I2C_STATUS_T *stat;

/* Only WAIT event needs to be handled */
if (event != I2C_EVENT_WAIT) {
return;
}

stat = &iic->mXfer->status;
/* Call the state change handler till xfer is done */
while (*stat == I2C_STATUS_BUSY) {
if (Chip_I2C_IsStateChanged(id)) {
Chip_I2C_MasterStateHandler(id);
}
}
}

void init_memoriai2c (void)
{
//Inicializo i2c de la memoria
Chip_IOCON_PinMux(LPC_IOCON, I2C_DEVICE_PORT, I2C_SDA_PIN, IOCON_MODE_INACT, IOCON_FUNC3);
Chip_IOCON_PinMux(LPC_IOCON, I2C_DEVICE_PORT, I2C_SCL_PIN, IOCON_MODE_INACT, IOCON_FUNC3);
Chip_IOCON_EnableOD(LPC_IOCON,I2C_DEVICE_PORT, I2C_SDA_PIN);
Chip_I2C_Init(I2C_DEVICE_NUM_MEMR);
Chip_I2C_SetClockRate(I2C_DEVICE_NUM_MEMR,I2C_SPEED_MMR);
Chip_I2C_SetMasterEventHandler(I2C_DEVICE_2,Chip_I2C_EventHandlerPolling);

}

Port 0, SDAPin = 0, SCLPin = 1, I2C_DEVICE_NUM_MEMR = 2, I2C_SPEED_MMR = 256000, I2C_DEVICE_2 = IC2C

0 Kudos

574 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi Alejandro Sobral,

  Please create a new question post about your own question, then our LPC engineer will help you.

  I don't support the LPC product now, thanks a lot for your understanding.

Best Regards,

kerry

0 Kudos