跳转到内容

SensorPressure::XGZP6847D API

文档完整
符号
29
已记录
29
修订版本
0.1.0+cea60a9e62e2

1

XGZP6847DDevice

XGZP6847D 数字压力传感器驱动。 https://cfsensor.com/product/xgzp6847d/ 官方产品页: https://cfsensor.com/wp-content/uploads/2026/04/XGZP6847D-Pressure-Sensor-V3.0.pdf V3.0 datasheet: https://www.scribd.com/document/891923775/XGZP6847D-Pressure-Sensor-V2-2025-05-04-21-28-42 V2.8 检索页: 旧版协议/量程换算参考资料: 当前实现使用的是旧版协议里的 K 表换算: pressure_pa = signExtend24(raw_pressure) / K -100~100 kPa -> pressure_range_kpa = 100 -> K = 64 量程 -100~300 kPa -> pressure_range_kpa = 300 -> K = 16 量程 这里的 pressure_range_kpa 不是总量程跨度,而是 max(abs(Pmin), abs(Pmax))。 例如: onTrigger() onRead() 该设备需要先写命令触发一次联合转换,再等待芯片完成内部测量,最后读取 压力和温度原始值并更新缓存。因此它重写了、conversionMs() 和三个状态机钩子。

pressure/XGZP6847D/XGZP6847DDevice.hpp:35

结构体

1

函数

12

XGZP6847DDevice::XGZP6847DDevice

                    XGZP6847DDevice::XGZP6847DDevice (float pressure_range_kpa, uint8_t address_7bit=DefaultAddress)
                  

构造压力传感器设备对象 pressure_range_kpa 旧版 K 表使用的等效量程,单位 kPa; 取 max(abs(Pmin), abs(Pmax)),不是 Pmax - Pmin address_7bit 设备的 7 位 I2C 地址

pressure/XGZP6847D/XGZP6847DDevice.hpp:55

XGZP6847DDevice::calcK

                    int32_t XGZP6847DDevice::calcK (float pressure_range_kpa)
                  

根据量程计算压力换算系数 pressure_range_kpa 旧版 K 表使用的等效量程,单位 kPa; 取 max(abs(Pmin), abs(Pmax)),不是 Pmax - Pmin 对应的压力换算系数

pressure/XGZP6847D/XGZP6847DDevice.hpp:139

XGZP6847DDevice::conversionMs

                    uint32_t XGZP6847DDevice::conversionMs () const override
                  

获取芯片一次联合转换的最大等待时间 转换时间上限,单位毫秒

pressure/XGZP6847D/XGZP6847DDevice.hpp:107

XGZP6847DDevice::init

                    bool XGZP6847DDevice::init (I2CBusDMA &bus, uint32_t timeout_ms) override
                  

通过最小寄存器读操作确认设备在线 bus 当前设备所在的 I2C 总线 timeout_ms 单次事务超时时间,单位毫秒 初始化探活是否成功

pressure/XGZP6847D/XGZP6847DDevice.hpp:80

XGZP6847DDevice::onRead

                    bool XGZP6847DDevice::onRead (I2CBusDMA &bus, uint32_t now_ms, uint32_t timeout_ms) override
                  

读取原始数据并更新缓存 bus 当前设备所在的 I2C 总线 now_ms 当前时间戳,单位毫秒 timeout_ms 单次事务超时时间,单位毫秒 读取并解析是否成功

pressure/XGZP6847D/XGZP6847DDevice.hpp:119

XGZP6847DDevice::onTrigger

                    bool XGZP6847DDevice::onTrigger (I2CBusDMA &bus, uint32_t timeout_ms) override
                  

发送一次联合转换命令 bus 当前设备所在的 I2C 总线 timeout_ms 单次事务超时时间,单位毫秒 触发采样是否成功

pressure/XGZP6847D/XGZP6847DDevice.hpp:101

XGZP6847DDevice::signExtend24

                    int32_t XGZP6847DDevice::signExtend24 (const uint8_t data[3])
                  

将 24 位补码原始压力扩展为 32 位有符号整数 data 指向 3 字节原始压力数据 符号扩展后的 32 位压力原始值

pressure/XGZP6847D/XGZP6847DDevice.hpp:146

变量

13

文件

2