Hello world code for PCT2075 and LM75B component class library. The PCT2075 is a temperature-to-digital converter featuring +/-1 degree-C accuracy over -25 degree-C to +100 degree-C range. It uses an on-chip band gap temperature sensor and Sigma-Delta A-to-D conversion technique with an overtemperature detection output that is a drop-in replacement for other LM75 series thermal sensors.

Dependencies:   PCT2075 mbed

Committer:
okano
Date:
Fri Feb 27 12:35:30 2015 +0000
Revision:
1:5398b0799e20
Parent:
0:3c3d4c5ac8e9
could built, no test done

Who changed what in which revision?

UserRevisionLine numberNew contents of line
okano 0:3c3d4c5ac8e9 1 #include "I2CTempSensor.h"
okano 0:3c3d4c5ac8e9 2
okano 0:3c3d4c5ac8e9 3 I2CTempSensor::I2CTempSensor( PinName i2c_sda, PinName i2c_scl, char address )
okano 0:3c3d4c5ac8e9 4 : i2c_p( new I2C( i2c_sda, i2c_scl ) ), i2c( *i2c_p ), adr( address )
okano 0:3c3d4c5ac8e9 5 {
okano 0:3c3d4c5ac8e9 6 init();
okano 0:3c3d4c5ac8e9 7 }
okano 0:3c3d4c5ac8e9 8
okano 0:3c3d4c5ac8e9 9 I2CTempSensor::I2CTempSensor( I2C &i2c_obj, char address )
okano 0:3c3d4c5ac8e9 10 : i2c_p( NULL ), i2c( i2c_obj ), adr( address )
okano 0:3c3d4c5ac8e9 11 {
okano 0:3c3d4c5ac8e9 12 init();
okano 0:3c3d4c5ac8e9 13 }
okano 0:3c3d4c5ac8e9 14
okano 0:3c3d4c5ac8e9 15 I2CTempSensor::~I2CTempSensor()
okano 0:3c3d4c5ac8e9 16 {
okano 0:3c3d4c5ac8e9 17 if ( NULL != i2c_p )
okano 0:3c3d4c5ac8e9 18 delete i2c_p;
okano 0:3c3d4c5ac8e9 19 }
okano 0:3c3d4c5ac8e9 20
okano 0:3c3d4c5ac8e9 21 void I2CTempSensor::init( void )
okano 0:3c3d4c5ac8e9 22 {
okano 0:3c3d4c5ac8e9 23 char command[ 2 ];
okano 0:3c3d4c5ac8e9 24
okano 0:3c3d4c5ac8e9 25 command[ 0 ] = LM75B_Conf;
okano 0:3c3d4c5ac8e9 26 command[ 1 ] = 0x00;
okano 0:3c3d4c5ac8e9 27
okano 0:3c3d4c5ac8e9 28 i2c.write( adr, command, 2 );
okano 0:3c3d4c5ac8e9 29 }
okano 0:3c3d4c5ac8e9 30
okano 1:5398b0799e20 31 short I2CTempSensor::read16( void )
okano 0:3c3d4c5ac8e9 32 {
okano 0:3c3d4c5ac8e9 33 char command[ 2 ];
okano 0:3c3d4c5ac8e9 34
okano 0:3c3d4c5ac8e9 35 command[ 0 ] = LM75B_Temp;
okano 0:3c3d4c5ac8e9 36
okano 0:3c3d4c5ac8e9 37 i2c.write( adr, command, 1 ); // Send command string
okano 0:3c3d4c5ac8e9 38 i2c.read( adr, command, 2 ); // read two bytes data
okano 0:3c3d4c5ac8e9 39
okano 0:3c3d4c5ac8e9 40 return ( (command[ 0 ] << 8)| command[1] );
okano 0:3c3d4c5ac8e9 41 }