Paparazzi UAS  v6.2_unstable
Paparazzi is a free software Unmanned Aircraft System.
baro_ms5611_i2c.c
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2011-2013 The Paparazzi Team
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 "math/pprz_isa.h"
33 #include "mcu_periph/sys_time.h"
34 #include "modules/core/abi.h"
35 #include "mcu_periph/uart.h"
36 #include "pprzlink/messages.h"
38 
39 
40 #ifndef MS5611_I2C_DEV
41 #define MS5611_I2C_DEV i2c0
42 #endif
43 
44 /* address can be 0xEC or 0xEE (CSB\ low = 0xEE) */
45 #ifndef MS5611_SLAVE_ADDR
46 #define MS5611_SLAVE_ADDR 0xEE
47 #endif
48 
50 #ifndef MS5611_TYPE_MS5607
51 #define MS5611_TYPE_MS5607 FALSE
52 #endif
53 PRINT_CONFIG_VAR(MS5611_TYPE_MS5607)
54 
56 
61 
64 
65 
66 void baro_ms5611_init(void)
67 {
69 
70  baro_ms5611_enabled = true;
71  baro_ms5611_alt_valid = false;
72 
75 }
76 
78 {
79 
81 
82 #if SENSOR_SYNC_SEND
83  // send coeff every 30s
84  RunOnceEvery((30 * BARO_MS5611_PERIODIC_CHECK_FREQ), baro_ms5611_send_coeff());
85 #endif
86 }
87 
89 void baro_ms5611_read(void)
90 {
91  if (sys_time.nb_sec > 1) {
93  }
94 }
95 
97 {
98 
100 
102  uint32_t now_ts = get_sys_time_usec();
103  float pressure = (float)baro_ms5611.data.pressure;
104  AbiSendMsgBARO_ABS(BARO_MS5611_SENDER_ID, now_ts, pressure);
105  float temp = baro_ms5611.data.temperature / 100.0f;
106  AbiSendMsgTEMPERATURE(BARO_MS5611_SENDER_ID, temp);
107  baro_ms5611.data_available = false;
108 
110  baro_ms5611_alt_valid = true;
111 
112 #ifdef SENSOR_SYNC_SEND
113  fbaroms = baro_ms5611.data.pressure / 100.;
114  DOWNLINK_SEND_BARO_MS5611(DefaultChannel, DefaultDevice,
116  &fbaroms, &temp);
117 #endif
118  }
119 }
120 
122 {
123  if (baro_ms5611.initialized) {
124  DOWNLINK_SEND_MS5611_COEFF(DefaultChannel, DefaultDevice,
125  &baro_ms5611.data.c[0],
126  &baro_ms5611.data.c[1],
127  &baro_ms5611.data.c[2],
128  &baro_ms5611.data.c[3],
129  &baro_ms5611.data.c[4],
130  &baro_ms5611.data.c[5],
131  &baro_ms5611.data.c[6],
132  &baro_ms5611.data.c[7]);
133  }
134 }
Ms5611_I2c::initialized
bool initialized
config done flag
Definition: ms5611_i2c.h:41
uint32_t
unsigned int uint32_t
Typedef defining 32 bit unsigned int type.
Definition: vl53l1_types.h:78
baro_ms5611_r
float baro_ms5611_r
Definition: baro_ms5611_i2c.c:62
Ms5611Data::temperature
int32_t temperature
temperature with 0.01 degrees Celsius resolution
Definition: ms5611.h:53
baro_ms5611_i2c.h
abi.h
baro_ms5611_sigma2
float baro_ms5611_sigma2
Definition: baro_ms5611_i2c.c:63
ms5611_i2c_init
void ms5611_i2c_init(struct Ms5611_I2c *ms, struct i2c_periph *i2c_p, uint8_t addr, bool is_ms5607)
Definition: ms5611_i2c.c:33
ms5611_i2c_read
static void ms5611_i2c_read(struct Ms5611_I2c *ms)
convenience function to trigger new measurement.
Definition: ms5611_i2c.h:59
baro_ms5611_read
void baro_ms5611_read(void)
trigger new measurement or initialize if needed
Definition: baro_ms5611_i2c.c:89
Ms5611Data::d2
uint32_t d2
Definition: ms5611.h:56
Mpl3115::pressure
uint32_t pressure
pressure in 1/4 Pascal
Definition: mpl3115.h:80
MS5611_SLAVE_ADDR
#define MS5611_SLAVE_ADDR
Definition: baro_ms5611_i2c.c:46
get_sys_time_usec
uint32_t get_sys_time_usec(void)
Get the time in microseconds since startup.
Definition: sys_time_arch.c:75
MS5611_TYPE_MS5607
#define MS5611_TYPE_MS5607
set to TRUE if baro is actually a MS5607
Definition: baro_ms5611_i2c.c:51
baro_ms5611_alt_valid
bool baro_ms5611_alt_valid
Definition: baro_ms5611_i2c.c:59
uart.h
arch independent UART (Universal Asynchronous Receiver/Transmitter) API
pprz_isa_altitude_of_pressure
static float pprz_isa_altitude_of_pressure(float pressure)
Get absolute altitude from pressure (using simplified equation).
Definition: pprz_isa.h:82
BARO_MS5611_SIGMA2
#define BARO_MS5611_SIGMA2
Definition: baro_ms5611_i2c.h:10
Ms5611_I2c::data_available
volatile bool data_available
data ready flag
Definition: ms5611_i2c.h:42
fbaroms
float fbaroms
Definition: baro_ms5611_i2c.c:57
Ms5611_I2c
Definition: ms5611_i2c.h:36
Ms5611_I2c::data
struct Ms5611Data data
Definition: ms5611_i2c.h:43
MS5611_I2C_DEV
#define MS5611_I2C_DEV
Definition: baro_ms5611_i2c.c:41
sys_time.h
Architecture independent timing functions.
baro_ms5611_init
void baro_ms5611_init(void)
Definition: baro_ms5611_i2c.c:66
ms5611_i2c_event
void ms5611_i2c_event(struct Ms5611_I2c *ms)
Definition: ms5611_i2c.c:119
baro_ms5611_periodic_check
void baro_ms5611_periodic_check(void)
Definition: baro_ms5611_i2c.c:77
baro_ms5611
struct Ms5611_I2c baro_ms5611
Definition: baro_ms5611_i2c.c:55
BARO_MS5611_R
#define BARO_MS5611_R
Definition: baro_ms5611_i2c.h:9
ms5611_i2c_periodic_check
void ms5611_i2c_periodic_check(struct Ms5611_I2c *ms)
Periodic function to ensure proper delay after triggering reset or conversion.
Definition: ms5611_i2c.c:78
sys_time
Definition: sys_time.h:71
baro_ms5611_alt
float baro_ms5611_alt
Definition: baro_ms5611_i2c.c:58
baro_ms5611_event
void baro_ms5611_event(void)
Definition: baro_ms5611_i2c.c:96
sys_time::nb_sec
volatile uint32_t nb_sec
full seconds since startup
Definition: sys_time.h:72
baro_ms5611_send_coeff
void baro_ms5611_send_coeff(void)
Definition: baro_ms5611_i2c.c:121
BARO_MS5611_SENDER_ID
#define BARO_MS5611_SENDER_ID
Definition: abi_sender_ids.h:40
ftempms
float ftempms
Definition: baro_ms5611_i2c.c:57
Ms5611Data::pressure
uint32_t pressure
pressure in Pascal (0.01mbar)
Definition: ms5611.h:52
Ms5611Data::d1
uint32_t d1
Definition: ms5611.h:55
Ms5611Data::c
uint16_t c[PROM_NB]
Definition: ms5611.h:54
pprz_isa.h
Paparazzi atmospheric pressure conversion utilities.
baro_ms5611_enabled
bool baro_ms5611_enabled
Definition: baro_ms5611_i2c.c:60