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.

LAUNCHXL-CC2650: Sensor controller studio + I2C + temperature sensor SHT21

Part Number: LAUNCHXL-CC2650

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? 

  • Hello Rustem,

    • Have you added an appropriate pull-up resistor on the SDA and SCL lines?
    • Have you tried both 100 kHz and 400 kHz I2C SCL frequency?
    • Have you evaluated the I2C Light Sensor project in sensor controller studio?
    • Is 100 us delay long enough?
      • The measurement times given in the data sheet for T typ are in the range 9-85 ms. 
      • You can set up timer event trigger instead as is done in the example mentioned above or simply increase the delay (fwDelayUs(100000, FW_DELAY_RANGE_100_MS);
    • Perhaps try the Trigger T measurement no hold master 1111’0011 instead (0xF3)?

    If all the above fails can you connect a logic analyzer to the I2C lines and capture some traffic to further evaluate what is going wrong?

  • Hello, Eirik! Thank you for quick answer!

    NoHoldMaster + increased Delay solves my problem!

    Working code:

    i2cStart();

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

    i2cTx(TRIG_T_MEASUREMENT); //0xf3

    i2cStop();

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

  • Happy to hear it worked!