Well its partially working, the concept works but I can't just re-initialise my IIC task and re-run
fnOpen( TYPE_IIC, FOR_I_O, &tIICParameters);
I don't think the drivers were ever coded to be restarted. If I try re-initialising the task then the software crashes, I'm presuming its because IICPortID is not getting allocated properly.
Next I tried going a bit deeper and running fnConfigIIC(&tIICParameters); this improved things. But code is still not starting back up again cleanly, and the application resrats soon after. I'm suspecting some buffers need to be cleared.
When I detect IIC lockup, (done via a timeout counter) I run this bit of code
{
fnKickSCL(); // Clock the SCL line 16 times to free up SDA
fnConfigIIC(&tIICParameters); // Init IIC hardware
IICIdle = true; // Reset my internal flag that flags if a transmission is in progress
}
Where fnKickSCL() is defined below
void fnKickSCL(void)
{
int i;
int delay;
#define IICDELAYTIME 10
_CONFIG_PORT_OUTPUT(B, PORT_BIT2);
_CONFIG_PORT_INPUT_PULLUP(B, PORT_BIT3);
for(i=0; i<16; i++)
{
for(delay=0; delay<IICDELAYTIME; delay++) _CLEARBITS(B, PORT_BIT2);
for(delay=0; delay<IICDELAYTIME; delay++) _SETBITS(B, PORT_BIT2);
}
}
This is now at least restarting the IIC Bus as can be seen in the attached logic trace, I've got to find out where the software error is.
How do I go about resetting the IIC buffers, I don't mind about loosing data?
Cheers
Martin