Tool/software: Linux
Here is a code segment that is currently running in my application.
We are using the MRAA I2C library in our design.
*****************************************************************************************
//Open I2C context
SensorI2cBus = mraa_i2c_init_raw(SENSOR_BUS); //SENSOR_BUS = 0
//Configure hdc1080 device
status = mraa_i2c_address(SensorI2cBus, HDC1080_ADDR); //HDC1080_ADDR = 0x40
if (MRAA_SUCCESS != status)
{
//Failed to set device address on the bus
return false;
}
status = mraa_i2c_write_word_data(SensorI2cBus, DEFAULT_CFG, CFG_REG); /DEFAULT_CFG = 0x1000
if (MRAA_SUCCESS != status)
{
//Failed to write configuration data
return false;
}
status = mraa_i2c_address(SensorI2cBus, HDC1080_ADDR);
int nData = mraa_i2c_read_word_data(SensorI2cBus, 0xFE);
nData = mraa_i2c_read_word_data(SensorI2cBus, DEV_ID_REG);
nData = mraa_i2c_read_word_data(SensorI2cBus, SN_REG_1);
nData = mraa_i2c_read_word_data(SensorI2cBus, SN_REG_2);
nData = mraa_i2c_read_word_data(SensorI2cBus, SN_REG_3);
//The next line returns an error in the status variable if I call this function.
status = mraa_i2c_write_byte_data(SensorI2cBus, 0x00, TEMP_REG);
/nData is always -1 (no data read)
nData = mraa_i2c_read_word_data(SensorI2cBus, TEMP_REG);
*****************************************************************************************
I can read the MFG_ID, DEV_ID, and SN registers with no problem. However, I always get an error trying to read temperature or humidity. I tried this both ways with and without the write function before reading the temperature register. I have done this using single-step debugging in GDB so I am sure I am waiting long enough before the read on the Temp Reg. What is wrong here? I have tried many different things here without any progress.