I have done the I2C communication with the sensor but whenever I try to read the data from the buffer it is always showing FF.
Is there any pin that I should clear after getting the data to the buffer?
Code: Select all
unsigned int I2C_Master_Read_Byte(char ACKflag)
{
int t,temp,p[50];
I2C1CONLbits.RCEN = 1; //Receive enable
while(!DataRdyI2C1())
{
LATBbits.LATB2=~LATBbits.LATB2; // Only entering ones
}
temp=I2C1RCV;
if(ACKflag == 1) //Set state in preparation for TX below
{
I2C1CONLbits.ACKDT = 1;//NACK
}
else
{
I2C1CONLbits.ACKDT = 0;//ACK
}
I2C1CONLbits.ACKEN = 1;
sprintf(p, "temp : %d ",temp);
Oled_WriteString(p);
return temp;
}
int DataRdyI2C1(void)
{
return I2C1STATbits.RBF;
}