adding tmp102 sensor for the econotag from Hedde Bosman.

This can be pulling in as a common driver if we can make a generic i2c
Contiki driver.
This commit is contained in:
Mariano Alvira 2011-07-18 07:30:49 -04:00
parent 485d6716e0
commit 697af5ef08
3 changed files with 132 additions and 1 deletions

View file

@ -4,7 +4,7 @@ CONTIKI_TARGET_DIRS = . dev apps net
CONTIKI_CORE=contiki-mc1322x-main
CONTIKI_TARGET_MAIN = ${CONTIKI_CORE}.o
CONTIKI_TARGET_SOURCEFILES += contiki-mc1322x-main.c clock.c button-sensor.c sensors.c slip.c light-sensor.c
CONTIKI_TARGET_SOURCEFILES += contiki-mc1322x-main.c clock.c button-sensor.c sensors.c slip.c light-sensor.c tmp102-sensor.c
CONTIKIMC1322X=$(CONTIKI)/cpu/mc1322x
CONTIKIBOARD=.

View file

@ -0,0 +1,87 @@
/*
* An interface to the TI TMP102 temperature sensor
* 12 bit temperature reading, 0.5 deg. Celsius accuracy
* -----------------------------------------------------------------
*
* Author : Hedde Bosman (heddebosman@incas3.eu)
*/
#include "contiki.h"
#include "lib/sensors.h"
#include "dev/tmp102-sensor.h"
#ifndef bool
#define bool uint8_t
#endif
#ifndef false
#define false 0
#endif
#ifndef true
#define true 1
#endif
static void set_configuration(uint8_t rate, bool precision) {
uint8_t tx_buf[] = {TMP102_REGISTER_CONFIGURATION,
0,
(precision ? TMP102_CONF_EXTENDED_MODE : 0) | ((rate << 6) & TMP102_CONF_CONVERSION_RATE)
};
i2c_transmitinit(TMP102_ADDR, 3, tx_buf);
}
/*---------------------------------------------------------------------------*/
static int value(int type) {
uint8_t reg = TMP102_REGISTER_TEMPERATURE;
uint8_t temp[2];
int16_t temperature = 0;
/* transmit the register to start reading from */
i2c_transmitinit(TMP102_ADDR, 1, &reg);
while (!i2c_transferred()); // wait for data to arrive
/* receive the data */
i2c_receiveinit(TMP102_ADDR, 2, temp);
while (!i2c_transferred()); // wait for data to arrive
// 12 bit normal mode
temperature = ((temp[0] <<8) | (temp[1])) >> 4; // lsb
// 13 bit extended mode
//temperature = ((temp[0] <<8) | (temp[1])) >> 3; // lsb
temperature = (100*temperature)/16; // in 100th of degrees
return temperature;
}
/*---------------------------------------------------------------------------*/
static int status(int type) {
switch (type) {
case SENSORS_ACTIVE:
case SENSORS_READY:
return 1; // fix?
break;
}
return 0;
}
/*---------------------------------------------------------------------------*/
static int configure(int type, int c) {
switch (type) {
case SENSORS_ACTIVE:
if (c) {
// set active
set_configuration(1, false); // every 1 second, 12bit precision
} else {
// set inactive
}
return 1;
}
return 0;
}
/*---------------------------------------------------------------------------*/
SENSORS_SENSOR(tmp102_sensor, "Temperature", value, configure, status); // register the functions

View file

@ -0,0 +1,44 @@
/*
* An interface to the TI TMP102 temperature sensor
* 12 bit temperature reading, 0.5 deg. Celsius accuracy
* -----------------------------------------------------------------
*
* Author : Hedde Bosman (heddebosman@incas3.eu)
*/
#ifndef __TMP102_SENSOR_H__
#define __TMP102_SENSOR_H__
#include "i2c.h"
#include "lib/sensors.h"
extern const struct sensors_sensor tmp102_sensor;
#define TMP102_VALUE_TYPE_DEFAULT 0
#define TMP102_ADDR 0x48 // if A0 @ ground
//#define TMP102_ADDR 0x49 // if A0 @ V+
//#define TMP102_ADDR 0x4A // if A0 @ SDA
//#define TMP102_ADDR 0x4B // if A0 @ SCL
#define TMP102_REGISTER_TEMPERATURE 0x00
#define TMP102_REGISTER_CONFIGURATION 0x01
#define TMP102_REGISTERO_T_LOW 0x02
#define TMP102_REGISTERO_T_HIGH 0x03
#define TMP102_CONF_EXTENDED_MODE 0x10
#define TMP102_CONF_ALERT 0x20
#define TMP102_CONF_CONVERSION_RATE 0xC0 // 2 bits indicating conversion rate (0.25, 1, 4, 8 Hz)
#define TMP102_CONF_SHUTDOWN_MODE 0x01
#define TMP102_CONF_THERMOSTAT_MODE 0x02 // 0 = comparator mode, 1 = interrupt mode
#define TMP102_CONF_POLARITY 0x04
#define TMP102_CONF_FAULT_QUEUE 0x18 // 2 bits indicating number of faults
#define TMP102_CONF_RESOLUTION 0x60 // 2 bits indicating resolution, default = b11 = 0x60
#define TMP102_CONF_ONESHOT_READY 0x80 //
#endif