Paparazzi UAS v7.1_unstable
Paparazzi is a free software Unmanned Aircraft System.
Loading...
Searching...
No Matches
baro_scp_i2c.c
Go to the documentation of this file.
1
6
7
8#include "baro_scp_i2c.h"
9
10#include "mcu_periph/sys_time.h"
11#include "mcu_periph/i2c.h"
12#include "modules/core/abi.h"
13#include "led.h"
14
15#include "mcu_periph/uart.h"
16#include "pprzlink/messages.h"
18
19
23
25
26#ifndef SCP_I2C_DEV
27#define SCP_I2C_DEV i2c0
28#endif
29
30#define SCP1000_SLAVE_ADDR 0x22
31
33{
34 /* switch to high resolution */
38}
39
44
46{
47
49
52 } else if (baro_scp_status == BARO_SCP_IDLE) {
53
54 /* init: start two byte temperature */
58 }
59}
60
62{
63
64 if (scp_trans.status == I2CTransSuccess) {
65
67
68 /* read two byte temperature */
69 baro_scp_temperature = scp_trans.buf[0] << 8;
71 if (baro_scp_temperature & 0x2000) {
72 baro_scp_temperature |= 0xC000;
73 }
75
76 /* start one byte msb pressure */
80 }
81
83
84 /* read one byte pressure */
85 baro_scp_pressure = scp_trans.buf[0] << 16;
86
87 /* start two byte lsb pressure */
91 }
92
94
95 /* read two byte pressure */
96 baro_scp_pressure |= scp_trans.buf[0] << 8;
99
100 uint32_t now_ts = get_sys_time_usec();
101 float pressure = (float) baro_scp_pressure / 100.f; // 0.01 Pa to Pa
102 AbiSendMsgBARO_ABS_RAW(BARO_SCP_SENDER_ID, now_ts, pressure);
103
105 }
106
108 }
109}
Main include for ABI (AirBorneInterface).
#define BARO_SCP_SENDER_ID
#define SCP1000_SLAVE_ADDR
uint32_t baro_scp_pressure
uint8_t baro_scp_status
static void baro_scp_start_high_res_measurement(void)
void baro_scp_event(void)
void baro_scp_periodic(void)
void baro_scp_init(void)
#define SCP_I2C_DEV
struct i2c_transaction scp_trans
uint16_t baro_scp_temperature
#define SCP1000_DATARD16
#define BARO_SCP_RD_TEMP
#define BARO_SCP_UNINIT
#define BARO_SCP_IDLE
#define BARO_SCP_RD_PRESS_1
#define SCP1000_OPERATION
Definition baro_scp_i2c.h:6
#define SCP1000_TEMPOUT
#define BARO_SCP_RD_PRESS_0
#define SCP1000_HIGH_RES
Definition baro_scp_i2c.h:9
#define SCP1000_DATARD8
uint32_t get_sys_time_usec(void)
Get the time in microseconds since startup.
bool i2c_transmit(struct i2c_periph *p, struct i2c_transaction *t, uint8_t s_addr, uint8_t len)
Submit a write only transaction.
Definition i2c.c:202
bool i2c_transceive(struct i2c_periph *p, struct i2c_transaction *t, uint8_t s_addr, uint8_t len_w, uint16_t len_r)
Submit a write/read transaction.
Definition i2c.c:222
@ I2CTransSuccess
transaction successfully finished by I2C driver
Definition i2c.h:58
I2C transaction structure.
Definition i2c.h:94
Architecture independent I2C (Inter-Integrated Circuit Bus) API.
arch independent LED (Light Emitting Diodes) API
Architecture independent timing functions.
volatile uint32_t nb_sec
full seconds since startup
Definition sys_time.h:80
arch independent UART (Universal Asynchronous Receiver/Transmitter) API
unsigned short uint16_t
Typedef defining 16 bit unsigned short type.
unsigned int uint32_t
Typedef defining 32 bit unsigned int type.
unsigned char uint8_t
Typedef defining 8 bit unsigned char type.