Paparazzi UAS v7.1_unstable
Paparazzi is a free software Unmanned Aircraft System.
Loading...
Searching...
No Matches
baro_bmp280.c
Go to the documentation of this file.
1/*
2 * Chris Efstathiou hendrixgr@gmail.com
3 * Florian Sansou florian.sansou@enac.fr
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, see
18 * <http://www.gnu.org/licenses/>.
19 *
20 */
21
28
29
30#include "baro_bmp280.h"
31
32#include "modules/core/abi.h"
33#include "mcu_periph/sys_time.h"
34#include "math/pprz_isa.h"
35
36
37#ifndef BMP280_USE_SPI
38#define BMP280_USE_SPI FALSE
39#endif
41PRINT_CONFIG_VAR(BMP280_DEV)
43
44#ifndef BMP280_SLAVE_ADDR
45#define BMP280_SLAVE_ADDR BMP280_I2C_ADDR
46#endif
47
48#ifndef BMP280_SLAVE_IDX
49#define BMP280_SLAVE_IDX SPI_SLAVE0
50#endif
51
52
53float baro_alt = 0;
54float baro_temp = 0;
55float baro_press = 0;
57
58
60
61
63{
64 #if BMP280_USE_SPI
66 baro_bmp280.spi.p = &BMP280_DEV;
67 baro_bmp280.spi.slave_idx = BMP280_SLAVE_IDX;
68 #else
70 baro_bmp280.i2c.p = &BMP280_DEV;
71 baro_bmp280.i2c.slave_addr = BMP280_SLAVE_ADDR;
72 #endif
74}
75
80
82{
84
85 if (baro_bmp280.data_available) {
86 uint32_t now_ts = get_sys_time_usec();
87 // send ABI message
88 AbiSendMsgBARO_ABS_RAW(BARO_BMP_SENDER_ID, now_ts, baro_bmp280.pressure);
89 AbiSendMsgTEMPERATURE_RAW(BARO_BMP_SENDER_ID, now_ts, baro_bmp280.temperature, TEMPERATURE_TYPE_BARO);
90 baro_bmp280.data_available = false;
92 baro_alt_valid = true;
93 baro_press = (float)baro_bmp280.pressure;
94 baro_temp = ((float)baro_bmp280.temperature) / 100;
95 }
96}
Main include for ABI (AirBorneInterface).
#define TEMPERATURE_TYPE_BARO
barometer die
Definition abi_common.h:91
#define BARO_BMP_SENDER_ID
#define BMP280_SLAVE_ADDR
default slave address
Definition baro_bmp280.c:45
#define BMP280_USE_SPI
Definition baro_bmp280.c:38
float baro_press
Definition baro_bmp280.c:55
void baro_bmp280_periodic(void)
Definition baro_bmp280.c:76
bool baro_alt_valid
Definition baro_bmp280.c:56
void baro_bmp280_init(void)
Definition baro_bmp280.c:62
float baro_alt
Definition baro_bmp280.c:53
float baro_temp
Definition baro_bmp280.c:54
#define BMP280_SLAVE_IDX
Definition baro_bmp280.c:49
void baro_bmp280_event(void)
Definition baro_bmp280.c:81
struct bmp280_t baro_bmp280
Definition baro_bmp280.c:59
Bosch BMP280 sensor interface.
void bmp280_periodic(struct bmp280_t *bmp)
Should be called periodically to request sensor readings.
Definition bmp280.c:101
void bmp280_init(struct bmp280_t *bmp)
Initialize the bmp280 sensor instance.
Definition bmp280.c:48
void bmp280_event(struct bmp280_t *bmp)
Should be called in the event thread.
Definition bmp280.c:157
@ BMP280_I2C
Definition bmp280.h:54
@ BMP280_SPI
Definition bmp280.h:53
uint32_t get_sys_time_usec(void)
Get the time in microseconds since startup.
static float pprz_isa_altitude_of_pressure(float pressure)
Get absolute altitude from pressure (using simplified equation).
Definition pprz_isa.h:82
PRINT_CONFIG_VAR(ONELOOP_ANDI_FILT_CUTOFF)
Paparazzi atmospheric pressure conversion utilities.
Architecture independent timing functions.
unsigned int uint32_t
Typedef defining 32 bit unsigned int type.