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.

RTOS/CC1310: I2C_transfer() failed using the i2ctmp007 example

Part Number: CC1310

Tool/software: TI-RTOS

Hello, I used C1310 LP to get the BH1750 sensor data which is a light sensor. 

I successfully got the data when using the SCE "I2C Light Sensor" example.

And here is the code in SCE below:

// Select the result register
i2cStart();
i2cTx(I2C_OP_WRITE | ALS_I2C_ADDR);
i2cTx(0x20);

// If successful ...
if (state.i2cStatus == 0x0000) {
    U16 resultRegH;
    U16 resultRegL;
    
    // Read the result
    i2cRepeatedStart();
    i2cTx(I2C_OP_READ | ALS_I2C_ADDR);
    i2cRxAck(resultRegH);
    i2cRxNack(resultRegL);
    i2cStop();
    
    output.value = (resultRegH<<8) | (resultRegL);
    
} else {
    i2cStop();
}

I just change my sensor slave ADDR to "0x46" and reading address to "0x20" , and then it works.

But in the "i2ctmp007.c" Example, I also change that two address, it doesn't work.

Here is the code in CCS:

void *mainThread(void *arg0)
{
    unsigned int    i;
    uint16_t        temperature;
    uint8_t         txBuffer[1];
    uint8_t         rxBuffer[2];
    I2C_Handle      i2c;
    I2C_Params      i2cParams;
    I2C_Transaction i2cTransaction;

    /* Call driver init functions */
    ...
    I2C_init();
    ...
    /* Create I2C for usage */
    I2C_Params_init(&i2cParams);
    i2cParams.bitRate = I2C_100kHz;
    i2c = I2C_open(Board_I2C_TMP, &i2cParams);
    if (i2c == NULL) {
        Display_printf(display, 0, 0, "Error Initializing I2C\n");
        while (1);
    }
    else {
        Display_printf(display, 0, 0, "I2C Initialized!\n");
    }

    /* Point to the T ambient register and read its 2 bytes */
    txBuffer[0] = 0x20;//TMP007_OBJ_TEMP;
    i2cTransaction.slaveAddress = 0x46;
    i2cTransaction.writeBuf = txBuffer;
    i2cTransaction.writeCount = 1;
    i2cTransaction.readBuf = rxBuffer;
    i2cTransaction.readCount = 2;

    /* Take 20 samples and print them out onto the console */
    for (i = 0; i < 20; i++) {
        if (I2C_transfer(i2c, &i2cTransaction)) {
            ...                
            Display_printf(display, 0, 0, "Sample %u: %d (C)\n", i, temperature);
        }
        else {
            Display_printf(display, 0, 0, "I2C Bus fault\n");
        }

        /* Sleep for 1 second */
        sleep(1);
    }

    /* Deinitialized I2C */
    I2C_close(i2c);
    Display_printf(display, 0, 0, "I2C closed!\n");

    return (NULL);
}

It always printing out "I2C Bus fault",can everyone can help me ?

  • How is the sensor connected to the board ?
  • There are five wire on the sensor :

    sensor --> CC1310 Launchpad
    VCC --> 3.3V
    GND --> GND
    SCL --> DIO4
    SDA --> DIO5
    ADDR ---> GND

    I think my connection is right, because I can successfully get the data from SCE, but I really don't know why it doesn't work on CCS project.

    And I look through the I2C in TI-drivers API several times, I cannot find any problem on the I2C configuration.
  • The sensor controller does a bit banged version of I2C, if you run it from the CM3 it uses a hardware module and a different driver. I saw a E2E post regarding I2C not too long ago where the issue was the bit order in the address (I think) I would recommend doing a search on E2E to find how others has solved their issue. We don't have other sensors easily available to test with hence it's a bit difficult to do testing on our side.