SSP2CON2bits.RCEN = 1; // enable master for 1 byte receptionwhile ( !SSP2STATbits.BF ); // wait until byte received #if defined (I2C_V3) || defined (I2C_V6) || defined (I2C_V6_1)
unsigned char ReadI2C2( void )
{
if( ((SSP2CON1&0x0F)==0x08) || ((SSP2CON1&0x0F)==0x0B) ) //master mode only
SSP2CON2bits.RCEN = 1; // enable master for 1 byte reception
while ( !SSP2STATbits.BF ); // wait until byte received
return ( SSP2BUF ); // return with read byte
}
#endifNo sé de donde has sacado esa función, de todas maneras la he probado y me da error de compilaciónmientras corría el proyecto en modo debugger para ver los valores de los registros y de los puertos, observé que cuando llegaba a la sentencia de estarti2c2, no activaba el bit SSP2CON2bits.SEN = 1;, así como restart12c2 (SSP2CON2bits.RSEN = 1; ), ReadI2C2 (SSP2CON2bits.RCEN = 1;) y StopI2C2(SSP2CON2bits.PEN = 1;) , la flecha verde pasaba por encima pero el bit no cambiaba en el registro, lo que hice fue saque esa sentencia de la función y la puse directamente en el driver del dispositivo y empezó a funcionar pero no del todo bien, (ahora lo explico).
Connecting to MPLAB ICD 2
...Connected
Setting Vdd source to target
Target Device PIC18F67J50 found, revision = Rev 0x3
...Reading ICD Product ID
Running ICD Self Test
...Passed
MPLAB ICD 2 ready for next operation