Paparazzi UAS  v5.8.2_stable-0-g6260b7c
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
temp_tmp102.c
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2010 Martin Mueller
3  *
4  * This file is part of paparazzi.
5  *
6  * paparazzi is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2, or (at your option)
9  * any later version.
10  *
11  * paparazzi is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with paparazzi; see the file COPYING. If not, write to
18  * the Free Software Foundation, 59 Temple Place - Suite 330,
19  * Boston, MA 02111-1307, USA.
20  *
21  */
22 
31 
32 #include "mcu_periph/i2c.h"
33 #include "led.h"
34 #include "mcu_periph/uart.h"
35 #include "messages.h"
37 
38 
42 
43 #ifndef TMP_I2C_DEV
44 #define TMP_I2C_DEV i2c0
45 #endif
46 
47 /*
48  address depends on to what pin A0 is connected to
49  A0: GND Vcc SDA SCL
50  Addr: 0x90 0x92 0x94 0x96
51 */
52 
53 #ifndef TMP102_SLAVE_ADDR
54 #define TMP102_SLAVE_ADDR 0x90
55 #endif
56 
57 /* OS=0 R1=1 R0=1 F1=0 POL=0 TM=0 SD=0 */
58 #define TMP102_CONF1 0x60
59 /* CR1=1 CR0=1 AL=1 EM=1 0000 */
60 #define TMP102_CONF2 0xF0
61 
62 
63 void tmp102_init(void)
64 {
66  /* configure 8Hz and enhanced mode */
71 }
72 
73 void tmp102_periodic(void)
74 {
78 }
79 
80 void tmp102_event(void)
81 {
82 
84 
85  uint16_t tmp_temperature;
86 
87  /* read two byte temperature */
88  tmp_temperature = tmp_trans.buf[0] << 8;
89  tmp_temperature |= tmp_trans.buf[1];
90  tmp_temperature >>= 3;
91  if (tmp_temperature & 0x1000) {
92  tmp_temperature |= 0xE000;
93  }
94 
95  ftmp_temperature = ((int16_t) tmp_temperature) / 16.;
96 
97  DOWNLINK_SEND_TMP_STATUS(DefaultChannel, DefaultDevice, &tmp_temperature, &ftmp_temperature);
99  }
100 }
unsigned short uint16_t
Definition: types.h:16
arch independent UART (Universal Asynchronous Receiver/Transmitter) API
void tmp102_event(void)
Definition: temp_tmp102.c:80
volatile uint8_t buf[I2C_BUF_LEN]
Transaction buffer With I2C_BUF_LEN number of bytes.
Definition: i2c.h:122
#define TMP102_CONF1
Definition: temp_tmp102.c:58
transaction successfully finished by I2C driver
Definition: i2c.h:57
#define TMP_I2C_DEV
Definition: temp_tmp102.c:44
bool_t i2c_transceive(struct i2c_periph *p, struct i2c_transaction *t, uint8_t s_addr, uint8_t len_w, uint16_t len_r)
Submit a write/read transaction.
Definition: i2c.c:278
#define FALSE
Definition: std.h:5
#define TRUE
Definition: std.h:4
transaction set to done by user level
Definition: i2c.h:59
#define TMP102_CONF2
Definition: temp_tmp102.c:60
bool_t i2c_transmit(struct i2c_periph *p, struct i2c_transaction *t, uint8_t s_addr, uint8_t len)
Submit a write only transaction.
Definition: i2c.c:258
signed short int16_t
Definition: types.h:17
float ftmp_temperature
Definition: temp_tmp102.c:40
I2C transaction structure.
Definition: i2c.h:93
enum I2CTransactionStatus status
Transaction status.
Definition: i2c.h:126
struct i2c_transaction tmp_trans
Definition: temp_tmp102.c:41
unsigned char uint8_t
Definition: types.h:14
void tmp102_periodic(void)
Definition: temp_tmp102.c:73
void tmp102_init(void)
Definition: temp_tmp102.c:63
#define TMP102_CONF_REG
Definition: temp_tmp102.h:7
uint8_t tmp_meas_started
Definition: temp_tmp102.c:39
arch independent LED (Light Emitting Diodes) API
#define TMP102_TEMP_REG
Definition: temp_tmp102.h:6
#define TMP102_SLAVE_ADDR
Definition: temp_tmp102.c:54
Architecture independent I2C (Inter-Integrated Circuit Bus) API.