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.