Archive for January, 2012

Using TMP100 temperature sensor with your PIC – PR5

January 31st, 2012 No comments

In this post I will describe how you can connect the TMP100 temperature sensor from TI to your PIC as well as receive temperature data. The sensor I am using is a generous sample from TI. Compared to the DS18S20 that I used before, this sensor is much faster, it takes 40ms to take a measurement with 0.5 degrees accuracy. The communication protocol is I2C. It could be a bit difficult connect it to your circuit since it is using a SOT-23-6 package.

For this project, I will be using my PIC prototyping board which carries a 18F4520. But you can pretty much use the C18 code in this post, with any PIC having a hardware I2C module.

Package problems!

Because SOT-23-6 is so small the first thing I needed was to create an adapter to make TMP100 compatible with my breadboard. This was a perfect excuse for improving my CNC skills :). So I created an adapter in EAGLE, cut it out using the CNC and then solder the sensor and 6 pins. The sensor is now breadboard ready!

The TMP100 adapter


The connection is really simple. Add two pull-up resistors to the SDA and SDL lines. I used 10kOhm. The datasheet also suggests an optional capacitor on the supply.

TMP100 pinout


TMP100 Schematic

As you can see from the schematic there are two pins called ADD1 and ADD0. Those pins determine the I2C address of the sensor. You can find more details in the datasheet. I connected those two lines to GND therefore the address of the sensor I am using is 0x90. That’s all on the hardware side.

TMP100 – Point Register

I2c is the language this sensor talks :). So we need to use your PICs I2C hardware capabilities. Initialize your communications using


This sensor has a Point Register (PR)which (guess what!) points to the address of the register you want  to read or write :) Before doing anything else we should point PR to the temperature register. To do that we have to initiate an I2C communication, send the address of the sensor and tell that sensor whether we like to write or read from it. This is done using a single byte. You see, the address is 7-bits starting from the MSB and bit 0 indicates whether is read or write operation (0=Write 1=Read). Let’s do an example. Our sensor’s address is 0x90. We wish to read something from the sensor so the byte should be 0x91. If we wish to write something to the sensors it should be 0x90. That’s it.

Therefore to write to point PR to the temperature register we should issue the following

WriteI2C(0x90); // Call the sensor with WRITE
WriteI2C(0x00); // Write Temp reg to point register;

Notice the 0x00? That is the address of the temperature register. The sensor is now ready to give us some temperatures.

TMP100 – Read that temperature

To read the temperature off the sensor, we need to call it using its address and READ (what we said above, remember?) and the sensor will transmit two bytes of data back. We read that using the appropriate I2C commands shown below. We have to acknowledge the reception of the bytes to let TMP100 know that we are ready for the next byte. Temperature is read as follows

first_byte = ReadI2C();
second_byte = ReadI2C();

The temperature is made out of two bytes. If you don’t care about getting any decimals you can just use the first byte. The 4 most significant bits of the second byte contain information on the decimal value of the temperature.

TMP100 – C18 Library

I made a really simple library for tmp100 in C18. Just include the tmp100.h file to your project and make sure you initiate the I2C (the OpenI2C() command shown in this post) before calling any functions.


OK that is pretty much. You should be able to get some measurements out of that little sensor. If you need further help take a look at the example below

#pragma config OSC = HSPLL
#pragma config WDT = OFF
#pragma config PWRT = ON
#pragma config LVP = OFF
#pragma config PBADEN = OFF
#include <p18cxxx.h>
#include <i2c.h>
#include <usart.h>
#include <delays.h>
#include <p18f4520.h>
#include <stdio.h>
#include "tmp100.h"
void main(void) {
    unsigned int raw_tmpr;
    char str_tmpr[8];
              USART_RX_INT_OFF &
              USART_ASYNCH_MODE &
              USART_EIGHT_BIT &
              USART_CONT_RX &
    OpenI2C(MASTER,SLEW_OFF);   // Initialize I2C module
    tm_setconf(0x60);   // Set sensor to full sensitivity
        raw_tmpr = tm_gettemp();    // Get 2 bytes of temperature
        tm_tostr(raw_tmpr,str_tmpr);    // Convert the temperature to text
        printf("Temperature is %s\r",str_tmpr); // And output through USART

I connected the USART TX/RX line using my CP2102 and used the cutecom program on Ubuntu to read the output on my PC. The screenshot below shows the terminal

The terminal on Ubuntu

Incoming search terms:

  • tmp100 (45)