c - 如何将值转换为传感器的温度?

标签 c sensors i2c temperature

我正在研究 ST 温度传感器 ( hts221 ),我使用 I2C 命令与传感器通信。 我是新手...

我引用了 Data sheet for HTS221 , 并从 Sensor 获取值。 但是我不知道如何将值转换为实际温度。

从传感器获取的值如下:

Read HTS221 TEMP_OUT_L: 0x2a value is 0x15
Read HTS221 TEMP_OUT_H: 0x2b value is 0xFF
Read HTS221 T0_degC_x8: 0x32 value is 0xBF
Read HTS221 T1_degC_x8: 0x33 value is 0xBF
Read HTS221 T1/T0 msb: 0x35 value is 0x4
Read HTS221 T0_OUT-3C: 0x3C value is 0x0
Read HTS221 T0_OUT-3D: 0x3D value is 0x0
Read HTS221 T1_OUT-3E: 0x3E value is 0x0
Read HTS221 T1_OUT-3F: 0x3F value is 0x0

温度寄存器说明如下图

enter image description here

还有像下图这样的标定系数和温度转换的例子,不过我还是明白是什么意思。 enter image description here enter image description here

有人可以教我如何将上述值转换​​为传感器的温度吗? 我对此一无所知... 提前致谢。

最佳答案

您需要阅读以下校准寄存器:

T0_degC_x8  (Calibration register 32)
T1_degC_x8  (Calibration register 33)
T1_T0msb    (Calibration register 35)
T0_OUT      (Calibration register 3C and 3D)
T1_OUT      (Calibration register 3E and 3F)

T0_degC_x8 和 T1_degC_x8 是 10 位值,因此您需要从寄存器 35 中获取最后 2 位。

然后就是简单的插值得到测得的温度:

double T_DegC;
double T0_degC = (T0_degC_x8 + (1 << 8) * (T1_T0msb & 0x03)) / 8.0; 
double T1_degC = (T1_degC_x8 + (1 << 6) * (T1_T0msb & 0x0C)) / 8.0; // Value is in 3rd and fourth bit, so we only need to shift this value 6 more bits.
T_DegC = (T0_degC + (T_OUT - T0_OUT) * (T1_degC - T0_degC) / (T1_OUT - T0_OUT)); 

注意:

寄存器编号是十六进制的,所以寄存器32、33、35实际上是寄存器0x32、0x33、0x35。

关于c - 如何将值转换为传感器的温度?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25605318/

相关文章:

c - 用于对多边形轮廓中的顶点进行排序的线性时间算法

android - 在android上获取电池温度

c++ - 如何独立检查多个变量?

algorithm - 模拟退火 - 传感器网络中的传感器定位

c++ - 树莓派 I2C

c++ - 在结构中为 Char* 赋值,哪种解决方案是理想的 c++

c - 将数字打印为单词

c - 无法链接到 BFD

c - 与传感器 CCS 编译器的 I2C 通信

java - NoClassDefFound错误: com/pi4j/io/I2CFactory$UnsupportedBusNumberException