Microchip’s TC74 is an affordable digital temperature sensor with a basic I2C interface. It has a resolution of 1 degree Celsius, and a variety of -40 to +125 degrees. This is an easy method to add temperature measurement to a job without an analog to digital converter. We’ll show you how to utilize the TC74 below.
Microchip TC74 digital temperature sensor (Octopart search, starting at $0.88)
The TC74 is available in five pin through-hole and surface mount packages, see the TC74 datasheet (PDF). We couldn’t find a Cadsoft Eagle footprint for any version of this part, if you know of one please link to it in the comments.
Different versions of the TC74 are calibrated for certain voltages, but all work from 2.7-5volts. The TC74A5 we utilized is a lot of accurate when operating at 5volts, but we powered it from a 3.3volt supply. The I2C connection needs 2 pull-up resistors to hold the bus high (R1, R2), 2K-10K must work. C1 is a 0.1uF decoupling capacitor.
We utilized the Bus Pirate universal serial interface in I2C mode to test drive the TC74, but the exact same principals apply to any microcontroller. We powered the TC74 from the Bus Pirate’s 3.3volt supply, and utilized the on-board pull-up resistors to hold the I2C bus high.
Command
Value
Select temperature register
0x00
Select configuration register
0x01
The TC74’s compose address is 0x9a, and the checked out address 0x9b. It has two, one-byte registers. Register address 0 holds the temperature reading, register 1 holds the configuration settings.
Configuration register
Bit 6 of the configuration register is 0 at power-on, and modifications to 1 when the first valid temperature reading is available. bit 7 is writable, and puts the TC74 in a power saving standby mode. reading the register includes two steps: utilize a partial compose command to choose the register, then utilize the checked out command to retrieve the value.
I2C>{0x9a 1}
210 I2C begin CONDITION
220 I2C WRITE: 0x9A got ACK: indeed <–write address
220 I2C WRITE: 0x01 got ACK: indeed <–select config register
240 I2C stop CONDITION
First, we choose the configuration register with a partial compose command. This doesn’t actually compose a value, it selects the register to checked out and write. { produces the I2C begin condition, complied with by the TC74 compose address (0x9a) and the choose configuration register command (0x01). } problems the I2C stop condition and ends the transaction.
Now we can checked out the contents of the register.
I2C>{0x9b r}
210 I2C begin CONDITION
220 I2C WRITE: 0x9B got ACK: indeed <–read address
230 I2C READ: 0x40 <– register value (01000000)
240 I2C stop CONDITION
I2C>
The checked out address (0x9b) returns the one byte register value (r). The configuration register value, 0x40 or 01000000, shows that the device is out of standby (bit 7=0), and a valid temperature reading is available (bit 6=1).
The TC74 has a low-power standby mode. enable it by composing 1 to bit 7 of the configuration register.
I2C>{0x9a 1 0b10000000}
210 I2C begin CONDITION
220 I2C WRITE: 0x9A got ACK: indeed <–write address
220 I2C WRITE: 0x01 got ACK: indeed <–select config register
220 I2C WRITE: 0x80 got ACK: indeed <–value to compose (01000000)
240 I2C stop CONDITION
I2C>
The register is written with single three-byte command. first we send the compose address (0x9a), complied with by the register to choose (0x01), and finally the value to compose (0x80). only bit 7 of the configuration register is writable, the values of bits 6-0 are ignored.
Read the register again to confirm that the command worked.
I2C>{0x9a 1}{0x9b r}
210 I2C begin condition <–first command sets register
220 I2C WRITE: 0x9A got ACK: indeed <–write address
220 I2C WRITE: 0x01 got ACK: indeed <–config register (1)
240 I2C stop condition <–end first command
210 I2C begin condition <–begin second command
220 I2C WRITE: 0x9B got ACK: indeed <–read address
230 I2C READ: 0x80 <– register value (10000000)
240 I2C stop condition <–end second command
I2C>
The register value, 10000000, now shows that the device is in standby (bit 7=1). notice that bit 6 is now 0, no temperature data is available.
Clear bit 7 to exit standby, then wait on bit 6 to return to 1 before reading the temperature register.
I2C>{0x9a 1 0b00000000}
210 I2C begin CONDITION
220 I2C WRITE: 0x9A got ACK: indeed <–write address
220 I2C WRITE: 0x01 got ACK: YES<–select config register
220 I2C WRITE: 0x00 got ACK: YES<–value to compose (00000000)
240 I2C stop CONDITION
I2C>
Temperature data is prepared when the configuration register value returns to 0x40 (01000000).
Temperature
The temperature register is checked out in two steps. First, a partial compose command selects the temperature register (0), then a checked out sequence returns the contents.
I2C>{0x9a 0}{0x9b r}
210 I2C begin CONDITION
220 I2C WRITE: 0x9A got ACK: indeed <–write address
220 I2C WRITE: 0x00 got ACK: indeed <–selecttemperature register
240 I2C stop CONDITION
210 I2C begin CONDITION
220 I2C WRITE: 0x9B got ACK: indeed <–read address
230 I2C READ: 0x18 <–grab one byte
240 I2C stop CONDITION
I2C>
The temperature is an integer value of degrees Celsius, negative numbers are represented as a twos complement. positive values from 0 to 127 degrees Celsius are just represented by that value. negative temperatures have bit 7 set, and variety from -1 to -65 (255-128), see table 4.4 on page 8 of the datasheet. The hexadecimal value 0x18 is equal to 24 in decimal, so the temperature reading is 24C (75F).
Like this post? inspect out the parts articles you may have missed.