Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
8 years, 4 months ago.
HDC1000 with Nucleo 401RE
Hello
I am using the HDC1000 temp sensor by ControlEverything with the Nucleo 401RE. https://shop.controleverything.com/products/humidity-and-temperature-sensor-3-rh-0-2-c
I tried to review some information on I²C and HDC1000 for mbed is here
https://developer.mbed.org/handbook/I2C https://developer.mbed.org/users/kenjiArai/code/HDC1000/ https://developer.mbed.org/users/yasuyuki/code/mbed_HDC1000/
I used the following code but I got the temp = -39.88 C. What was wrong in my code? Thanks.
my code
#include "mbed.h" // Read temperature I2C I²C (PB_9, PB_8); //for STM32F401RE const int addr = 0x40; Serial pc(USBTX, USBRX); int main() { char cmd[2]; pc.baud(9600); while (1) { cmd[0] = 0x02; cmd[1] = 0x30; I²C .write(addr, cmd, 2); wait(0.5); cmd[0] = 0x00; I²C .write(addr, cmd, 2); wait(1.0); I²C .read(addr, cmd, 2); float tmp = (float((cmd[0]<<8)|cmd[1])); float cTemp = (tmp / 65536.0) * 165.0 - 40; pc.printf("Temp = %.2f deg C\n", cTemp); } }
Anat,
Do you have pull up resistors on both i2c lines? values from 1.5k to 10k probably will do! :)
Regards,
Andrea, team mbed
posted by Andrea Corrado 06 Jun 2017Thank you. After changing the address from 0x40 to 0x80, it works! The issue was about the 7-bit vs 8-bit address.
posted by Anat Ruangrassamee 06 Jun 2017