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/LAUNCHXL-CC2650: i2cStatus always 0x0001 when trying to read temperate from RTC module using SCS

Part Number: LAUNCHXL-CC2650

Tool/software: TI-RTOS

Hello,

I am having trouble getting i2c working in sensor controller studio. Every time I do "task testing" i2cStatus is always 0x0001.

Here is my code in arduino where I prototyped, I am now trying to get it working in SCS:

As you can see, it works perfectly in arduino.

Here is my SCS project: led_blinker_launchpad.zip

Please ignore the commented out code and title of the project. It's the LED example project I am modifying while following the code found in the I2C light sensor project and the i2c documentation for SCS..

Please ask questions if I forgot to say something, I will try to explain best I can.

  • Hi Roman,

    Have you gone through the Sensor Controller labs in SimpleLink Academy? You can find them here: software-dl.ti.com/.../overview.html
  • Here is the code, if it helps:

    state.counter += 10;
    
    // Select the temperature register
    i2cStart();
    i2cTx(I2C_OP_WRITE | 0x68);
    i2cTx(0x11);
    
    // If successful ...
    if (state.i2cStatus == 0x0000) {
        
        state.insidecounter += 3;
        
        U16 resultRegH;
        U16 resultRegL;
    
        // Read the result
        i2cRepeatedStart();
        i2cTx(I2C_OP_READ | DS3231_ADDRESS);
        i2cRxAck(resultRegH);
        i2cRxNack(resultRegL);
        i2cStop();
        
    } else {
        i2cStop();
    }
    
    fwScheduleTask(5);

    I can't even get inside the if statement. When using the debugger I can tell that the "i2cTx(I2C_OP_WRITE | 0x68);" statement returns i2cStatus of 0x0001

  • For the record, I can access the sensor from CCS:

        unsigned int    i;
        uint16_t        temperature;
        float           temp_float;
        uint8_t         txBuffer[1];
        uint8_t         rxBuffer[2];
        I2C_Handle      i2c;
        I2C_Params      i2cParams;
        I2C_Transaction i2cTransaction;
    
        /* Create I2C for usage */
        I2C_Params_init(&i2cParams);
        i2cParams.bitRate = I2C_400kHz;
        i2c = I2C_open(Board_I2C, &i2cParams);
        if (i2c == NULL) {
            System_abort("Error Initializing I2C\n");
        }
        else {
            System_printf("I2C Initialized!\n");
        }
    
        /* Point to the T ambient register and read its 2 bytes */
        // set up transaction
        txBuffer[0] = DS3231_REG_TEMPERATURE;
        i2cTransaction.slaveAddress = DS3231_ADDRESS;
        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)) {
    
                /* Extract degrees C from the received data; see TMP102 datasheet */
                temperature = (rxBuffer[0] << 2) | (rxBuffer[1] >> 6);
                temp_float = (float) temperature / 4.0f;
    
                /*
                 * If the MSB is set '1', then we have a 2's complement
                 * negative value which needs to be sign extended
                 */
    //            if (rxBuffer[0] & 0x80) {
    //                temperature |= 0xF000;
    //            }
    
                System_printf("Sample %u: %f (C)\n", i, temp_float);
            } else {
                System_printf("I2C Bus fault\n");
            }
    
            System_flush();
            Task_sleep(1000000 / Clock_tickPeriod);
        }
    
        /* Deinitialized I2C */
        I2C_close(i2c);
        System_printf("I2C closed!\n");

  • Hello Roman,

    • Have you mounted external pull-up on SCL and SDA?
      • External pull-up resistors are required for SCL and SDA. The resistor values must comply with the requirements in the I2C Specification. Typical values are 2.2 kOhm or 10 kOhm, depending on bus load and serial clock frequency.
    • Which sensor is it?
    • Can you try to run at 100 kHz instead of 400 kHz just to test?
    • Can you take a logic analyzer plot on the communication (for both working (CCS-TI-RTOS) and not working (SCS))?

  • Hi Eirik V,

    I am using a breakout board for the RTC module. It has 4.7 KOhm resistors inside. I double checked with a DMM. Here is the schematic for the breakout board: 7356.Protel Schematic.pdf

    The sensor is the DS3231, I am using a breakout board for it. Here is a link I found for it:

    I have tried both many times still nothing. I also tried varying the clock stretch timeout from 1 uS to 10 uS.

    I don't have a oscilloscope at home but I can try at school some time this week.

  • Here is a picture from the scope:

  • Here is another screenshot, but using a digital probe.

  • Hello Roman,

    Perhaps the pull-up is too weak?

    The TI-RTOS driver you succeeded with will configure internal pull-up on SDA/SCL. The sensor controller framework will not configure any pull-up. You can hack/alter this in the framework function scifTaskResourceInit():

    scifInitIo(9, AUXIOMODE_OPEN_DRAIN_WITH_INPUT, -1, 1);
    scifInitIo(10, AUXIOMODE_OPEN_DRAIN_WITH_INPUT, -1, 1);

    By changing the third argument to 1:

    scifInitIo(9, AUXIOMODE_OPEN_DRAIN_WITH_INPUT, 1, 1);
    scifInitIo(10, AUXIOMODE_OPEN_DRAIN_WITH_INPUT, 1, 1);

  • Hello Eirik V,

    Thank you for helping me out! I managed to get it working.

    It turns out the problem was the I2C slave address I was using.

    In Arduino I used 0x68, in RTOS I used 0x68, and hence also used it here. In hindsight it's obvious but I should have done 0x68 << 1. I figured it out by using the digital scope on the Sensor Controller version and the RTOS version and comparing the two.

    Figure 1: 0x68 address in sensor controller

    Figure 2: 0x68 << 1 address in sensor controller

  • Happy to hear you figured it out!