Hello Peter,
In my k64f baremetal project I have found 2 issues with the i2c communication.
Issue 1) is the same as yours. Sometimes after flashing and initiating a debug session i2c will be stuck. I've never seen it happening with the release build, so I don't worry too much about it. I just power cycle the board and most times it will debug just fine.
Issue 2) is that sometimes the i2c communication will stop due to not receiving a stop signal from the slave device, locking the i2c in a busy state. As a workaround I set up a pseudo-watchdog to check if the busy flag is on and restart the i2c driver. So far, seems to fix the lockup issue.
Below is an example of my pseudo-watchdog ISR:
void FAKEDOG_ISR(void)
{
/* Clear interrupt flag.*/
PIT_ClearStatusFlags(PIT, kPIT_Chnl_2, PIT_TFLG_TIF_MASK);
PIT_StopTimer(PIT, kPIT_Chnl_2);
/*deal with I2C*/
if(I2C0->S & kI2C_BusBusyFlag)
{
i2c_master_transfer_t tmpXfer;
//preserve transfer status
memcpy(&tmpXfer,&masterXfer,sizeof(i2c_master_transfer_t));
//reset drivers
DMAMGR_Deinit();
I2C_MasterDeinit(I2C_MASTER_BASEADDR);
DMAMGR_Init();
i2c_init();
//restore transfer status
memcpy(&masterXfer,&tmpXfer,sizeof(i2c_master_transfer_t));
}
PIT_StartTimer(PIT, kPIT_Chnl_2);
}
Although not an exact answer to your question, I hope this information is useful to you.
Best regards,
Daniel Caetano