SFM Flow Meter Driver 1.0.0
API reference
Loading...
Searching...
No Matches
sfm_commands.hpp
Go to the documentation of this file.
1
17#pragma once
18
19#include <cstddef>
20#include <cstdint>
21
22namespace sfm {
23
25namespace addr {
26constexpr uint8_t kSfm4300Default = 0x2A;
27constexpr uint8_t kSfm4300Alt1 = 0x2B;
28constexpr uint8_t kSfm4300Alt2 = 0x2C;
29constexpr uint8_t kSfm4300Alt3 = 0x2D;
30constexpr uint8_t kSfm3119 = 0x29;
31constexpr uint8_t kSfm3003 = 0x28;
32constexpr uint8_t kSfm3003Ce = 0x2D;
33constexpr uint8_t kSfm3013 = 0x2F;
34constexpr uint8_t kSfm3019 = 0x2E;
36constexpr uint8_t kSfm6000Default = 0x24;
37constexpr uint8_t kSfm6000R560 = 0x23;
38constexpr uint8_t kSfm6000R1k2 = 0x22;
39constexpr uint8_t kSfm6000R2k7 = 0x21;
40constexpr uint8_t kSfm6000R5k6 = 0x20;
41constexpr uint8_t kSfm6000R12k = 0x42;
42constexpr uint8_t kSfm6000R27k = 0x41;
43constexpr uint8_t kGeneralCall = 0x00;
44} // namespace addr
45
47namespace cmd {
48// SF06 (SFM4300) start codes — gas meaning is SF06's.
49constexpr uint16_t kStartO2 = 0x3603;
50constexpr uint16_t kStartAir = 0x3608;
51constexpr uint16_t kStartN2O = 0x3615;
52constexpr uint16_t kStartCO2 = 0x361E;
53constexpr uint16_t kStartAirO2Mix = 0x3632;
54constexpr uint16_t kStartN2OO2Mix = 0x3639;
55constexpr uint16_t kStartCO2O2Mix = 0x3646;
56// SFx6000 start codes — calibrated gas index (interface reference §3.3.1, §3.5.1).
57constexpr uint16_t kSfx6000StartGas0 = 0x3603;
58constexpr uint16_t kSfx6000StartGas1 = 0x3608;
59constexpr uint16_t kSfx6000StartGas2 = 0x3615;
60constexpr uint16_t kSfx6000StartGas3 = 0x361E;
61constexpr uint16_t kSfx6000StartGas4 = 0x3624;
62constexpr uint16_t kSfx6000StartMix0 = 0x3650;
63// SFx6000 output-buffer pointers (no measurement interruption).
64constexpr uint16_t kSfx6000PointerGasInfo = 0xE151;
65constexpr uint16_t kSfx6000PointerTemperature = 0xE102;
66constexpr uint16_t kSfx6000PointerResult = 0xE000;
67constexpr uint16_t kUpdateConcentrationSet = 0xE17D;
68constexpr uint16_t kUpdateConcentrationActivate = 0xE000;
69constexpr uint16_t kStopContinuous = 0x3FF9;
70constexpr uint16_t kConfigureAveraging = 0x366A;
71constexpr uint16_t kReadScaleOffsetUnit = 0x3661;
72constexpr uint16_t kEnterSleep = 0x3677;
73constexpr uint16_t kReadProductIdentifier = 0xE102;
74constexpr uint8_t kGeneralCallReset = 0x06;
75} // namespace cmd
76
78namespace timing {
79constexpr uint32_t kFirstResultAfterStartMs = 12;
80constexpr uint32_t kAccuracySettleAfterStartMs = 30;
81constexpr uint32_t kSoftResetMs = 20;
82constexpr uint32_t kWarmUpMs = 30;
83constexpr uint32_t kMeasurementPeriodUs = 500;
84constexpr uint32_t kStopToIdleUs = 500;
85constexpr uint32_t kStopToIdleMs = 1;
86constexpr uint16_t kMaxAveragingWindow = 128;
87constexpr uint32_t kSfx6000SoftResetMs = 30;
88constexpr uint32_t kSfx6000MeasurementPeriodUs = 1000;
89} // namespace timing
90
92constexpr uint16_t kFlowUnitSlm20C = 0x0148;
93
95constexpr float kTemperatureScalePerC = 200.0f;
96
98constexpr uint16_t kStatusPureGasFraction = 0x3FF;
99
103constexpr uint8_t Crc8(const uint8_t* data, std::size_t len) noexcept {
104 uint8_t crc = 0xFFU;
105 for (std::size_t i = 0; i < len; ++i) {
106 crc ^= data[i];
107 for (int bit = 0; bit < 8; ++bit) {
108 crc = static_cast<uint8_t>((crc & 0x80U) != 0U ? ((crc << 1) ^ 0x31U) : (crc << 1));
109 }
110 }
111 return crc;
112}
113
115constexpr uint8_t Crc8Word(uint16_t word) noexcept {
116 const uint8_t b[2] = {static_cast<uint8_t>(word >> 8), static_cast<uint8_t>(word & 0xFFU)};
117 return Crc8(b, 2);
118}
119
120static_assert(Crc8Word(0xBEEF) == 0x92, "SF06 CRC-8 test vector (0xBEEF -> 0x92)");
121
122} // namespace sfm
constexpr uint8_t kSfm4300Alt1
ADDR to GND via 1.2 kΩ
Definition sfm_commands.hpp:27
constexpr uint8_t kSfm4300Alt3
ADDR to GND via 5.6 kΩ
Definition sfm_commands.hpp:29
constexpr uint8_t kSfm6000R2k7
2.7 kΩ
Definition sfm_commands.hpp:39
constexpr uint8_t kSfm6000R560
560 Ω
Definition sfm_commands.hpp:37
constexpr uint8_t kGeneralCall
I2C general-call (soft reset)
Definition sfm_commands.hpp:43
constexpr uint8_t kSfm3019
Definition sfm_commands.hpp:34
constexpr uint8_t kSfm6000Default
SFx6000 (SFM6000D / SFC6000D): ADDR pin to GND through a resistor (±5 %).
Definition sfm_commands.hpp:36
constexpr uint8_t kSfm6000R27k
27 kΩ
Definition sfm_commands.hpp:42
constexpr uint8_t kSfm4300Alt2
ADDR to GND via 2.7 kΩ
Definition sfm_commands.hpp:28
constexpr uint8_t kSfm3119
Definition sfm_commands.hpp:30
constexpr uint8_t kSfm3003Ce
SFM3003-300-CE (SFM3003 data sheet Table 2)
Definition sfm_commands.hpp:32
constexpr uint8_t kSfm6000R5k6
5.6 kΩ
Definition sfm_commands.hpp:40
constexpr uint8_t kSfm6000R12k
12 kΩ
Definition sfm_commands.hpp:41
constexpr uint8_t kSfm4300Default
ADDR to GND or floating.
Definition sfm_commands.hpp:26
constexpr uint8_t kSfm3013
Definition sfm_commands.hpp:33
constexpr uint8_t kSfm3003
SFM3003-300-CL.
Definition sfm_commands.hpp:31
constexpr uint8_t kSfm6000R1k2
1.2 kΩ
Definition sfm_commands.hpp:38
constexpr uint16_t kStopContinuous
Definition sfm_commands.hpp:69
constexpr uint16_t kSfx6000PointerGasInfo
after kReadScaleOffsetUnit
Definition sfm_commands.hpp:64
constexpr uint16_t kConfigureAveraging
argument: N (0 = avg-until-read)
Definition sfm_commands.hpp:70
constexpr uint16_t kSfx6000StartGas3
N2O (CO2 on SF06!)
Definition sfm_commands.hpp:60
constexpr uint16_t kEnterSleep
Definition sfm_commands.hpp:72
constexpr uint16_t kSfx6000StartGas2
CO2 (N2O on SF06!)
Definition sfm_commands.hpp:59
constexpr uint16_t kSfx6000StartGas4
Ar.
Definition sfm_commands.hpp:61
constexpr uint16_t kStartCO2O2Mix
argument: O2 volume fraction (‰)
Definition sfm_commands.hpp:55
constexpr uint16_t kStartAirO2Mix
argument: O2 volume fraction (‰)
Definition sfm_commands.hpp:53
constexpr uint16_t kUpdateConcentrationSet
argument: ‰
Definition sfm_commands.hpp:67
constexpr uint16_t kStartN2O
Definition sfm_commands.hpp:51
constexpr uint16_t kStartN2OO2Mix
argument: O2 volume fraction (‰)
Definition sfm_commands.hpp:54
constexpr uint16_t kSfx6000StartGas1
Air.
Definition sfm_commands.hpp:58
constexpr uint16_t kUpdateConcentrationActivate
Definition sfm_commands.hpp:68
constexpr uint8_t kGeneralCallReset
single byte to address 0x00
Definition sfm_commands.hpp:74
constexpr uint16_t kStartAir
Definition sfm_commands.hpp:50
constexpr uint16_t kSfx6000StartMix0
Gas0 in Gas1 (O2 in Air); argument ‰
Definition sfm_commands.hpp:62
constexpr uint16_t kReadProductIdentifier
Definition sfm_commands.hpp:73
constexpr uint16_t kReadScaleOffsetUnit
argument: start command code
Definition sfm_commands.hpp:71
constexpr uint16_t kSfx6000PointerResult
back to flow / reserved / status
Definition sfm_commands.hpp:66
constexpr uint16_t kSfx6000PointerTemperature
while measuring (product ID when idle)
Definition sfm_commands.hpp:65
constexpr uint16_t kStartO2
Definition sfm_commands.hpp:49
constexpr uint16_t kStartCO2
Definition sfm_commands.hpp:52
constexpr uint16_t kSfx6000StartGas0
O2.
Definition sfm_commands.hpp:57
constexpr uint32_t kSfx6000SoftResetMs
interface reference §1.2
Definition sfm_commands.hpp:87
constexpr uint32_t kWarmUpMs
after reset / exit sleep
Definition sfm_commands.hpp:82
constexpr uint32_t kFirstResultAfterStartMs
first reading valid after start
Definition sfm_commands.hpp:79
constexpr uint32_t kMeasurementPeriodUs
internal sample period (~2 kHz)
Definition sfm_commands.hpp:83
constexpr uint32_t kAccuracySettleAfterStartMs
few-% deviations possible before
Definition sfm_commands.hpp:80
constexpr uint32_t kSfx6000MeasurementPeriodUs
1 kHz, NACK when no new sample
Definition sfm_commands.hpp:88
constexpr uint32_t kStopToIdleMs
kStopToIdleUs rounded up for DelayMs()
Definition sfm_commands.hpp:85
constexpr uint16_t kMaxAveragingWindow
Definition sfm_commands.hpp:86
constexpr uint32_t kStopToIdleUs
§4.3.4: idle and receptive ≤ 0.5 ms after stop
Definition sfm_commands.hpp:84
constexpr uint32_t kSoftResetMs
typ. 16 ms, max 20 ms
Definition sfm_commands.hpp:81
Definition sfm.hpp:20
constexpr uint16_t kStatusPureGasFraction
Status-word gas fraction value for a pure calibration gas (bits 9:0).
Definition sfm_commands.hpp:98
constexpr uint8_t Crc8Word(uint16_t word) noexcept
CRC-8 of one big-endian 16-bit word.
Definition sfm_commands.hpp:115
constexpr uint8_t Crc8(const uint8_t *data, std::size_t len) noexcept
CRC-8 per Sensirion SF06 (poly 0x31, init 0xFF, no reflection/xorout).
Definition sfm_commands.hpp:103
constexpr float kTemperatureScalePerC
Temperature scale (data sheet Tables 15/16: scale 200 per °C, offset 0).
Definition sfm_commands.hpp:95
constexpr uint16_t kFlowUnitSlm20C
Fixed flow-unit code returned by the SFM4300 (slm at 20 °C, 1013.25 mbar).
Definition sfm_commands.hpp:92