Other Parts Discussed in Thread: TMP112, , HDC1080
Tool/software: Code Composer Studio
Hello expert,
I would like to use CC2640 to get TMP112 sensor readings in a low power way. Temperature reading service works well in app by using the TIRTOS I2C driver. Now I'm trying to use temperature sensor TMP112 in sensor controller.
I tried to modify the i2c light sensor code by changing the configuation and address:
Excution Code:
i2cStart(); i2cTx(I2C_OP_WRITE | ALS_I2C_ADDR); //ADDR= 0x0048 i2cTx(ALS_REG_CFG); //ALS_REG_CFG = 1 i2cTx(ALS_CFG_ONE_SHOT >> 8);//ALS_CFG_ONE_SHOT = 0x60A0 i2cTx(ALS_CFG_ONE_SHOT >> 0); i2cStop(); // Read the result after 100 milliseconds + a 20% margin evhSetupTimerTrigger(0, 120, 2); // Schedule the next execution fwScheduleTask(1);
Event Handler Code
// If a measurement was successfully started during the last execution ...
if (state.i2cStatus == 0x0000) {
// Select the result register
i2cStart();
i2cTx(I2C_OP_WRITE | ALS_I2C_ADDR);
i2cTx(ALS_REG_RESULT);
// If successful ...
if (state.i2cStatus == 0x0000) {
U16 resultRegH;
U16 resultRegL;
// Read the result
i2cRepeatedStart();
i2cTx(I2C_OP_READ | ALS_I2C_ADDR);
i2cRxAck(resultRegH);
i2cRxNack(resultRegL);
i2cStop();
// Convert the result (4-bit exponent + 12-bit mantissa) into 16-bit fixed-point
U16 tmp = (resultRegH << 8) | resultRegL;
U16 value = tmp >> 4;
output.value = value;
} else {
i2cStop();
}
}
However, when I debugged the code, the i2c_status became 0x0001.
Could anyone tell me what modification should I make to make i2c work?
Thanks,
Jianlin