Drivber for Ti's TMP007 Infrared Thermopile Sensor with Integrated Math Engine
Revision 1:93710a3abf0a, committed 2016-06-05
- Comitter:
- messi1
- Date:
- Sun Jun 05 19:53:43 2016 +0000
- Parent:
- 0:a1ed9ce625d4
- Commit message:
- Add TMP007_Defs.h file
Changed in this revision
diff -r a1ed9ce625d4 -r 93710a3abf0a include/TMP007.h --- a/include/TMP007.h Sun Jun 05 19:38:48 2016 +0000 +++ b/include/TMP007.h Sun Jun 05 19:53:43 2016 +0000 @@ -24,60 +24,8 @@ #include <I2C.h> #include "PinNames.h" - +#include "TMP007_Defs.h" -// Constants for calculating object temperature -#define TMP007_B0 -0.0000294 -#define TMP007_B1 -0.00000057 -#define TMP007_B2 0.00000000463 -#define TMP007_C2 13.4 -#define TMP007_TREF 298.15 -#define TMP007_A2 -0.00001678 -#define TMP007_A1 0.00175 -#define TMP007_S0 6.4 // * 10^-14 - -// Configuration Settings -#define TMP007_CFG_RESET 0x8000 -#define TMP007_CFG_MODEON 0x1000 -#define TMP007_CFG_1SAMPLE 0x0000 -#define TMP007_CFG_2SAMPLE 0x0200 -#define TMP007_CFG_4SAMPLE 0x0400 -#define TMP007_CFG_8SAMPLE 0x0600 -#define TMP007_CFG_16SAMPLE 0x0800 -#define TMP007_CFG_1SAMPLE_LPWR 0x0a00 -#define TMP007_CFG_2SAMPLE_LPWR 0x0c00 -#define TMP007_CFG_4SAMPLE_LPWR 0x0e00 -#define TMP007_CFG_ALRTEN 0x0100 -#define TMP007_CFG_ALLRTF 0x0080 -#define TMP007_CFG_TC 0x0040 -#define TMP007_CFG_INT_COMP 0x0020 - -// Registers to read thermopile voltage and sensor temperature -#define TMP007_SENSOR_VOLT 0x00 //RO -#define TMP007_LOCAL_TEMP 0x01 //RO -#define TMP007_CONFIG 0x02 //RW -#define TMP007_OBJECT_TEMP 0x03 //RO -#define TMP007_STATUS 0x04 //RO -#define TMP007_STATUS_MASK 0x05 //RW - -#define TMP007_OBJECT_TEMP_HI_LIM 0x06 //RW -#define TMP007_OBJECT_TEMP_LO_LIM 0x07 //RW -#define TMP007_LOCAL_TEMP_HI_LIM 0x08 //RW -#define TMP007_LOCAL_TEMP_LO_LIM 0x09 //RW - -#define TMP007_COEFFICIENT_S0 0x0a //RW -#define TMP007_COEFFICIENT_A1 0x0b //RW -#define TMP007_COEFFICIENT_A2 0x0c //RW -#define TMP007_COEFFICIENT_B0 0x0d //RW -#define TMP007_COEFFICIENT_B1 0x0e //RW -#define TMP007_COEFFICIENT_B2 0x0f //RW -#define TMP007_COEFFICIENT_C2 0x10 //RW -#define TMP007_COEFFICIENT_TC0 0x11 //RW -#define TMP007_COEFFICIENT_TC1 0x12 //RW - -#define TMP007_MANUFACTURE_ID 0x1E //RO -#define TMP007_DEVICE_ID 0x1F //RO -#define TMP007_MEM_ACCESS 0x2A //RW class TMP007 { @@ -90,6 +38,7 @@ uint16_t readConfig() ; uint16_t readStatus(); + void writeStatusMask(const uint16_t value); /** Configures sensor, use before reading from it */ void setSamples(const uint16_t samples); @@ -113,7 +62,6 @@ double readDieTempF(); private: - /** * Writes a word value into the register. Note: the device must have the * auto-increment bit set in the MODE1 register to work. @@ -133,8 +81,6 @@ */ uint16_t readWord(const uint8_t reg); - - private: mbed::I2C _i2cPort; uint8_t _addr;
diff -r a1ed9ce625d4 -r 93710a3abf0a include/TMP007_Defs.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/include/TMP007_Defs.h Sun Jun 05 19:53:43 2016 +0000 @@ -0,0 +1,67 @@ +#ifndef TMP007_DEFS_H +#define TMP007_DEFS_H + +// Constants for calculating object temperature +#define TMP007_B0 -0.0000294 +#define TMP007_B1 -0.00000057 +#define TMP007_B2 0.00000000463 +#define TMP007_C2 13.4 +#define TMP007_TREF 298.15 +#define TMP007_A2 -0.00001678 +#define TMP007_A1 0.00175 +#define TMP007_S0 6.4 // * 10^-14 + +// Configuration Settings +#define TMP007_CFG_RESET 0x8000 +#define TMP007_CFG_MODEON 0x1000 +#define TMP007_CFG_1SAMPLE 0x0000 +#define TMP007_CFG_2SAMPLE 0x0200 +#define TMP007_CFG_4SAMPLE 0x0400 +#define TMP007_CFG_8SAMPLE 0x0600 +#define TMP007_CFG_16SAMPLE 0x0800 +#define TMP007_CFG_1SAMPLE_LPWR 0x0a00 +#define TMP007_CFG_2SAMPLE_LPWR 0x0c00 +#define TMP007_CFG_4SAMPLE_LPWR 0x0e00 +#define TMP007_CFG_ALRTEN 0x0100 +#define TMP007_CFG_ALLRTF 0x0080 +#define TMP007_CFG_TC 0x0040 +#define TMP007_CFG_INT_COMP 0x0020 + +// Status Mask +#define TMP007_ALRTEN 0x8000 +#define TMP007_CRTEN 0x4000 +#define TMP007_OHEN 0x2000 +#define TMP007_OLEN 0x1000 +#define TMP007_LHEN 0x0800 +#define TMP007_LLEN 0x0400 +#define TMP007_DVEN 0x0200 +#define TMP007_MEM_C_EN 0x0100 + +// Registers to read thermopile voltage and sensor temperature +#define TMP007_SENSOR_VOLT 0x00 //RO +#define TMP007_LOCAL_TEMP 0x01 //RO +#define TMP007_CONFIG 0x02 //RW +#define TMP007_OBJECT_TEMP 0x03 //RO +#define TMP007_STATUS 0x04 //RO +#define TMP007_STATUS_MASK 0x05 //RW + +#define TMP007_OBJECT_TEMP_HI_LIM 0x06 //RW +#define TMP007_OBJECT_TEMP_LO_LIM 0x07 //RW +#define TMP007_LOCAL_TEMP_HI_LIM 0x08 //RW +#define TMP007_LOCAL_TEMP_LO_LIM 0x09 //RW + +#define TMP007_COEFFICIENT_S0 0x0a //RW +#define TMP007_COEFFICIENT_A1 0x0b //RW +#define TMP007_COEFFICIENT_A2 0x0c //RW +#define TMP007_COEFFICIENT_B0 0x0d //RW +#define TMP007_COEFFICIENT_B1 0x0e //RW +#define TMP007_COEFFICIENT_B2 0x0f //RW +#define TMP007_COEFFICIENT_C2 0x10 //RW +#define TMP007_COEFFICIENT_TC0 0x11 //RW +#define TMP007_COEFFICIENT_TC1 0x12 //RW + +#define TMP007_MANUFACTURE_ID 0x1E //RO +#define TMP007_DEVICE_ID 0x1F //RO +#define TMP007_MEM_ACCESS 0x2A //RW + +#endif // TMP007_DEFS_H \ No newline at end of file
diff -r a1ed9ce625d4 -r 93710a3abf0a src/TMP007.cpp --- a/src/TMP007.cpp Sun Jun 05 19:38:48 2016 +0000 +++ b/src/TMP007.cpp Sun Jun 05 19:53:43 2016 +0000 @@ -40,7 +40,7 @@ //-------------------------------------------------------------------------------- uint16_t TMP007::readConfig() { - uint16_t res = readWord(TMP007_CONFIG); + uint16_t res = readWord(TMP007_CONFIG); return res; } @@ -50,6 +50,12 @@ return readWord(TMP007_STATUS); } +//-------------------------------------------------------------------------------- +void TMP007::writeStatusMask(const uint16_t value) +{ + writeWord(TMP007_STATUS_MASK, value); +} + //-------------------------------------------------------------------------------- /** TMP007 Config method. * Used for configuring the sensor with desired samples. @@ -70,14 +76,7 @@ */ uint16_t TMP007::readRawLocalTemperature() { - int16_t raw = 0; - char reg = TMP007_LOCAL_TEMP; - char data[2]; - - _i2cPort.write(_addr, ®, 1); - _i2cPort.read(_addr, data, 2); - - raw = (data[0] << 8) | data[1] ; + uint16_t raw = readWord(TMP007_LOCAL_TEMP); raw >>= 2; return raw; @@ -89,15 +88,7 @@ */ uint16_t TMP007::readRawSensorVoltage() { - char reg=TMP007_SENSOR_VOLT; - char data[2]; - - _i2cPort.write(_addr, ®, 1); - _i2cPort.read(_addr, data, 2); - - int16_t raw = (data[0] << 8) | data[1] ; - - return raw; + return readWord(TMP007_SENSOR_VOLT); } //-------------------------------------------------------------------------------- @@ -115,8 +106,7 @@ // Equations for calculating temperature found in section 7.3.4 in the user guide double tdie_tref = Tdie - TMP007_TREF; - double S = (1 + TMP007_A1*tdie_tref + - TMP007_A2*tdie_tref*tdie_tref); + double S = (1 + TMP007_A1*tdie_tref + TMP007_A2*tdie_tref*tdie_tref); S *= TMP007_S0; S /= 10000000; S /= 10000000;