MCP9808
instruction code, outlined in Example 5-1, shows the
communication flow; also see Figure 5-5 for the timing
diagram.
5.1.3.1
TA Bits to Temperature Conversion
To convert the TA bits to decimal temperature, the
upper three boundary bits (TA<15:13>) must be
masked out. Then, determine the SIGN bit (bit 12) to
check positive or negative temperature, shift the bits
accordingly, and combine the upper and lower bytes of
the 16-bit register. The upper byte contains data for
temperatures greater than +32°C while the lower byte
contains data for temperature less than +32°C, includ-
ing fractional data. When combining the upper and
lower bytes, the upper byte must be right-shifted by
4 bits (or multiply by 24) and the lower byte must be left-
shifted by 4 bits (or multiply by 2-4). Adding the results
of the shifted values provides the temperature data in
decimal format (see Equation 5-1).
EQUATION 5-1:
BYTES TO
TEMPERATURE
CONVERSION
Temperature TA ≥ 0°C
= (UpperByte × 2 + LowerByte × 2
4
–4
T
)
A
Temperature < 0°C
= 256 – (UpperByte × 2 + LowerByte × 2
4
–4
T
)
A
Where:
TA = Ambient Temperature (°C)
UpperByte = TA bit 15 to bit 8
LowerByte = TA bit 7 to bit 0
The temperature bits are in two’s compliment format,
therefore, positive temperature data and negative tem-
perature data are computed differently. Equation 5-1
shows the temperature computation. The example
EXAMPLE 5-1:
SAMPLE INSTRUCTION CODE
2
This example routine assumes the variables and I C™ communication subroutines are predefined
(see Appendix A: “Source Code”):
i2c_start();
// send START command
i2c_write (AddressByte & 0xFE);
//WRITE Command (see Section 4.1.4 “Address Byte”)
//also, make sure bit 0 is cleared ‘0’
i2c_write(0x05);
// Write T Register Address
A
i2c_start();
//Repeat START
i2c_write(AddressByte | 0x01);
// READ Command (see Section 4.1.4 “Address Byte”)
//also, make sure bit 0 is Set ‘1’
// READ 8 bits
UpperByte = i2c_read(ACK);
LowerByte = i2c_read(NAK);
//and Send ACK bit
// READ 8 bits
//and Send NAK bit
i2c_stop();
// send STOP command
//Convert the temperature data
//First Check flag bits
if ((UpperByte & 0x80) == 0x80){
}
//T ³ T
A
CRIT
if ((UpperByte & 0x40) == 0x40){
}
//T > T
A
UPPER
LOWER
if ((UpperByte & 0x20) == 0x20){
}
//T < T
A
UpperByte = UpperByte & 0x1F;
if ((UpperByte & 0x10) == 0x10){
UpperByte = UpperByte & 0x0F;
//Clear flag bits
//T < 0°C
A
//Clear SIGN
Temperature = 256 - (UpperByte x 16 + LowerByte / 16);
}else //T ³ 0°C
Temperature = (UpperByte x 16 + LowerByte / 16);
//Temperature = Ambient Temperature (°C)
A
© 2011 Microchip Technology Inc.
DS25095A-page 25