AnsweredAssumed Answered

Garbled I2C transmission

Question asked by SCOTT MILLER on Dec 26, 2015
Latest reply on Jan 3, 2016 by SCOTT MILLER

I'm using interrupt-based I2C block transfers with the Processor Expert drivers for the MK22FN1M0AVLH12.  I've got a periodic I2C query that starts by sending a register number to a particular address.  Other code handles a subsequent block read command to get data from the register.


The problem is that the register byte, immediately after the slave address, is getting garbled.  It should be 0x02 but it frequently comes out 0xff, 0x88, or other values.  It shows up this way on my logic analyzer, and the oscilloscope confirms that's what's actually on the SDA line.  Nothing looks amiss on the analog side - levels are correct, no ringing or overshoot to speak of.  It's just wrong.


If I step through the code - specifically if I have any delay between the transmission of the slave address and the 0x02 byte, it works perfectly.  It does not work, however, if I insert a delay loop in the I2C ISR.  The garbled byte just gets moved out a few milliseconds.  The driver looks like it's behaving properly and I'm not seeing any spurious I2C interrupts.  I've tried baud rates all the way down to 15 kHz and it behaves exactly the same.


The behavior is the same if the register byte is set to 0x00 or 0xff.  Everything else looks OK on the logic analyzer - it just doesn't send the right data.


Any ideas?  This looks like it *should* be very straightforward but it's driving me nuts.