Content originally posted in LPCWare by DF9DQ on Sat Jan 02 04:15:45 MST 2016
It looks like an issue with the way you handle the SI bit (which is notorious for that...).
Before you begin transmission with the START condition, SI is assumed to be cleared. It shouldn't be necessary to do it explicitly, because if SI were still set you would be getting I2C interrupts at that time. Yet it doesn't harm to clear it, so simply change to
I2CONCLR.SIC = 1
I2CONSET.STA = 1
Sending the START condition takes time (your 4 µs!), and before sending SLA+X you must wait for SI to get set again after the I2C block has reached state 0x08 (in I2CSTAT).
It is then when you write SLA+X to I2CDAT, clear STA, and *afterwards* clear SI.
wait_for_SI()
I2DAT = 0xA0
I2CONCLR.STAC = 1
I2CONCLR.SIC = 1
For any action in response to an I2C interrupt (SI=1) it is important that you first do all the preparations necessary for the desired next step, and only clear SI after all that is done.
Regards,
Rolf