This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Display TMP112 data temperature

Other Parts Discussed in Thread: TMP112

Hello.

I'm trying to display in a LCD 16x2 the data temperature from TMP112. So far I've got this:

temper=ReadByte();
SendAck(1);               // SDA low -> more data to come

temper2=ReadByte();
SendAck(0);                 //SDA high

temperature=temper+temper2;
var=temperature/16;
var2=temperature%16;

And then the display shows: 

printf("Temperature: %d.%d", var,var2);

I'm not sure if this is right. I've the data temperatura from TMP112 at temper and temper2 and then send both to temperature and display the integer part first and the rest of division after.

Can someone tell me if I'm doing this right?

Thanks.

  • Helo Natalia,

    Out of 8 bits in Byte 2 of Temperature register (also called as Tlow register in TMP112 data sheet) only 4 of the MSB bits are used in normal more  (in extended mode 5 bits are use). In other words, if you refer to Table 4, Page 7 of data sheet you will see that only D[7] to D[4] of of the bits are used for temperature. So, you need to shift these bits to the right and then perform the addition (temper+temper2).

     

    Secondly, if you are dealing with negative numbers please remember to include 2's compliment conversion code.More on this is explained on Page 8 of data sheet.

     

    Best Regards,

    Abhi

  • Thanks for the help.

    Is this what you meant?

    temper=ReadByte();
    SendAck(1);

    temper2=ReadByte();
    SendAck(0);


    temper2=temper2>>4;

    temperature=temper+temper2;
    var=temperature/16;
    var2=temperature%16;

  • If temper2 is holding the Low byte of temperature data , yes this method should work.

     

    Best regards,

    Abhi