Figure 1: Digital Thermometer using TC74 I2C Thermal Sensor Circuit Diagram

TC74 is a serially accessible digital temperature sensor particularly suited for low cost and small form-factor applications. Temperature data is converted from the on-board thermal sensing element and made available as an 8-bit digital word.

Communication with the TC74 is accomplished via a simple 2-wire I2C compatible serial port. This bus also can be used to implement multi-drop/multi-zone monitoring. The SHDN bit in the CONFIG register can be used to activate the low-power Standby mode. Temperature resolution is 1°C. Conversion rate is a nominal 8 samples/sec. Power consumption in only 200 µA (5 µA Standby).

Small size, low installed cost and ease of use make the TC74 an ideal choice for implementing thermal management in a variety of systems

Pin Descriptions

Figure 2: TC74 pin descriptions

Below is the description of each pin:

Table 1: TC74 pin description

The TC74 stores the measured temperature into its 8-bit temperature register as 2’s complement binary format. The most significant bit is the sign bit, which is set to 1 for negative temperatures. Therefore, the maximum measurable positive temperature is + 127 °C (0111 1111).

Each unit value represents one degree (Celsius). For example the reading of 0000 0000b corresponds to 0°C and 0001 1001b corresponds to +25°C. Examples of this temperature to binary value relationship are shown in Table 2 below.

Table 2: TC74 Temperature to binary value relationship

The TC74 has also got another 8-bit Read/Write Configuration Register (RWCR) that is used to put the device into a low power (IDD = 5 µA, typical) Standby mode. In this mode, the A/D converter is halted and the temperature data registers are frozen. Bit 7 of RWCR must be set to put TC74 into Standby mode

Table 3: TC74 Configuration Register

For more information, please read the TC74 Datasheet.

Watch the Video Tutorial

Serial Port Operation

The Serial Clock input (SCLK) and bidirectional data port (SDA) form a 2-wire bidirectional serial port for programming and interrogating the TC74.

The host microcontroller communicate with the slave TC74 through the I2C bus. The host microcontroller provides the clock signal for all the data transfers and the TC74 always operates as a Slave. The default 7-bit I2C address of TC74 is 1001 101b (ox4D). However, 7 other address options are also available which can be identified from the part number of the device

The I2C protocol is illustrated in Figure 3 below. All data transfers have two phases and all bytes are transferred MSB first. Accesses are initiated by a START condition, followed by a device address byte and one or more data bytes.
The device address byte includes a Read/Write selection bit. Each access must be terminated by a STOP
condition. A convention called “Acknowledge” (ACK) confirms receipt of each byte. Note that SDA can change only during periods when SCLK is low (SDA changes while SCLK is high are reserved for START and STOP conditions)

Figure 3: TC74 Serial Port Operation

To learn more about the I2C bus communication, please read the article:

PIC Microcontroller Communication with I2C Bus

Steps to Read Temperature:

  • The host microcontroller issues a Start condition followed by the address byte of the sensor. The address byte consists of the 7-bit slave address and a Read/Write bit (R/W). The R/W bit is always ‘0’ (Write) in the first phase.
  • TC74 responds with an ACK if the received 7-bit address matches with its own slave address.
  • Then the host microcontroller sends the command byte to TC74 to indicate which register it wants to access. For reading the temperature, the command byte should be 00h. The TC74 responds with an acknowledge pulse.
  • The host microcontroller issues a new Start condition because the direction of data transfer is now going to be changed. The new address byte with R/W bit 1 is sent by the host, which is acknowledged by the slave.
  • The TC74 transmits the 8-bit temperature data from the temperature register. Upon receiving the byte, the host doesn’t acknowledge, but generates a Stop condition

Buy the Components for this project from our Online Store

[porto_products view=”grid” ids=”4684,4682, 4924,4520,4541″]

The circuit diagram of the project is on figure 1 above, the PIC18F45K22 is used but any other PIC with I2C interface could be used. Don’t forget to put two pull-up resistors on SDA and SCL lines of I2C bus.

To simplify everything, we are going to use MPLAB Code Configurator (MCC).

  • In MCC System module, we’re gonna set our Oscillator select to 8MHz Internal Oscillator. we’re gonna disable the MCLR pin as well.
  • In pin module, set RB0 to RB6 as digital Output pins for our LCD connections.

To learn more how to use the LCD, please read the article:

Interfacing LCD Display with PIC Microcontroller

What’s important to us in this tutorial is the I2C set with MCC. As shown on figure 4 below:

  • Select the MSSP1 under Device Resources.
  • Select I2C Master
  • Slew rate control, select standard speed,
  • Set the I2C clock frequency to 100KHz or below by changing the Baud rate generator value which is what is normally referred to as Standard Speed. This value will depend on the system clock frequency.
  • Set the Slave address to 7-bit

Figure 4: TC74 I2C Sensor Configuration with MCC

By clicking on the MCC Generate button, a number of header and source files will be auto generated for us including the I2c1.h and I2C1.c

You can read the I2C1.h for a short descriptions of the functions prototypes and macros generated by MCC. You could also right click on the peripherals in project resources in MCC and select help for more information on how to use them with an option to a wiki page.

Below is a quick summary of some few functions that we are going to use in this tutorials, for  more information, please read the description of each function in the i2c.h file generated by the MCC or read our I2C Communication tutorial.

  • I2C1_MESSAGE_STATUS: Defines the different message status when processing TRBs (Transanction Request Block)
  • I2C_Initialize(): This routine initializes the i2c1 driver instance for index, making it ready for clients to open and use it
  • I2C_MasterWrite(): This function handles one i2c master write transaction with the supplied parameters. It will send data to i2c queue, waits for the transaction to complete and returns the result. The parameters are:
    • address: The address of the i2c slave peripheral to be accessed
    • length: The length of the data block to be sent
    • *pdata: A pointer to the block of data to be sent
    • *pstatus: A pointer to the status variable
  • I2C_MasterRead(): This function handles one i2c master read transaction with the supplied parameters. It will send data to i2c queue, waits for the transaction to complete and returns the result. The parameters are:
    • address: The address of the i2c slave peripheral to be accessed
    • length: The length of the data block to be sent
    • *pdata: A pointer to the block of data to be sent
    • *pstatus: A pointer to the status variable
  • I2C1_MasterTRBInsert(): Inserts a list of i2c transaction requests into the i2c transaction queue. The i2c processes lists of transaction requests. Each transaction list is handled as a string of i2c restarts. When the list of transactions is complete, an i2c stop is produced, the flag is set with the correct condition code and the next list is processed from the queue.
  • I2C_MasterQueueIsEmpty(): This function returns the empty status of the Master queue. You can use this function to check if the queue is empty. This can verify if the Master is currently idle. This function will return True if the queue is empty and false if the queue is not empty.

The MCC I2C Master drivers are based on an Interrupt Driven State Machine designed to perform small I2C transactions automatically. These can be queued to obtain custom sequences as required by each specific application like for example a MasterWrite followed by a MasterRead.

During the call of a Write, Read or TRBInsert, we will pass the I2C driver a pointer to a status variable I2C1_MESSAGE_STATUS that will be able to interrogate periodically to check for the operation completion otherwise it will return fail, pending, lost state etc.

We must Enable Peripheral and Global Interrupts (uncomment the lines) immediately after the SYSTEM_Initialize() call in the main function, failure to do so, the I2C drivers state machine won’t be able to advance.

In this simple example below, the microcontroller reads the temperature word from the TC74’s Temperature Register and displays it on a 16×2 LCD. The Celsius temperature value is displayed on the 1st line of the LCD and the converted to Fahrenheit Temperature value on the 2nd line of the LCD. The default TC74 address of 0x4D is used.

You can easily create a PCB for this project as we have learned in our PCB start to finish tutorials, all you need is to get a good PCB prototyping company that will offer your good quality PCBs at a good price. We recommend, a China Shenzhen-based manufacturer specializing in PCB prototyping, small-volume production and PCB Assembly service all under one.

They are now running a promotion for their PCB Assembly services, get a worldwide free shipping when you place an order for PCB Assembly.

To learn more, please click on the image below and to get an instant PCB Assembly quote online, please visit their home page: 

Main Function

You can download the full project files (MPLAB XC8 source code and Proteus Schematic design) below here.

Note: All the files are zipped, you will need to unzip them (Download a free version of the Winzip utility to unzip files). 

Download: MPLAB X Project TC74

Download: Proteus Schematic Project TC74