-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
baro_ms5611_spi.c
116 lines (96 loc) · 3.26 KB
/
baro_ms5611_spi.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
/*
* Copyright (C) 2011-2013 The Paparazzi Team
*
* This file is part of paparazzi.
*
* paparazzi is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* paparazzi is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with paparazzi; see the file COPYING. If not, write to
* the Free Software Foundation, 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*
*/
/**
* @file subsystems/sensors/baro_ms5611_spi.c
*
* Driver for MS5611 baro on LisaM/Aspirin2.2 via SPI.
*
*/
#include "subsystems/sensors/baro.h"
#include "peripherals/ms5611_spi.h"
#include "mcu_periph/sys_time.h"
#include "led.h"
#include "std.h"
#include "subsystems/abi.h"
#ifndef DOWNLINK_DEVICE
#define DOWNLINK_DEVICE DOWNLINK_AP_DEVICE
#endif
#include "mcu_periph/uart.h"
#include "messages.h"
#include "subsystems/datalink/downlink.h"
#ifndef MS5611_SPI_DEV
#define MS5611_SPI_DEV spi2
#endif
/* SPI SLAVE3 is on pin PC13
* Aspirin 2.2 has ms5611 on SPI bus
*/
#ifndef MS5611_SLAVE_DEV
#define MS5611_SLAVE_DEV SPI_SLAVE3
#endif
#ifndef BARO_BOARD_MS5611_SENDER_ID
#define BARO_BOARD_MS5611_SENDER_ID 7
#endif
struct Ms5611_Spi bb_ms5611;
void baro_init(void) {
ms5611_spi_init(&bb_ms5611, &MS5611_SPI_DEV, MS5611_SLAVE_DEV);
#ifdef BARO_LED
LED_OFF(BARO_LED);
#endif
}
void baro_periodic(void) {
if (sys_time.nb_sec > 1) {
/* call the convenience periodic that initializes the sensor and starts reading*/
ms5611_spi_periodic(&bb_ms5611);
#if DEBUG
if (bb_ms5611.initialized)
RunOnceEvery((50*30), DOWNLINK_SEND_MS5611_COEFF(DefaultChannel, DefaultDevice,
&bb_ms5611.data.c[0],
&bb_ms5611.data.c[1],
&bb_ms5611.data.c[2],
&bb_ms5611.data.c[3],
&bb_ms5611.data.c[4],
&bb_ms5611.data.c[5],
&bb_ms5611.data.c[6],
&bb_ms5611.data.c[7]);
#endif
}
}
void baro_event(){
if (sys_time.nb_sec > 1) {
ms5611_spi_event(&bb_ms5611);
if (bb_ms5611.data_available) {
float pressure = (float)bb_ms5611.data.pressure;
AbiSendMsgBARO_ABS(BARO_BOARD_MS5611_SENDER_ID, &pressure);
bb_ms5611.data_available = FALSE;
#ifdef BARO_LED
RunOnceEvery(10,LED_TOGGLE(BARO_LED));
#endif
#if DEBUG
float ftempms = bb_ms5611.data.temperature / 100.;
float fbaroms = bb_ms5611.data.pressure / 100.;
DOWNLINK_SEND_BARO_MS5611(DefaultChannel, DefaultDevice,
&bb_ms5611.data.d1, &bb_ms5611.data.d2,
&fbaroms, &ftempms);
#endif
}
}
}