TMP006: Adding very basic support for TMP007

Signed-off-by: Abhishek Malik <abhishek.malik@intel.com>
This commit is contained in:
Abhishek Malik 2017-05-08 10:30:43 -07:00
parent 7688e5f230
commit 6c383dbd42
3 changed files with 55 additions and 8 deletions

View File

@ -44,8 +44,13 @@ int main(int argc, char **argv)
//! [Interesting] //! [Interesting]
std::cout << "Initializing test-application..." << std::endl; std::cout << "Initializing test-application..." << std::endl;
// please make sure that you have the right i2c address for your device
// the correct range of addresses is 0x40 - 0x47
// Instantiate an TMP006 instance on bus 1 // Instantiate an TMP006 instance on bus 1
upm::TMP006 *mySensor = new upm::TMP006(1); upm::TMP006 *mySensor = new upm::TMP006(1, TMP006_CONFIG_CR_DEF, TMP006_I2C_ADDRESS);
// you can also get basic tmp007 functionality by initializing it as follows
//upm::TMP006 *mySensor = new upm::TMP006(1, TMP006_CONFIG_CR_DEF, TMP007_I2C_ADDRESS);
// activate periodic measurements // activate periodic measurements
mySensor->setActive(); mySensor->setActive();

View File

@ -42,9 +42,11 @@ TMP006::TMP006(int bus, uint8_t conv_rate, int devAddr) : m_i2ControlCtx(bus) {
m_temperature = 0; m_temperature = 0;
m_name = TMP006_NAME;; m_name = TMP006_NAME;
m_controlAddr = devAddr; m_controlAddr = devAddr;
sensorType = TMP006_SEN;
m_bus = bus; m_bus = bus;
if (conv_rate > TMP006_CONFIG_CR_AS16) { if (conv_rate > TMP006_CONFIG_CR_AS16) {
@ -85,20 +87,46 @@ TMP006::checkID(void)
uint8_t tmp[2]; uint8_t tmp[2];
uint16_t id; uint16_t id;
int re = 0; int re = 0;
int ret = 0;
tmp[0] = 0;tmp[1] = 0;
// Checking if TMP006
re = m_i2ControlCtx.readBytesReg(TMP006_DEVICE_ID_REG, tmp, 2); re = m_i2ControlCtx.readBytesReg(TMP006_DEVICE_ID_REG, tmp, 2);
if (re != 2) { if (re != 2) {
/* not enough bytes were read! */ /* not enough bytes were read! */
return -1; //return -1;
ret = -1;
} }
id = ((uint16_t)tmp[0] << 8) | tmp[1]; id = ((uint16_t)tmp[0] << 8) | tmp[1];
if (id != TMP006_DEVICE_ID) { if (id != TMP006_DEVICE_ID) {
return -1; //return -1;
ret = -1;
} else {
sensorType = TMP006_SEN;
return 0;
} }
return 0; // Checking if TMP007
re = m_i2ControlCtx.readBytesReg(TMP007_DEVICE_ID_REG, tmp, 2);
if (re != 2) {
/* not enough bytes were read! */
//return -1;
ret = -1;
}
id = ((uint16_t)tmp[0] << 8) | tmp[1];
if (id != TMP007_DEVICE_ID) {
//return -1;
ret = -1;
} else {
sensorType = TMP007_SEN;
return 0;
}
return ret;
} }
void void
@ -174,9 +202,11 @@ TMP006::sampleData(void)
*drdy = buf[0] & (TMP006_DRDY_DATA_RDY); *drdy = buf[0] & (TMP006_DRDY_DATA_RDY);
if(! (*drdy)) { if(sensorType == TMP006_SEN) {
/* conversation in progress */ if(! (*drdy)) {
return -1; /* conversation in progress */
return -1;
}
} }
tmp = m_i2ControlCtx.readWordReg(TMP006_SENSOR_VOLTAGE); tmp = m_i2ControlCtx.readWordReg(TMP006_SENSOR_VOLTAGE);

View File

@ -35,6 +35,10 @@
#define TMP006_MANUFACTURER_ID 0x5449 #define TMP006_MANUFACTURER_ID 0x5449
#define TMP006_DEVICE_ID 0x0067 #define TMP006_DEVICE_ID 0x0067
#define TMP007_I2C_ADDRESS 0x40
// this should actually be split
#define TMP007_DEVICE_ID 0x0078
#ifndef TMP006_CONVERSION_TIME #ifndef TMP006_CONVERSION_TIME
#define TMP006_CONVERSION_TIME 1E6 /**< Default Conversion Time in us */ #define TMP006_CONVERSION_TIME 1E6 /**< Default Conversion Time in us */
#endif #endif
@ -46,6 +50,9 @@
#define TMP006_MANUFACTURER_ID_REG 0xFE #define TMP006_MANUFACTURER_ID_REG 0xFE
#define TMP006_DEVICE_ID_REG 0xFF #define TMP006_DEVICE_ID_REG 0xFF
/* TMP007 Register Map */
#define TMP007_DEVICE_ID_REG 0x1F
/* TMP006 configuration register bitmap */ /* TMP006 configuration register bitmap */
#define TMP006_RST_SOFT (1 << 15) #define TMP006_RST_SOFT (1 << 15)
@ -86,6 +93,10 @@
#define TMP006_CCONST_C2 13.4 /* Constant \f$c_{\mathrm{2}}\f$ */ #define TMP006_CCONST_C2 13.4 /* Constant \f$c_{\mathrm{2}}\f$ */
#define TMP006_CCONST_LSB_SIZE 156.25E-9 /* Sensor Voltage Register LSB Size */ #define TMP006_CCONST_LSB_SIZE 156.25E-9 /* Sensor Voltage Register LSB Size */
typedef enum {
TMP006_SEN,
TMP007_SEN } tmp_t;
namespace upm { namespace upm {
/** /**
@ -195,6 +206,7 @@ class TMP006 {
int m_controlAddr; int m_controlAddr;
int m_bus; int m_bus;
mraa::I2c m_i2ControlCtx; mraa::I2c m_i2ControlCtx;
tmp_t sensorType;
int32_t m_temperature; int32_t m_temperature;
}; };