https://e2e.ti.com/support/interface-group/interface/f/interface-forum/580898/scs-i2c-sht21
我尝试在传感器控制器工作室中使用温度传感器SHT21。
代码:
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);
如果(state.i2cStatus == 0x0000){
U16结果H;
U16结果L;
U16 CRC;
i2cRxAck(resultH);
i2cRxAck(resultL);
i2cRxNack(CRC);
output.value =(resultH << 8)| resultL;
}
i2cStop();
有时(40 % of samples)返回正确的值,有时返回(40 %)- 0,有时返回(20 %)-随机值。
已尝试使用延迟,RepeatedStart(),i2cStatus - 不幸运。
Arduino板上相同传感器的相同代码工作正常。
我做错了什么?