Paparazzi UAS  v4.0.4_stable-3-gf39211a
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
temp_tmp102.c
Go to the documentation of this file.
1 /*
2  * $Id: temp_tmp102.c $
3  *
4  * Copyright (C) 2010 Martin Mueller
5  *
6  * This file is part of paparazzi.
7  *
8  * paparazzi is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2, or (at your option)
11  * any later version.
12  *
13  * paparazzi is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with paparazzi; see the file COPYING. If not, write to
20  * the Free Software Foundation, 59 Temple Place - Suite 330,
21  * Boston, MA 02111-1307, USA.
22  *
23  */
24 
33 
34 #include "mcu_periph/i2c.h"
35 #include "led.h"
36 #include "mcu_periph/uart.h"
37 #include "messages.h"
39 
40 #ifndef DOWNLINK_DEVICE
41 #define DOWNLINK_DEVICE DOWNLINK_AP_DEVICE
42 #endif
43 
47 
48 #ifndef TMP_I2C_DEV
49 #define TMP_I2C_DEV i2c0
50 #endif
51 
52 /*
53  address depends on to what pin A0 is connected to
54  A0: GND Vcc SDA SCL
55  Addr: 0x90 0x92 0x94 0x96
56 */
57 
58 #ifndef TMP102_SLAVE_ADDR
59 #define TMP102_SLAVE_ADDR 0x90
60 #endif
61 
62 /* OS=0 R1=1 R0=1 F1=0 POL=0 TM=0 SD=0 */
63 #define TMP102_CONF1 0x60
64 /* CR1=1 CR0=1 AL=1 EM=1 0000 */
65 #define TMP102_CONF2 0xF0
66 
67 
68 void tmp102_init(void) {
70  /* configure 8Hz and enhanced mode */
75 }
76 
77 void tmp102_periodic( void ) {
81 }
82 
83 void tmp102_event( void ) {
84 
86 
87  uint16_t tmp_temperature;
88 
89  /* read two byte temperature */
90  tmp_temperature = tmp_trans.buf[0] << 8;
91  tmp_temperature |= tmp_trans.buf[1];
92  tmp_temperature >>= 3;
93  if (tmp_temperature & 0x1000)
94  tmp_temperature |= 0xE000;
95 
96  ftmp_temperature = ((int16_t) tmp_temperature) / 16.;
97 
98  DOWNLINK_SEND_TMP_STATUS(DefaultChannel, DefaultDevice, &tmp_temperature, &ftmp_temperature);
100  }
101 }
unsigned short uint16_t
Definition: types.h:16
arch independent UART (Universal Asynchronous Receiver/Transmitter) API
void tmp102_event(void)
Definition: temp_tmp102.c:83
#define TMP102_CONF1
Definition: temp_tmp102.c:63
#define I2CTransmit(_p, _t, _s_addr, _len)
Definition: i2c.h:148
#define TMP_I2C_DEV
Definition: temp_tmp102.c:49
#define FALSE
Definition: imu_chimu.h:141
#define TMP102_CONF2
Definition: temp_tmp102.c:65
signed short int16_t
Definition: types.h:17
enum I2CTransactionStatus status
Definition: i2c.h:47
float ftmp_temperature
Definition: temp_tmp102.c:45
#define TRUE
Definition: imu_chimu.h:144
volatile uint8_t buf[I2C_BUF_LEN]
Definition: i2c.h:46
struct i2c_transaction tmp_trans
Definition: temp_tmp102.c:46
unsigned char uint8_t
Definition: types.h:14
#define I2CTransceive(_p, _t, _s_addr, _len_w, _len_r)
Definition: i2c.h:156
void tmp102_periodic(void)
Definition: temp_tmp102.c:77
void tmp102_init(void)
Definition: temp_tmp102.c:68
#define TMP102_CONF_REG
Definition: temp_tmp102.h:7
uint8_t tmp_meas_started
Definition: temp_tmp102.c:44
arch independent LED (Light Emitting Diodes) API
#define TMP102_TEMP_REG
Definition: temp_tmp102.h:6
#define TMP102_SLAVE_ADDR
Definition: temp_tmp102.c:59