Paparazzi UAS  v7.0_unstable
Paparazzi is a free software Unmanned Aircraft System.
temp_lm75.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 "pprzlink/messages.h"
37 
38 
41 
42 #ifndef LM75_I2C_DEV
43 #define LM75_I2C_DEV i2c0
44 #endif
45 
46 /* address can be set through A0..A2, starting at 0x90 */
47 
48 #ifndef LM75_SLAVE_ADDR
49 #define LM75_SLAVE_ADDR 0x90
50 #endif
51 
52 void lm75_init(void)
53 {
55 }
56 
57 void lm75_periodic(void)
58 {
61 }
62 
63 void lm75_event(void)
64 {
66  uint16_t lm75_temperature;
67  float flm75_temperature;
68 
69  /* read two byte temperature */
70  lm75_temperature = lm75_trans.buf[0] << 8;
71  lm75_temperature |= lm75_trans.buf[1];
72  lm75_temperature >>= 7;
73  if (lm75_temperature & 0x0100) {
74  lm75_temperature |= 0xFE00;
75  }
76 
77  flm75_temperature = ((int16_t) lm75_temperature) / 2.;
78 
79  DOWNLINK_SEND_TMP_STATUS(DefaultChannel, DefaultDevice, &lm75_temperature, &flm75_temperature);
81  }
82 }
volatile uint8_t buf[I2C_BUF_LEN]
Transaction buffer With I2C_BUF_LEN number of bytes.
Definition: i2c.h:122
enum I2CTransactionStatus status
Transaction status.
Definition: i2c.h:126
bool 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:344
@ I2CTransSuccess
transaction successfully finished by I2C driver
Definition: i2c.h:57
@ I2CTransDone
transaction set to done by user level
Definition: i2c.h:59
I2C transaction structure.
Definition: i2c.h:93
Architecture independent I2C (Inter-Integrated Circuit Bus) API.
arch independent LED (Light Emitting Diodes) API
void lm75_event(void)
Definition: temp_lm75.c:63
uint8_t lm75_meas_started
Definition: temp_lm75.c:39
void lm75_init(void)
Definition: temp_lm75.c:52
#define LM75_I2C_DEV
Definition: temp_lm75.c:43
#define LM75_SLAVE_ADDR
Definition: temp_lm75.c:49
void lm75_periodic(void)
Definition: temp_lm75.c:57
struct i2c_transaction lm75_trans
Definition: temp_lm75.c:40
#define LM75_TEMP_REG
Definition: temp_lm75.h:6
arch independent UART (Universal Asynchronous Receiver/Transmitter) API
unsigned short uint16_t
Typedef defining 16 bit unsigned short type.
Definition: vl53l1_types.h:88
short int16_t
Typedef defining 16 bit short type.
Definition: vl53l1_types.h:93
unsigned char uint8_t
Typedef defining 8 bit unsigned char type.
Definition: vl53l1_types.h:98