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(¶ms);
    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, ¶ms);
    // 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
 
				 
		 
					 
                           
				 
				 
				