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.

Sensor controller studio with BME280 via I2C

Other Parts Discussed in Thread: CC1310

I tried to use sensor controller, BME280 with cc1310 launchpad. Here is my code for getting device ID. But it did not getting correct value. Can someone help me?


i2cStart();
i2cTx(0x77 | I2C_OP_WRITE);
i2cTx(0xd0);


if (state.i2cStatus == 0x0000) {


i2cRepeatedStart();
i2cTx(0x77 | I2C_OP_READ);
i2cRxAck(output.value);

}
i2cStop();

// Schedule the next execution
fwScheduleTask(1);

  • Hi harsha,

    There are few things that need to be checked.

    1. Can you validate that the BME280 is working with another I2C device?
    2. Do you know whether data is transmitted between the BME and the CC1310? This makes sure that the I2C is working on the CC1310 side.
    3. Are you using the correct address for your BME? From the documentation, it seems like it should be 0xEE (0b1110 1110) or 0xEC (0b1110 1100) depending on your SDO pin. I could be wrong, so make sure that it is correct
    4. The last byte should that you read should be done with a  nack (i2cRxNack) followed by the stop. Can you check how many bytes you are supposed to read to confirm that you are doing it correctly

    Hope this helps.

    For your information, if you need to post code, please use the rich formatting and click on the syntax highlighter to insert your code. This will make the code much easier to read for us.

    Regards,

    Michel

  • Hi Michel,
    Thank you for your quick attention. I have already read BME280 using code composer studio via I2C interfaced with CC1310 LaunchPad. Now i wanted to do it using Sensor Controller Studio. If i code it correctly can i see the value change of state.i2cStatus in the graph of senso controller studio? Because i am beginner to the SCS. I checked the BME280 datasheet the slave address is 0x77 and i got the device id calling to the 0xD0 register but here i used code composer studio
  • Hi,

    Have you tried using 0xEE as your first byte?

    The address is indeed 0x77 but it needs to be shifted by one bit. The first byte in the I2C transaction is going to be the address as the 7 MSB with the read/write bit as the LSB. SCS is not smart enough to do the bit shift needed for the address byte. So when you look at the actual byte that you want to send, it would look like this:

    0b1110 111x (where x is the read/write bit). If you look at this byte ignoring what each bit means, it does equal 0xEE.

    If we now take a look at this line in your SCS code:

    i2cTx(0x77 | I2C_OP_READ);

    It represents this arithmetic operation:

    0b0111 0111 OR 0b0000 0001 = 0b0111 0111

    So you end up sending this address over the I2C bus: 0x3B

    So as mentioned earlier, you need to manually do the bit shift, and this means that the address byte will line of code will look like this:

    // for read
    i2cTx(0xEE | I2C_OP_READ);
    
    //for write
    i2cTx(0xEE | I2C_OP_WRITE);

    I presume that the reason why it worked with Code Composer Studio is that it does the bit shift for you automatically, and therefore, you only see 0x77 as the address.

    Regards,

    Michel

  • Hi Michel,
    Thank you for your quick response. Here you explained it very clearly. My problem is solved. I attached my code and hope it might be useful someone.

    i2cStart();
    i2cTx(I2C_OP_WRITE | (DEVICE_ADDRESS <<1 ));
    i2cTx(WHO_AM_I); //WHO_AM_I is the register for device ID




    i2cRepeatedStart();
    i2cTx(I2C_OP_READ | (DEVICE_ADDRESS <<1 ));
    i2cRxAck(state.whoami);
    i2cStop();

    Regards,
    Harsha
  • Thank you Harsha for posting this. It helped me out a lot. I would have never thought about the slave address shift.

    Regards,
    Rob