Hi guys, still trying to chip away at pic32 i2c and the TCM8240 Camera found at sparkfun.
My I2C knowledge is lacking and I can't figure out why I'm getting stuck after my stop bit.
Code:
void TPI2CStop(void)
{
int x = 0;
// wait for module idle
I2CIdle();
//initiate stop bit
CONbits.PEN = 1;
//wait for hardware clear of stop bit
while (CONbits.PEN)
{
I2CWait(50);
x++;
if (x > 1) break;
}
CONbits.RCEN = 0;
// IFS0bits.MI2C3IF = 0; // Clear Interrupt
STATbits.IWCOL = 0;
STATbits.BCL = 0;
// wait for module idle
I2CIdle(); << STUCK HERE **********************************
}
here my I2cIdle() func
Code:
void I2CIdle(void)
{
UINT8 timeout = 150;
/* Wait until I2C Bus is Inactive */
while (CONbits.SEN || CONbits.PEN || CONbits.RCEN ||
CONbits.RSEN || CONbits.ACKEN || STATbits.TRSTAT || timeout-- );
}
CONbits.PEN is the bit which is stopping my loop from breaking..
from the pic32 family reference manual
PEN: Stop Condition Enable bit
In I2C Master mode only
1 = Initiate Stop condition on SDAx and SCLx pins; cleared by module
0 = Stop condition idle
I assume that if I'm getting this far, e.g. receiving ACK from camera, that communication is working?
what could be the problem? thanks for any assistance