1 year ago
#274862
luca
PIC16F1787 I2C read temperature from TCN75S: ACKEN bit doesn't get cleared
I'm trying to read the temperature from a TCN75S sensor using a PIC.
i2c_start();
i2c_write(0b10010000);
i2c_write(0x00);
i2c_stop();
i2c_start();
i2c_write(0b10010001);
PORTD = i2c_read();
i2c_stop();
First I set the register pointer to the temperature register and then I try to read the temperature from the register, but I get stuck in a while loop, because the ACKEN bit from the SSPCON2 register doesn't get cleared.
read function:
char i2c_read(void)
{
char data = 0x00;
i2c_wait();
SSPCON2bits.RCEN = 1;
i2c_wait();
data = SSPBUF;
i2c_wait();
SSPCON2bits.ACKDT = 0;
SSPCON2bits.ACKEN = 1;
return data;
}
wait function:
void i2c_wait(void)
{
while((SSPSTAT & 0x04) || (SSPCON2 & 0x1F))
{
PORTD = SSPCON2;
}
}
c
temperature
0 Answers
Your Answer