LPC4367 I2C stuck in interrupt handler

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

LPC4367 I2C stuck in interrupt handler

1,555 Views
jochem
Contributor I

I am using an LPC4367 on an OM13084 development board, this board is connected to another system using I2C (I2C bus 1 on the LPC4367) as a slave. There are also two sensors connected to the same I2C bus, which I read out using the LPC4367 a I2C master. I'm using the lpcopen libraries 3.02. All communciation over the I2C bus is handled via interrupt.

Receiving data from the other system is not a problem, I'm receiving everything that is send over the bus correct.

But when I try to read data from the sensors connected to the bus with the LPC4367, the program gets stuck in the

"Chip_I2C_EventHandler()" at random moments (after a couple of hours). 

/* 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) {}

When this happens the status of the I2C bus is stuck at "I2C_STATUS_BUSY"

Any idea what can be causing this and how to fix this?

Labels (1)
0 Kudos
Reply
3 Replies

1,263 Views
jochem
Contributor I

I checked the I2C bus when the problem occurs both SDA and SCL are high. When i only use the LPC4367 as a slave receiving data from the other system it works ok, although sometimes the "Chip_I2C_MasterStateHandler(DEFAULT_SLAVE_I2C )" is called leading to a hard fault, I fixed this for the moment by using the watchdog timer to reset the LPC4367. When this happens the I2C Status register (STAT) contains 0x00, which is not a valid state according to the datasheet. Also when only using the LPC4367 as a slave I would not expect the "Chip_I2C_MasterStateHandler(DEFAULT_SLAVE_I2C )" to be called.

static void i2c_state_handling()
{
    if (Chip_I2C_IsMasterActive(DEFAULT_SLAVE_I2C ))
    {
        Chip_I2C_MasterStateHandler(DEFAULT_SLAVE_I2C );
    }
    else
    {
        Chip_I2C_SlaveStateHandler(DEFAULT_SLAVE_I2C);
    }
}

When I add one or two sensors to the bus and read data from them using the LPC4367 as master, the problem occurs. During readout of the sensors there is no communciation from the other system.

When the problem happens the I2C bus is not active both lines are high, the other system tries to communicate with the LPC4367 over the bus but when writing the slave address this is not acknowledged.

I tried using forced access  to the bus by adding  a time-out to the "Chip_I2C_EventHandler()" 

/* 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;
    unsigned int error_count = 0;

    /* 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)
    {
        //add timeout forcing bus to stop
        _delay_ms(5);
        error_count++;
        if(error_count > 100)
        {
            iic->ip->CONSET = I2C_I2CONSET_STO;
        }
    }

}  

But this doesn't fix the problem.

I also tried using the watchdog timer to reset the LPC4367 when a fault occurs but even after a reset I2C communication is still not possible.

0 Kudos
Reply

1,263 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi Jochem,

   Please check my new attached codebundle code  I2C code on your side, whether it still have problems or not?

  Any updated information, please kindly let me know.


Have a great day,
Kerry

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

0 Kudos
Reply

1,263 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi Jochem van der Meer,

     Can you check the I2C bus when the problem happens? Check the I2C bus whether it is not normally when the problem happens.

     Besides, please remove another I2C slave, just use one I2C slave, and one I2C master in the I2C bus, whether the problem still happens or not? Just want to exclude the other I2C node influence.

   After you get the I2C bus wave when the problem happens, please also send it to me, I will check it.

  Besides, these information may also useful to you:

pastedImage_1.png

 


Have a great day,
Kerry

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

0 Kudos
Reply