I'm trying to use temperature sensor SHT21 in Sensor Controller Studio.
Code:
i2cStart();
i2cTx(I2C_OP_WRITE | ALS_I2C_ADDR); //0x40<<1
i2cTx(TRIG_T_MEASUREMENT_HM); //0xe3
i2cStop();
fwDelayUs(100, FW_DELAY_RANGE_100_MS);
i2cStart();
i2cTx(I2C_OP_READ | ALS_I2C_ADDR);
if (state.i2cStatus == 0x0000) {
U16 resultH;
U16 resultL;
U16 CRC;
i2cRxAck(resultH);
i2cRxAck(resultL);
i2cRxNack(CRC);
output.value = (resultH << 8) | resultL;
}
i2cStop();
Sometimes (40% of samples) it returns right value, sometimes (40%) - 0, sometimes (20%) - random value.
Tried to play with Delays, RepeatedStart(), i2cStatus - no luck.
Same code with same sensor on Arduino board works fine.
What i'm doing wrong?