Drivber for Ti's TMP007 Infrared Thermopile Sensor with Integrated Math Engine
Diff: include/TMP007.h
- Revision:
- 0:a1ed9ce625d4
- Child:
- 1:93710a3abf0a
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/include/TMP007.h Sun Jun 05 19:38:48 2016 +0000 @@ -0,0 +1,144 @@ +/** TMP007 Temperature methods. + * Used for interfacing the TMP007 with the mbed. + * + * Example: + * @code + * #include "mbed.h" + * #include "TMP007.h" + + * #define Address 0x40 // depending on pin ADR0 and ADR1 it can be either 0x40, 0x41, 0x44 or 0x45 + * + * TMP007 sensor(p9, p10, Address); + * + * int main() + * { + * while(1) { + * printf("TTemperature: %f F \r \n", sensor.readObjTempF(Address)); + * wait(0.5); + * } + * } + * @endcode + */ +#ifndef TMP007_H +#define TMP007_H + +#include <I2C.h> +#include "PinNames.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 +{ +public: + + // Constructor + TMP007(PinName sda, PinName scl, int addr); + + void writeConfig(const uint16_t value); + uint16_t readConfig() ; + + uint16_t readStatus(); + + /** Configures sensor, use before reading from it */ + void setSamples(const uint16_t samples); + + /** Read raw sensor temperature */ + uint16_t readRawLocalTemperature(); + + /** Read raw thermopile voltage */ + uint16_t readRawSensorVoltage(); + + /** Calculate object temperature (C) based on raw sensor temp and thermopile voltage */ + double readObjTempC(); + + /** Calculate object temperature (F) based on raw sensor temp and thermopile voltage */ + double readObjTempF(); + + /** Caculate sensor temperature (C) based on raw reading */ + double readDieTempC(); + + /** Caculate sensor temperature (F) based on raw reading */ + 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. + * + * @param reg Register location to write into + * @param word Word to write + * @return True if successful + */ + bool writeWord(const uint8_t reg, const uint16_t word); + + /** + * Read a word value from the register. Note: the device must have the + * auto-increment bit set in the MODE1 register to work. + * + * @param reg Register location to read from + * @return Value in the specified register + */ + uint16_t readWord(const uint8_t reg); + + + +private: + mbed::I2C _i2cPort; + uint8_t _addr; + +}; + +#endif \ No newline at end of file