MPLAB MCC I2C problems.
Hy everyone. I was trying to use I2C, using MCC code.
I'm using PIC24FJ64GA106, this device has 3 I2C modules, and for some security requirements I need to use two.
The first problem is that the Foundation Services Library does not support the use of more than one I2C module. The other module should be used with more basic routines.
However, the biggest problem is a piece of code (there are actually several)
while (I2C_BUSY == i2c_close ()); // sit here until finished.
At that point, if the other device connected to the I2C bus does not respond, or something happens, the microcontroller remains absolutely blocked.
There are several dangerous while in the generated code, including one while (1).
I am grateful for the existence of the MCC tool, and my post is to help you correct these things.
I would suggest (as I've seen in other codes) that they give escape options for time and / or retries, and return a boolean if the routine ended successfully or not.
If I have a display, an RTC and a memory hung on the I2C bus, and the display is disconnected, I can safely continue to work, this should not block my equipment. Furthermore, I should block it if I choose to.