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.

CCS/LAUNCHXL-CC2650: Programming the Si7021 temperature sensor with Sensor Controller Studio

Part Number: LAUNCHXL-CC2650

Tool/software: Code Composer Studio

Hello everyone,

I am trying program the temperature sensor Si7021 with the sensor controller on the CC2650 LAUNCHPAD. I am having a hard time understanding how to use I2C on the sensor controller studio. I have programmed the temperature sensor on Code Composer Studio successfully but I want it to run from the sensor controller so I can optimize the power consumption. Can anyone help me better understand the use of I2C on sensor controller. I have looked at the Ambient light sensor example that they have but I do not understand it.

/*
 *  ======== empty.c ========
 */
/* XDCtools Header files */
#include <xdc/std.h>
#include <xdc/runtime/System.h>
#include <ti/drivers/Power.h>
#include <ti/drivers/power/PowerCC26XX.h>

/* BIOS Header files */
#include <ti/sysbios/BIOS.h>
#include <ti/sysbios/knl/Clock.h>
#include <ti/sysbios/knl/Task.h>

/* TI-RTOS Header files */
#include <ti/drivers/I2C.h>
#include "I2C.h"
#include <ti/drivers/PIN.h>
#include <ti/drivers/i2c/I2CCC26XX.h>
#include <driverlib/prcm.h>

/* Board Header files */
#include "Board.h"

#define TASKSTACKSIZE   1024

Task_Struct task0Struct;
Char task0Stack[TASKSTACKSIZE];



Void Si7021(UArg arg0, UArg arg1)
{
    I2C_init();


    // Local Variables
    uint8_t             txBuff[1];
    uint8_t             rxBuff[2];
    I2C_Handle          handle;
    I2C_Params          params;
    I2C_Transaction     transaction;
    char                i = 0;
    bool                ret;
    I2CCC26XX_I2CPinCfg     pinCfg;


    // Opening the driver
    I2C_Params_init(&params);
    params.bitRate = I2C_400kHz;


    // Initialize master I2C transaction structure
    transaction.writeCount = 1;
    transaction.writeBuf = txBuff;
    transaction.readCount = 2;
    transaction.readBuf = rxBuff;
    transaction.slaveAddress = 0x40;


    // Open the I2C
    handle = I2C_open(Board_I2C0, &params);


    // Check for I2C Initialization
    if(handle == NULL)
    {
        System_printf("Error initializing\n");
    }
    else
    {
        System_printf("I2C initialized\n");
    }
    System_flush();


    pinCfg.pinSDA = Board_I2C0_SDA0;
    pinCfg.pinSCL = Board_I2C0_SCL0;
    params.custom = (uintptr_t)&pinCfg;

    // Extract data from sensor
    while(TRUE)
    {
        System_printf("Case %d: \n", i + 1);
        //System_flush();

        txBuff[0] = 0xE5;

        ret = I2C_transfer(handle, &transaction);
        if(ret)
        {
            // Get data from the buffers
            uint16_t msb = rxBuff[0];
            uint16_t lsb = rxBuff[1];

            //lsb &= 0xFC;

            uint16_t hum = msb << 8 | lsb;


            // Convert the data to readable data

            float humidity = (125.0 * hum);
            humidity /= 65536;
            humidity -= 6;

            System_printf("%1.2f percent RH\n", humidity);
            System_flush();

        }

        txBuff[0] = 0xE0;
        if(ret)
        {
            //Get data from the buffers
            uint16_t msb = rxBuff[0];
            uint16_t lsb = rxBuff[1];

            //lsb &= 0xFC;

            uint16_t temp = msb << 8 | lsb;

            // Convert the data to readable data
            float temperature = (175.72 * temp);
            temperature /= 65536;
            temperature -= 46.85;

            // Convert to Fahrenheit
            temperature *= 9;
            temperature /= 5;
            temperature += 14;

            System_printf("%1.2f degrees F\n", temperature);
            System_flush();

        }

        i++;
    }
}

/*
 *  ======== main ========
 */
int main(void)
{
    Task_Params taskParams;

    /* Call board init functions */
    Board_initGeneral();
    Board_initI2C();


    /* Construct heartBeat Task  thread */
    Task_Params_init(&taskParams);
    taskParams.stackSize = TASKSTACKSIZE;
    taskParams.stack = &task0Stack;
    Task_construct(&task0Struct, (Task_FuncPtr)Si7021, &taskParams, NULL);


    /* Start BIOS */
    BIOS_start();

    return (0);
}

 I have inserted the code I used to program the temperature sensor using code composer studio. If anyone can please help me convert this code to something that will function on the sensor controller studio. Thank you!

Best Regards,

     Francisco Ochoa

  • I assume you have seen the I2C light sensor example in Sensor Controller Studio? The only thing you should have to do is to change the address. What exactly do you have a problem with? I believe that the Sensor Controller Studio implementation and the I2C driver uses different address format.
  • I have looked at the I2C light example and I have changed all the addresses but I don't get any output value. Also, it seems the I2C state must be 0x000 in order for it I2C to be successful and I keep on getting 0x0001.
  • I got it to work. I had to shift the slave address by 1 and I was able to read temperature and humidity from the sensor. Thanks!
  • I modified the i2c ALS example yet only produced inconsistent and slow response from the Si7021. It appears to be a timing problem not well defined. I tried lots and lots of timing sequences but could not obtain a solid consistent packets... attached is an example of a well working i2c sensor with Sensor Controller Studio, something I could not achieve with the Si7021. So, I ordered the HDC1010 and hope to have a little easier job, since it is already a part of the SubG ecosystem. Thank you for sharing your excellent code Francisco.