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.

I2C doesn't work in TI 15.4 Stack example.

Other Parts Discussed in Thread: CC1350, CC1310, OPT3001EVM, OPT3001

I do the following step to use I2C in sensor example.  I2C_open is no problem but I2C_transfer always return false. Can anyone use I2C successfully in sensor example?

1. Add the following header files to sensor.c

#include <ti/drivers/I2C.h> //YK
#include <ti/drivers/i2c/I2CCC26XX.h> //YK
#include "board.h" //YK
#include "board_lcd.h" //YK

2. Add the following I2C code in red to processSensorMsgEvt().

static void processSensorMsgEvt(void)
{
    Smsgs_sensorMsg_t sensor;
    uint32_t stat;

    memset(&sensor, 0, sizeof(Smsgs_sensorMsg_t));

    ApiMac_mlmeGetReqUint32(ApiMac_attribute_diagRxSecureFail, &stat);
    Sensor_msgStats.rxDecryptFailures = (uint16_t)stat;

    ApiMac_mlmeGetReqUint32(ApiMac_attribute_diagTxSecureFail, &stat);
    Sensor_msgStats.txEncryptFailures = (uint16_t)stat;

    ApiMac_mlmeGetReqArray(ApiMac_attribute_extendedAddress,
                           sensor.extAddress);

    /* fill in the message */
    sensor.frameControl = configSettings.frameControl;
    if(sensor.frameControl & Smsgs_dataFields_tempSensor)
    {
        memcpy(&sensor.tempSensor, &tempSensor,
               sizeof(Smsgs_tempSensorField_t));
    }
    if(sensor.frameControl & Smsgs_dataFields_lightSensor)
    {
        memcpy(&sensor.lightSensor, &lightSensor,
               sizeof(Smsgs_lightSensorField_t));
    }
    if(sensor.frameControl & Smsgs_dataFields_humiditySensor)
    {
        memcpy(&sensor.humiditySensor, &humiditySensor,
               sizeof(Smsgs_humiditySensorField_t));
    }
    if(sensor.frameControl & Smsgs_dataFields_msgStats)
    {
        memcpy(&sensor.msgStats, &Sensor_msgStats,
               sizeof(Smsgs_msgStatsField_t));
    }
    if(sensor.frameControl & Smsgs_dataFields_configSettings)
    {
        sensor.configSettings.pollingInterval = configSettings.pollingInterval;
        sensor.configSettings.reportingInterval = configSettings
                        .reportingInterval;
    }

    /* inform the user interface */
    Ssf_sensorReadingUpdate(&sensor);
    //YK
    {
        // Locals
        I2C_Handle handle;
        I2C_Params params;
        I2C_Transaction i2cTrans;
        uint8_t rxBuf[32];      // Receive buffer
        uint8_t txBuf[32];      // Transmit buffer
        I2C_init();
        // Configure I2C parameters.
        I2C_Params_init(&params);
        // Initialize master I2C transaction structure
        i2cTrans.writeCount   = 0;
        i2cTrans.writeBuf     = txBuf;
        i2cTrans.readCount    = 10;
        i2cTrans.readBuf      = rxBuf;
        i2cTrans.slaveAddress = 0x3C;
        // Open I2C
        handle = I2C_open(CC1350_LAUNCHXL_I2C0, &params);

        if (handle == NULL) {
            LCD_WRITE_STRING("Error Initializing I2C",8);
        }
        else {
            LCD_WRITE_STRING("I2C Initialized!",8);
        }

        // Do I2C transfer receive
        if (I2C_transfer(handle, &i2cTrans)){
            LCD_WRITE_STRING("Device ID read OK!",8);
        } else {
            LCD_WRITE_STRING("Device ID fail!",8);
        }

        /* Deinitialized I2C */
        I2C_close(handle);
        LCD_WRITE_STRING("I2C closed!",8);

        //System_flush();
    }
    /* send the data to the collector */
    sendSensorMessage(&collectorAddr, &sensor);
}

  • Hey YK,

    Information on how to use the I2C driver can be found in the SimpleLink CC13x0 SDK. Open tidriversAPIs.html in <SimpleLink SDK>\docs\tidrivers to see documentation on the I2C driver. To simply open a driver instance in blocking mode you can use this:

    // Example opening an I2C driver instance in blocking mode:
    
    I2C_Handle i2c;
    I2C_init();
    // NULL params are used, so default to blocking mode, 100 KHz
    i2c = I2C_open(Board_I2C0, NULL);
    if (!i2c) {
        // Error opening the I2C
    }
    
    // The below example shows sending three bytes of data to a slave peripheral at address 0x50, in blocking mode:
    
    unsigned char writeBuffer[3];
    I2C_Transaction i2cTransaction;
    i2cTransaction.slaveAddress = 0x50;
    i2cTransaction.writeBuf = writeBuffer;
    i2cTransaction.writeCount = 3;
    i2cTransaction.readBuf = NULL;
    i2cTransaction.readCount = 0;
    status = I2C_transfer(i2c, &i2cTransaction);
    if (!status) {
        // Unsuccessful I2C transfer
    }
    

    You can also refer to the I2C examples found in <SinpleLink SDK>\examples. Pick the example that matches your compiler and platform.

    ~Brocklobsta

  • I test your code in sensor.c and get the following link error. Do you test your I2C example code in TI 15.4 Stack sensor example?

    <Linking>

     undefined first referenced                                                                          
      symbol       in file                                                                               
     --------- ----------------                                                                          
     I2C_count C:/ti/simplelink_cc13x0_sdk_1_00_00_13/source/ti/drivers/lib/drivers_cc13x0.aem3<I2C.oem3>

    error #10234-D: unresolved symbols remain
    error #10010: errors encountered during linking; "sensor_cc1310lp.out" not built

    >> Compilation failure
    makefile:217: recipe for target 'sensor_cc1310lp.out' failed
    gmake[1]: *** [sensor_cc1310lp.out] Error 1
    makefile:213: recipe for target 'all' failed
    gmake: *** [all] Error 2

    **** Build Finished ****

  • Do you have any comment on this?
  • Can anyone from TI verify this?
  • Hey YK,

    Try adding this line in CC1350_LAUNCHXL.c

    const uint_least8_t I2C_count = CC1350_LAUNCHXL_I2CCOUNT;


    If you would like to see a example in action you can refer to the example "i2ctmp007_CC1310_LAUNCHXL_tirtos_ccs" in the SimpleLink CC13x0 SDK.

    ~Brocklobsta

  • I had added this line to solve the link problem but I2C_transfer still returns false. Do you test I2C code in sensor.c of TI 15.4 Stack by yourself?
  • I test i2ctmp007 example in simplelink_cc13x0_sdk_1_00_00_13. It doesn't work too and always goes to line "Display_printf(display, 0, 0, "I2C Bus fault\n");".
  • I had no problems with the i2ctmp007 example for the cc1350 sensor tag. I modified it with the i2c device addresses that I have on my custom board and was able to access them fine. My problem, same as YiKai, is trying to integrate i2c into the sensor example (TI 15.4-Stack v2.0.1). I lose connection to the debugger on the I2C_transfer() function call. I made a post on my issue here:
    e2e.ti.com/.../559735
  • OK, the problem is that I don't connect i2c sensor to my CC1310LP. After connecting the sensor, the code works fine.
  • YiKai Chen said:
    OK, the problem is that I don't connect i2c sensor to my CC1310LP. After connecting the sensor, the code works fine.

    In both the i2ctmp007 and the sensor example? If you were able to incorporate i2c into the sensor example, can you show me everything you did. Or if possible, maybe attach your project? Thanks.

  • I use OPT3001EVM and sample code in sunmaysky.blogspot.tw/.../basic-example-to-use-opt3001-on-cc2650.html . You have to connect OPT3001 SCL to CC1310LP DIO4 pin and SDA to CC1310LP DIO5 pin.
  • So the only changes you made to the sensor example were what you wrote in the first post and adding 'const uint_least8_t I2C_count = CC1350_LAUNCHXL_I2CCOUNT;' in CC1350_LAUNCHXL.c? Nothing else?

    Thanks.
  • Yes, that's what I did.