From e122f42ed9963c9f3f82e36352099eff3c231d07 Mon Sep 17 00:00:00 2001 From: Martin Mueller Date: Sat, 16 Oct 2010 09:00:42 +0000 Subject: [PATCH] some more meteo sensor modules. --- conf/airframes/mm/fixed-wing/funjetmm.xml | 4 +- conf/messages.xml | 22 +++-- conf/modules/ir_mlx.xml | 14 +++ conf/modules/temp_tmp102.xml | 14 +++ sw/airborne/modules/meteo/ir_mlx.c | 101 ++++++++++++++++++++++ sw/airborne/modules/meteo/ir_mlx.h | 18 ++++ sw/airborne/modules/meteo/temp_tmp102.c | 96 ++++++++++++++++++++ sw/airborne/modules/meteo/temp_tmp102.h | 16 ++++ 8 files changed, 278 insertions(+), 7 deletions(-) create mode 100644 conf/modules/ir_mlx.xml create mode 100644 conf/modules/temp_tmp102.xml create mode 100644 sw/airborne/modules/meteo/ir_mlx.c create mode 100644 sw/airborne/modules/meteo/ir_mlx.h create mode 100644 sw/airborne/modules/meteo/temp_tmp102.c create mode 100644 sw/airborne/modules/meteo/temp_tmp102.h diff --git a/conf/airframes/mm/fixed-wing/funjetmm.xml b/conf/airframes/mm/fixed-wing/funjetmm.xml index 7eb6bb6c9a..03bdacaa4d 100755 --- a/conf/airframes/mm/fixed-wing/funjetmm.xml +++ b/conf/airframes/mm/fixed-wing/funjetmm.xml @@ -55,9 +55,11 @@ + + diff --git a/conf/messages.xml b/conf/messages.xml index 32f8bf0d25..d45540dee8 100644 --- a/conf/messages.xml +++ b/conf/messages.xml @@ -531,8 +531,18 @@ - - + + + + + + + + + + + + @@ -548,8 +558,8 @@ - - + + @@ -563,8 +573,8 @@ - - + + diff --git a/conf/modules/ir_mlx.xml b/conf/modules/ir_mlx.xml new file mode 100644 index 0000000000..7dec6d1485 --- /dev/null +++ b/conf/modules/ir_mlx.xml @@ -0,0 +1,14 @@ + + + +
+ +
+ + + + + + +
+ diff --git a/conf/modules/temp_tmp102.xml b/conf/modules/temp_tmp102.xml new file mode 100644 index 0000000000..a21a3b02a7 --- /dev/null +++ b/conf/modules/temp_tmp102.xml @@ -0,0 +1,14 @@ + + + +
+ +
+ + + + + + +
+ diff --git a/sw/airborne/modules/meteo/ir_mlx.c b/sw/airborne/modules/meteo/ir_mlx.c new file mode 100644 index 0000000000..a619c9ab45 --- /dev/null +++ b/sw/airborne/modules/meteo/ir_mlx.c @@ -0,0 +1,101 @@ +/* + * $Id: ir_mlx.c $ + * + * Copyright (C) 2010 Martin Mueller + * + * This file is part of paparazzi. + * + * paparazzi is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * paparazzi is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with paparazzi; see the file COPYING. If not, write to + * the Free Software Foundation, 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + * + */ + +/** \file ir_mlx.c + * \brief Melexis 90614 I2C + * + * This reads the values for temperatures from the Melexis 90614 IR sensor through I2C. + */ + + +#include "ir_mlx.h" + +#include "sys_time.h" +#include "i2c.h" +#include "led.h" +#include "uart.h" +#include "messages.h" +#include "downlink.h" + +#ifndef MLX_I2C_DEV +#define MLX_I2C_DEV i2c0 +#endif + +struct i2c_transaction mlx_trans; + +uint8_t ir_mlx_status; +uint16_t ir_mlx_itemp_case; +float ir_mlx_temp_case; +uint16_t ir_mlx_itemp_obj; +float ir_mlx_temp_obj; + +/* I2C address is set to 3 */ +#define MLX90614_ADDR 0x06 + +// printf("Ta = %2.2f°C (0x%04X)\n", (tp*0.02)-273.15, tp); + + +void ir_mlx_init( void ) { + ir_mlx_status = IR_MLX_UNINIT; +} + +void ir_mlx_periodic( void ) { + if (cpu_time_sec > 1) { + /* start two byte case temperature */ + mlx_trans.buf[0] = MLX90614_TA; + I2CTransceive(MLX_I2C_DEV, mlx_trans, MLX90614_ADDR, 1, 2); + ir_mlx_status = IR_MLX_RD_CASE_TEMP; + } +} + +void ir_mlx_event( void ) { + if ((mlx_trans.status == I2CTransSuccess)) { + if (ir_mlx_status == IR_MLX_RD_CASE_TEMP) { + /* read two byte case temperature */ + ir_mlx_itemp_case = mlx_trans.buf[1] << 8; + ir_mlx_itemp_case |= mlx_trans.buf[0]; + ir_mlx_temp_case = ir_mlx_itemp_case*0.02 - 273.15; + + /* start two byte obj temperature */ + mlx_trans.buf[0] = MLX90614_TOBJ; + ir_mlx_status = IR_MLX_RD_CASE_TEMP; + I2CTransceive(MLX_I2C_DEV, mlx_trans, MLX90614_ADDR, 1, 2); + ir_mlx_status = IR_MLX_RD_OBJ_TEMP; + } + else if (ir_mlx_status == IR_MLX_RD_OBJ_TEMP) { + /* read two byte obj temperature */ + ir_mlx_itemp_obj = mlx_trans.buf[1] << 8; + ir_mlx_itemp_obj |= mlx_trans.buf[0]; + ir_mlx_temp_obj = ir_mlx_itemp_obj*0.02 - 273.15; + mlx_trans.status = I2CTransDone; + + DOWNLINK_SEND_MLX_STATUS(DefaultChannel, + &ir_mlx_itemp_case, + &ir_mlx_temp_case, + &ir_mlx_itemp_obj, + &ir_mlx_temp_obj); + } + } +} + diff --git a/sw/airborne/modules/meteo/ir_mlx.h b/sw/airborne/modules/meteo/ir_mlx.h new file mode 100644 index 0000000000..f9ecd9aced --- /dev/null +++ b/sw/airborne/modules/meteo/ir_mlx.h @@ -0,0 +1,18 @@ +#ifndef IR_MLX_H +#define IR_MLX_H + +#include "std.h" + +#define MLX90614_TA 0x06 +#define MLX90614_TOBJ 0x07 + +#define IR_MLX_UNINIT 0 +#define IR_MLX_IDLE 1 +#define IR_MLX_RD_CASE_TEMP 2 +#define IR_MLX_RD_OBJ_TEMP 3 + +void ir_mlx_init(void); +void ir_mlx_periodic(void); +void ir_mlx_event(void); + +#endif diff --git a/sw/airborne/modules/meteo/temp_tmp102.c b/sw/airborne/modules/meteo/temp_tmp102.c new file mode 100644 index 0000000000..3acae39267 --- /dev/null +++ b/sw/airborne/modules/meteo/temp_tmp102.c @@ -0,0 +1,96 @@ +/* + * $Id: temp_tmp102.c $ + * + * Copyright (C) 2010 Martin Mueller + * + * This file is part of paparazzi. + * + * paparazzi is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * paparazzi is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with paparazzi; see the file COPYING. If not, write to + * the Free Software Foundation, 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + * + */ + +/** \file temp_tmp102.c + * \brief TI TMP102 I2C sensor interface + * + * This reads the values for temperature from the TI TMP201 sensor through I2C. + */ + + +#include "temp_tmp102.h" + +#include "i2c.h" +#include "led.h" +#include "uart.h" +#include "messages.h" +#include "downlink.h" + +uint8_t tmp_meas_started; +struct i2c_transaction tmp_trans; + +#ifndef TMP_I2C_DEV +#define TMP_I2C_DEV i2c0 +#endif + +/* + address depends on to what pin A0 is connected to + A0: GND Vcc SDA SCL + Addr: 0x90 0x92 0x94 0x96 +*/ + +#define TMP102_SLAVE_ADDR 0x90 + +/* OS=0 R1=1 R0=1 F1=0 POL=0 TM=0 SD=0 */ +#define TMP102_CONF1 0x60 +/* CR1=1 CR0=1 AL=1 EM=1 0000 */ +#define TMP102_CONF2 0xF0 + + +void tmp102_init(void) { + tmp_meas_started = FALSE; + /* configure 8Hz and enhanced mode */ + tmp_trans.buf[0] = TMP102_CONF_REG; + tmp_trans.buf[1] = TMP102_CONF1; + tmp_trans.buf[2] = TMP102_CONF2; + I2CTransmit(TMP_I2C_DEV, tmp_trans, TMP102_SLAVE_ADDR, 3); +} + +void tmp102_periodic( void ) { + tmp_trans.buf[0] = TMP102_TEMP_REG; + I2CTransceive(TMP_I2C_DEV, tmp_trans, TMP102_SLAVE_ADDR, 1, 2); + tmp_meas_started = TRUE; +} + +void tmp102_event( void ) { + + if ((tmp_trans.status == I2CTransSuccess) && (tmp_meas_started == TRUE)) { + + uint16_t tmp_temperature; + float ftmp_temperature; + + /* read two byte temperature */ + tmp_temperature = tmp_trans.buf[0] << 8; + tmp_temperature |= tmp_trans.buf[1]; + tmp_temperature >>= 3; + if (tmp_temperature & 0x1000) + tmp_temperature |= 0xE000; + + ftmp_temperature = ((int16_t) tmp_temperature) / 16.; + + DOWNLINK_SEND_TMP_STATUS(DefaultChannel, &tmp_temperature, &ftmp_temperature); + tmp_trans.status = I2CTransDone; + } +} + diff --git a/sw/airborne/modules/meteo/temp_tmp102.h b/sw/airborne/modules/meteo/temp_tmp102.h new file mode 100644 index 0000000000..989070b30d --- /dev/null +++ b/sw/airborne/modules/meteo/temp_tmp102.h @@ -0,0 +1,16 @@ +#ifndef TEMP_TMP102_H +#define TEMP_TMP102_H + +#include "std.h" + +#define TMP102_TEMP_REG 0x00 +#define TMP102_CONF_REG 0x01 +#define TMP102_T_LOW_REG 0x02 +#define TMP102_T_HIGH_REG 0x03 + + +void tmp102_init(void); +void tmp102_periodic(void); +void tmp102_event(void); + +#endif