lpcware

I2C & LPC1347 - Too many bytes are read when more than 1 byte is requested

Discussion created by lpcware Employee on Jun 15, 2016
Content originally posted in LPCWare by mathseng on Wed Oct 09 19:31:43 MST 2013
Problem:
The sample code for LPC13xx (used for LPC1347) for the I2C example reads back too many bytes when bytes requested is 2 or greater.
The error occurs in the handling of state value 0x50.

Suggested solution:
My suggested correction is to compare the current updated read index plus 1 against the number of bytes being requested.
This is because the action to occur happens AFTER the NEXT byte read, thus showing the need to compare with the modified pointer.

Implementation:
Modify the comparison test code in i2c.c::void I2C_IRQHandler(void) as follows - this then causes the state machine to execute state 0x58 after the NEXT byte - state 0x58 handles the LAST byte being received.
<code>
case 0x50:/* Data byte has been received, regardless following ACK or NACK */
I2CSlaveBuffer[RdIndex++] = LPC_I2C->DAT;
if ( (RdIndex +1) < I2CReadLength )
</code>

Regards,
Bill

Outcomes