I have a TCN75A temperature sensor interfaced to a PIC 18F2458. I am using C18 and it's software I2C library. I can successfully read the MSB of the temperature but the LSB always returns 255. Can anyone see anything wrong with my code?
Sorry! Hectic week... SwackI2C() does return the acknowledgement... So the code was correct... Have you tried to read just one byte and then the other in a new read?
Oh, ok. How would I go about doing that? The temperature register is 16 bits long and the pointer register only gives the option to point to that register and not a specific byte.
Reading the data sheet... SEND START (wait for ack).... PUT ADDRESS (wait for ack )...PUT POINTER (wait for ack )...... SEND RESTART (wait for ack).....PUT ADDRESS (w.f.a.)....
READ MSB (YOU send ack).... READ LSB (YOU send ack ) ...... SEND STOP .....
You haven't got a send ack in software.. you'll have to make it... Have a look how Mike Pierce did it....
I live in Oldham....
C:
void i2csendack(void)
{
//--- Send Ack to slave except for last time ---
SDA=0;
SDA_TRIS=I2CLOW; //-- Send ACK
i2cdelay(I2CDATASETTLE); //-- Give it time to settle
i2cclock(); //-- Pulse the clock
SDA_TRIS=I2CHIGH; //-- Release ACK
i2cdelay(I2CDATASETTLE); //-- Gap between next byte
}
//************** END OF i2csendack
Ignore the above post. I am back to the original code. I have added in the function in post 8 along with the corresponding "i2cclock" function and called i2csendack after I receive the first byte. I am still receiving 255 for the second byte.
Why did I not even consider using that! Thanks! Now I have a meaningful LSB. Although it's only changing between 0 and 128 which maybe means I am not successfully putting it into 12bit mode?