This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

[参考译文] HDC1080:获取温度读数时出现问题。

Guru**** 2604225 points
Other Parts Discussed in Thread: HDC1080

请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

https://e2e.ti.com/support/sensors-group/sensors/f/sensors-forum/663680/hdc1080-problem-getting-a-temperature-reading

器件型号:HDC1080

我将 HDC1080温度和湿度传感器通过3.3V、GND、SDA 和 SCL 连接到 Raspberry PI 3。 我正在尝试使用 C 和 wipringPi 库获取温度读数。 我不断从0x00寄存器读取'-1'。

这是我的代码:

#include 
#include 
#include 

int main()
{
int fd、temp;
unsigned int a = 15;

延迟(a);
fd = wiringPiI2Csetup (0x40);/*正在初始化 i2c 系统*/
延迟(a);

wiringPiI2CWrite (FD、0x80);//发送从机字节进行写入*/
延迟(a);

wiringPiI2CWriteReg16 (FD、0x02、0x00);/*配置测量*/
延迟(a);

wiringPiI2CWrite (FD、0x80);
延迟(a);
wiringPiI2CWrite (FD,0x00);/*触发测量*/
延迟(a);/*等待测量*/


wiringPiI2CWrite (FD、0x81);/*发送从器件字节进行读取*/
延迟(a);

temp = wiringPiI2CReadReg16 (FD、0x00);/*读取温度*/
延迟(a);
temp =((temp)/(2^16)*165)-40;/*将读数转换为摄氏度*/
printf ("%d"、temp);
} 

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。
    尊敬的 Patrick:
    请使用基于 Arduino 的软件示例作为检查代码的参考。 这将是一个很好的起点。 链接如下:

    www.ti.com/.../toolssoftware

    还有一个培训视频、介绍如何使用 I2C 与 HDC1080湿度和温度传感器连接 Arduino:
    www.ti.com/.../support

    此致、
    何塞