Paparazzi UAS  v5.2.2_stable-0-gd6b9f29
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
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 
31 #include "peripherals/ms5611_i2c.h"
32 
33 #include "mcu_periph/sys_time.h"
34 #include "led.h"
35 #include "std.h"
36 #include "subsystems/abi.h"
37 
38 #include "mcu_periph/uart.h"
39 #include "messages.h"
41 
42 #ifdef BARO_PERIODIC_FREQUENCY
43 #if BARO_PERIODIC_FREQUENCY > 100
44 #error "For MS5611 BARO_PERIODIC_FREQUENCY has to be < 100"
45 #endif
46 #endif
47 
48 
49 /* default i2c address
50  * when CSB is set to GND addr is 0xEE
51  * when CSB is set to VCC addr is 0xEC
52  *
53  * Note: Aspirin 2.1 has CSB bound to GND.
54  */
55 #ifndef BB_MS5611_SLAVE_ADDR
56 #define BB_MS5611_SLAVE_ADDR 0xEE
57 #endif
58 
59 
61 
62 
63 void baro_init(void) {
64  ms5611_i2c_init(&bb_ms5611, &BB_MS5611_I2C_DEV, BB_MS5611_SLAVE_ADDR);
65 
66 #ifdef BARO_LED
67  LED_OFF(BARO_LED);
68 #endif
69 }
70 
71 void baro_periodic(void) {
72  if (sys_time.nb_sec > 1) {
73 
74  /* call the convenience periodic that initializes the sensor and starts reading*/
76 
77 #if DEBUG
79  RunOnceEvery((50*30), DOWNLINK_SEND_MS5611_COEFF(DefaultChannel, DefaultDevice,
80  &bb_ms5611.data.c[0],
81  &bb_ms5611.data.c[1],
82  &bb_ms5611.data.c[2],
83  &bb_ms5611.data.c[3],
84  &bb_ms5611.data.c[4],
85  &bb_ms5611.data.c[5],
86  &bb_ms5611.data.c[6],
87  &bb_ms5611.data.c[7]));
88 #endif
89  }
90 }
91 
92 void baro_event(void) {
93  if (sys_time.nb_sec > 1) {
95 
97  float pressure = (float)bb_ms5611.data.pressure;
98  AbiSendMsgBARO_ABS(BARO_BOARD_SENDER_ID, &pressure);
100 
101 #ifdef BARO_LED
102  RunOnceEvery(10,LED_TOGGLE(BARO_LED));
103 #endif
104 
105 #if DEBUG
106  float ftempms = bb_ms5611.data.temperature / 100.;
107  float fbaroms = bb_ms5611.data.pressure / 100.;
108  DOWNLINK_SEND_BARO_MS5611(DefaultChannel, DefaultDevice,
110  &fbaroms, &ftempms);
111 #endif
112  }
113  }
114 }
struct Ms5611_I2c bb_ms5611
arch independent UART (Universal Asynchronous Receiver/Transmitter) API
uint32_t d1
Definition: ms5611.h:55
Common barometric sensor implementation.
int32_t temperature
temperature with 0.01 degrees Celsius resolution
Definition: ms5611.h:53
void baro_init(void)
volatile bool_t data_available
data ready flag
Definition: ms5611_i2c.h:41
void ms5611_i2c_init(struct Ms5611_I2c *ms, struct i2c_periph *i2c_p, uint8_t addr)
Definition: ms5611_i2c.c:33
Main include for ABI (AirBorneInterface).
float fbaroms
void baro_event(void)
#define FALSE
Definition: imu_chimu.h:141
struct Ms5611Data data
Definition: ms5611_i2c.h:42
#define BB_MS5611_SLAVE_ADDR
float ftempms
Architecture independent timing functions.
Measurement Specialties (Intersema) MS5611-01BA pressure/temperature sensor interface for I2C...
static void ms5611_i2c_periodic(struct Ms5611_I2c *ms)
convenience function
Definition: ms5611_i2c.h:65
void baro_periodic(void)
#define BARO_BOARD_SENDER_ID
default onboard baro
void ms5611_i2c_event(struct Ms5611_I2c *ms)
Definition: ms5611_i2c.c:117
#define LED_TOGGLE(i)
Definition: led_hw.h:30
volatile uint32_t nb_sec
full seconds since startup
Definition: sys_time.h:69
#define LED_OFF(i)
Definition: led_hw.h:29
arch independent LED (Light Emitting Diodes) API
bool_t initialized
config done flag
Definition: ms5611_i2c.h:40
uint16_t c[PROM_NB]
Definition: ms5611.h:54
uint32_t pressure
pressure in Pascal (0.01mbar)
Definition: ms5611.h:52
uint32_t d2
Definition: ms5611.h:56