The code seems to be ok, but there's a problem I think in the following statement:
I2C2CONbits.ACKDT = 0; //set ACKDT bit to send ACKbecause the value should be 1 instead of 0.
This is due, I think, to the behaviour of the master during the reading phase as described in the detailed Microchip reference manual for the I2C (Section 19, page 7).
I attach the code I used for the I2C bus communication; it is for I2C port 1, so you need to adapt to port 2.
File Attachment: File Name:
i2c.zipFile Size: 2057
I hope this will help you. If you have any problem post a more detailed version of the code you are using for the I2C communication.
Regard,
Christian.