STAR
Cal STAR — firmware, DAQ server, and engine design
Loading...
Searching...
No Matches
dev_ms5611.h
Go to the documentation of this file.
1#ifndef STAR_DEV_MS5611_H
2#define STAR_DEV_MS5611_H
3
4/*
5 * MS5611-01BA03 barometer (U5), SPI mode 3. Datasheet MS5611-01BA03 (06/2017)
6 * and application note AN520.
7 *
8 * Commands (p.10, Figure 4): reset 0x1E, convert D1 (pressure) 0x48 and
9 * D2 (temperature) 0x58 at OSR 4096, ADC read 0x00, PROM read 0xA0..0xAE.
10 * OSR 4096 conversion takes at most 9.04 ms (p.3), so results are read
11 * MS5611_CONVERSION_MS after the start command. Reading the ADC before the
12 * conversion ends returns 0, which the driver reports as DEV_ERR_DATA.
13 *
14 * The power-on reset (0x1E with CSB held low through the 2.8 ms PROM reload,
15 * p.10 Figure 5) is done once by board_bringup, not here.
16 *
17 * Compensation (p.8 first order, p.9 second order) in integer arithmetic,
18 * exactly as the datasheet; checked against its worked example (p.8).
19 */
20
21#include <stdint.h>
22
23#include "dev_bus.h"
24
25#ifdef __cplusplus
26extern "C" {
27#endif
28
29#define MS5611_CONVERSION_MS 10U /* >= 9.04 ms max at OSR 4096 */
30
31typedef struct {
32 uint16_t word[8]; /* word[1..6] = C1..C6; word[7] low nibble = CRC4 */
34
39
40/* AN520 CRC4 over the 8 PROM words (low byte of word 7 cleared). */
41uint8_t ms5611_crc4(const ms5611_prom_t* prom);
42
43/* Read all 8 PROM words; DEV_ERR_DATA if blank (all 0 / all 1) or the CRC4
44 * does not match. */
45int ms5611_read_prom(const dev_bus_t* bus, ms5611_prom_t* prom);
46
47/* Start a conversion; read it with ms5611_read_adc() >= 10 ms later. */
48int ms5611_start(const dev_bus_t* bus, ms5611_conversion_t which);
49
50/* 24-bit result of the last conversion. */
51int ms5611_read_adc(const dev_bus_t* bus, uint32_t* raw);
52
53/* Temperature in 0.01 degC and pressure in Pa (= 0.01 mbar), with
54 * second-order compensation below 20 degC. */
55void ms5611_compensate(const ms5611_prom_t* prom, uint32_t d1, uint32_t d2,
56 int32_t* temp_c100, int32_t* pressure_pa);
57
58#ifdef __cplusplus
59}
60#endif
61#endif
int ms5611_read_adc(const dev_bus_t *bus, uint32_t *raw)
Definition dev_ms5611.c:59
uint8_t ms5611_crc4(const ms5611_prom_t *prom)
Definition dev_ms5611.c:8
int ms5611_start(const dev_bus_t *bus, ms5611_conversion_t which)
Definition dev_ms5611.c:50
int ms5611_read_prom(const dev_bus_t *bus, ms5611_prom_t *prom)
Definition dev_ms5611.c:29
ms5611_conversion_t
Definition dev_ms5611.h:35
@ MS5611_D1_PRESSURE
Definition dev_ms5611.h:36
@ MS5611_D2_TEMPERATURE
Definition dev_ms5611.h:37
void ms5611_compensate(const ms5611_prom_t *prom, uint32_t d1, uint32_t d2, int32_t *temp_c100, int32_t *pressure_pa)
Definition dev_ms5611.c:72
uint32_t d1
Definition flight_e2e.c:77
uint32_t d2
Definition flight_e2e.c:77
uint16_t word[8]
Definition dev_ms5611.h:32