According to Texas Instrument, TMP101 is a two-wire, serial output temperature sensor available in SOT23-6 package. Requiring no external components, the TMP101 is capable of reading temperatures with a resolution of 0.0625°C.
This is from a project I did in 2008. The given routines measure temperature from TMP101 and output it to the serial port of the microcontroller at one second interval. TMP101 was connected to the standard I2C pins of the PIC18F452 microcontroller used.
__CONFIG (2,WDTDIS); __CONFIG (4,LVPDIS & STVRDIS); #define TMP101ADDR 0b10010010 //Here it's assumed ADD0 is floated unsigned char i2cBuffer[10]; void main(){ signed int temperature; float Realtemp; //DS1337 adress is 0xD0 TRISC = 0b10011000; init_comms(); printf("now intialising sensor\n"); SSPADD = 9; // 100 kHz I2C bus SSPCON1 = 0x08; SSPEN=1 ; // Enable I2C bus i2cBuffer[0]=0b00000001; //adress of the configuration register printf("Reading Cofiguration register...\n"); if(!GetI2C(TMP101ADDR,1,1,i2cBuffer)) printf("Device Error..\n") ; else printf("Config Register is %d\n",i2cBuffer[0]); printf("Now writing to the config register\n"); i2cBuffer[0]=0b00000001; //adress of the config register i2cBuffer[1]=0b01100000; //data to be written to config register //12bit resolution, continuous conversion if(!SendI2C(TMP101ADDR,2,i2cBuffer)) printf("error writing to config register\n"); while(1){ i2cBuffer[0]=0b00000000; //adress of temperature register if (GetI2C(TMP101ADDR,1,2,i2cBuffer)){ //pointer arithmatic to access Word and bytes of a long integer *(((unsigned char *)&temperature))=i2cBuffer[1]; *(((unsigned char *)&temperature)+1)=i2cBuffer[0]; Realtemp=(((float)temperature)/256.0); //converting 12bit result to correct value printf("Temperature is %0.2f\n",Realtemp); //sending the data to standard seria output } DelayS(1); } }
Download Complete Project: TMP101 Interfaced to PIC18F452