问题描述
我在ST Temperature sensor( hts221 )
上工作,我与传感器使用I2C
命令通信.
I am working on ST Temperature sensor( hts221 )
, I use I2C
command communication with sensor.
我从文档中看到如下文本.
I see from the document like the following text.
enter code here Temperature data are expressed as TEMP_OUT_H & TEMP_OUT_L as 2’s complement numbers.
enter code here Temperature data are expressed as TEMP_OUT_H & TEMP_OUT_L as 2’s complement numbers.
下面的图片是来自文档的描述.
And the following picture is the description from document.
从传感器读取的Temperature data
如下所示
And the Temperature data
read from the sensor is like the following
TEMP_OUT_L is 0xA8
TEMP_OUT_H is 0xFF
如何将TEMP_OUT_L和TEMP_OUT_H的值转换为温度数据?
提前谢谢吗?
推荐答案
在数据表说:
Temperature sensitivity 0.016 °C/LSB
这就是您需要做的:
#define TEMP_SENSITIVITY 0.016f
#define TEMP_OFFSET ??? /* Get this value from the datasheet. */
unsigned char tempOutH;
unsigned char tempOutL;
/* Here you get the values for tempOutH and tempOutL. */
uint16_t tempData = (tempOutH << 8) | tempOutL;
float temp = (tempData * TEMP_SENSITIVITY) + TEMP_OFFSET;
因此,您要做的是将两个8位的高值和低值连接在一起.这为您提供了一个16位值.然后,您可以将0到65535之间的数字转换/缩放为实际温度值.
So what you do is concatenate the two 8-bit high and low values. This gives you a single 16-bit value. Then you convert/scale that number between 0 and 65535 to the real temperature value.
我假设必须在数据表中指定一个偏移量,因为否则温度只能为正值:在0.0
和65363 * 0.016
之间.该偏移量将为负值.我让你找这个偏移量.
I assumed that there must be an offset specified in the datasheet, because otherwise the temperature can only positive: between 0.0
and 65363 * 0.016
. This offset will be a negative value. I leave it up to you to find this offset.
这篇关于如何转换从温度传感器得到的值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!