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.

CC2650STK: can't get value from temperature sensor using I2C_transfer() function.

Part Number: CC2650STK
Other Parts Discussed in Thread: CC2650, , TMP102

Hi 

I am trying to use the source code for launchpad in cc2650 sensortag and extend the code to get temperature value using I2C library. The example "i2ctmp007_cc2650STK_TI_CC2650f128"  works fine when I build it and upload it to the sensortag. But it doesn't work when I use same procedure to get temperature in a task that is triggered by SimpleBLEPeripheral_taskFxn. It seems I2C_transfer() function causing the problem here though I2C_open() returns true. I have changed priority of SBP_TASK_PRIORITY to 3, my created task to 2. 

I would be grateful if anyone help me out with this problem. I just want to get the temperature and humidity reading. What could go wrong?

Thanks in advance

  • Can you provide more details on what "task that is triggered by SimpleBLEPeripheral_taskFxn" means?
    The SensorTag sample application shows how to read sensor data over I2C.

    Best wishes
  • Dear sir,

    Thanks for your reply.

    What I want to do is get the IR temperature and the humidity sensor reading using sensortag. I know that the sensortag source code in the ble sdk contains the code. But I need to read reading from external sensor(Si7006-A20-IM). So I started with cc2650 sensortag( because tmp007 is simmiler to the sensor I need to use) and tried to extend source code for launchpad(simple_peripheral) and read temperature sensor from tmp007.

    What I did is mostly editing simple_peripheral.c in Application. There is a task with call back function simpleBLEPeripheral_taskFxn() and this task is created in SimpleBLEPeripheral_createTask(). I have similarly created a task calling function create_MyTask() from main to create the task and the callback function being MyTask_fxn(). I have posted a semaphore associated with MyTask in seimpleBLEPeripheral_taskFxn() so that bios may run MyTask. The task runs fine.
    Next I copy pasted the I2C codes from example i2ctmp007_CC2650STK_TI_CC2650f128(runs fine on sensortag) into the MyTask function.

    unsigned int i;
    uint16_t temperature;
    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(0, &i2cParams);
    if (i2c == NULL) {
    msg[7]='n';
    //System_abort("Error Initializing I2C\n");
    }
    else {
    //msg[7]=I2C_transfer(i2c, &i2cTransaction);
    //System_printf("I2C Initialized!\n");
    }

    /* Point to the T ambient register and read its 2 bytes */
    txBuffer[0] = TMP007_OBJ_TEMP;
    i2cTransaction.slaveAddress = Board_TMP007_ADDR;
    i2cTransaction.writeBuf = txBuffer;
    i2cTransaction.writeCount = 1;
    i2cTransaction.readBuf = rxBuffer;
    i2cTransaction.readCount = 2;
    msg[9] ++;
    if (I2C_transfer(i2c, &i2cTransaction)) {
    temp = 16;
    /* Extract degrees C from the received data; see TMP102 datasheet */
    temperature = (rxBuffer[0] << 6) | (rxBuffer[1] >> 2);

    /*
    * 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;
    }
    /*
    * For simplicity, divide the temperature value by 32 to get rid of
    * the decimal precision; see TI's TMP007 datasheet
    */
    temperature /= 32;
    msg[5]= temperature;
    temp = 12;

    //System_printf("Sample %u: %d (C)\n", i, temperature);
    }
    else {
    // System_printf("I2C Bus fault\n");
    }

    I2C_open(0, &i2cParams) does not return false. But I2C_transfer(i2c, &i2cTransaction) does not work. codes in if condition never executes.


    Can you please help me with this?

    Thanks in advance
    Zubair