Paparazzi UAS  v6.2_unstable
Paparazzi is a free software Unmanned Aircraft System.
baro_board_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 
30 #include "modules/sensors/baro.h"
31 #include "peripherals/ms5611_i2c.h"
32 
33 #include BOARD_CONFIG // include board specific settings
34 
35 #include "mcu_periph/sys_time.h"
36 #include "led.h"
37 #include "std.h"
38 #include "modules/core/abi.h"
39 
40 #include "mcu_periph/uart.h"
41 #include "pprzlink/messages.h"
43 
44 #if BARO_PERIODIC_FREQUENCY > 100
45 #error "For MS5611 BARO_PERIODIC_FREQUENCY has to be <= 100"
46 #endif
47 
48 
55 #ifndef BB_MS5611_SLAVE_ADDR
56 #define BB_MS5611_SLAVE_ADDR 0xEE
57 #endif
58 
60 #ifndef BB_MS5611_TYPE_MS5607
61 #define BB_MS5611_TYPE_MS5607 FALSE
62 #endif
63 PRINT_CONFIG_VAR(BB_MS5611_TYPE_MS5607)
64 
66 
67 void baro_init(void)
68 {
70 
71 #ifdef BARO_LED
72  LED_OFF(BARO_LED);
73 #endif
74 }
75 
76 void baro_periodic(void)
77 {
78  if (sys_time.nb_sec > 1) {
79 
80  /* call the convenience periodic that initializes the sensor and starts reading*/
82 
83 #if DEBUG
85  RunOnceEvery((50 * 30), DOWNLINK_SEND_MS5611_COEFF(DefaultChannel, DefaultDevice,
86  &bb_ms5611.data.c[0],
87  &bb_ms5611.data.c[1],
88  &bb_ms5611.data.c[2],
89  &bb_ms5611.data.c[3],
90  &bb_ms5611.data.c[4],
91  &bb_ms5611.data.c[5],
92  &bb_ms5611.data.c[6],
93  &bb_ms5611.data.c[7]));
94 #endif
95  }
96 }
97 
98 void baro_event(void)
99 {
100  if (sys_time.nb_sec > 1) {
102 
104  uint32_t now_ts = get_sys_time_usec();
105  AbiSendMsgBARO_ABS(BARO_BOARD_SENDER_ID, now_ts, bb_ms5611.data.pressure);
106  float temp = bb_ms5611.data.temperature / 100.0f;
107  AbiSendMsgTEMPERATURE(BARO_BOARD_SENDER_ID, temp);
108  bb_ms5611.data_available = false;
109 
110 #ifdef BARO_LED
111  RunOnceEvery(10, LED_TOGGLE(BARO_LED));
112 #endif
113 
114 #if DEBUG
115  float fbaroms = bb_ms5611.data.pressure / 100.;
116  DOWNLINK_SEND_BARO_MS5611(DefaultChannel, DefaultDevice,
118  &fbaroms, &temp);
119 #endif
120  }
121  }
122 }
baro_init
void baro_init(void)
Definition: baro_board_ms5611_i2c.c:67
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_BOARD_SENDER_ID
#define BARO_BOARD_SENDER_ID
default onboard baro
Definition: abi_sender_ids.h:33
Ms5611Data::temperature
int32_t temperature
temperature with 0.01 degrees Celsius resolution
Definition: ms5611.h:53
baro_event
void baro_event(void)
Definition: baro_board_ms5611_i2c.c:98
LED_OFF
#define LED_OFF(i)
Definition: led_hw.h:52
abi.h
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
BB_MS5611_SLAVE_ADDR
#define BB_MS5611_SLAVE_ADDR
default i2c address when CSB is set to GND addr is 0xEE when CSB is set to VCC addr is 0xEC
Definition: baro_board_ms5611_i2c.c:56
Ms5611Data::d2
uint32_t d2
Definition: ms5611.h:56
bb_ms5611
struct Ms5611_I2c bb_ms5611
Definition: baro_board_ms5611_i2c.c:65
LED_TOGGLE
#define LED_TOGGLE(i)
Definition: led_hw.h:53
ms5611_i2c.h
get_sys_time_usec
uint32_t get_sys_time_usec(void)
Get the time in microseconds since startup.
Definition: sys_time_arch.c:75
std.h
baro_periodic
void baro_periodic(void)
Definition: baro_board_ms5611_i2c.c:76
uart.h
arch independent UART (Universal Asynchronous Receiver/Transmitter) API
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
sys_time.h
Architecture independent timing functions.
BB_MS5611_TYPE_MS5607
#define BB_MS5611_TYPE_MS5607
set to TRUE if baro is actually a MS5607
Definition: baro_board_ms5611_i2c.c:61
ms5611_i2c_event
void ms5611_i2c_event(struct Ms5611_I2c *ms)
Definition: ms5611_i2c.c:119
led.h
arch independent LED (Light Emitting Diodes) API
baro.h
sys_time
Definition: sys_time.h:71
ms5611_i2c_periodic
static void ms5611_i2c_periodic(struct Ms5611_I2c *ms)
convenience function
Definition: ms5611_i2c.h:69
sys_time::nb_sec
volatile uint32_t nb_sec
full seconds since startup
Definition: sys_time.h:72
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