This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

[参考译文] SCS + I2C + SHT21

Guru**** 2473270 points


请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

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板上相同传感器的相同代码工作正常。

我做错了什么?  

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。
    我从Eirik V获得了另一条线的答案。

    NoHoldMaster +增加的延迟解决了我的问题!

    工作代码:

    i2cStart();

    i2cTx (I2C_OP_WRITE | ALS_I2C_ADDR);//0x40<1.

    i2cTx (trig_T_measurement);//0xf3

    i2cStop();

    fwDelayUs (10万,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();