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-CC1352R1: read OPT3001 data from sensors boosterpack

Part Number: LAUNCHXL-CC1352R1
Other Parts Discussed in Thread: CC1352R

Tool/software: Code Composer Studio

Hi,

I have this code and I'd like to know how to read and convert the data to something readable. The code is from the i2ctmp example but I have changed the sensor address.

I'm using a CC1352R board with the sensors boosterpack.

#define TASKSTACKSIZE       640

/*
 *  ======== TMP Registers ========
 */

#define OPT_ADDR      0x47;

#ifndef Board_TMP_ADDR
#define Board_TMP_ADDR       TMP007_ADDR
#endif

static Display_Handle display;

/*
 *  ======== mainThread ========
 */
void *mainThread(void *arg0)
{
    uint16_t        sample;
    uint16_t        lux;
    uint8_t         txBuffer[1];
    uint8_t         rxBuffer[2];
    I2C_Handle      i2c;
    I2C_Params      i2cParams;
    I2C_Transaction i2cTransaction;

    /* Call driver init functions */
    Display_init();
    GPIO_init();
    I2C_init();

    /* Configure the LED and if applicable, the TMP116_EN pin */
    GPIO_setConfig(Board_GPIO_LED0, GPIO_CFG_OUT_STD | GPIO_CFG_OUT_LOW);


    /* Open the HOST display for output */
    display = Display_open(Display_Type_UART, NULL);
    if (display == NULL) {
        while (1);
    }

    /* Turn on user LED */
    GPIO_write(Board_GPIO_LED0, Board_GPIO_LED_ON);
    Display_printf(display, 0, 0, "Starting the opt example.");

    /* Create I2C for usage */
    I2C_Params_init(&i2cParams);
    i2cParams.bitRate = I2C_400kHz;
    i2c = I2C_open(Board_I2C_TMP, &i2cParams);
    if (i2c == NULL) {
        Display_printf(display, 0, 0, "Error Initializing I2C\n");
        while (1);
    }
    else {
        Display_printf(display, 0, 0, "I2C Initialized!\n");
    }

    /* Common I2C transaction setup */
    i2cTransaction.writeBuf   = txBuffer;
    i2cTransaction.writeCount = 1;
    i2cTransaction.readBuf    = rxBuffer;
    i2cTransaction.readCount  = 2;

    txBuffer[0] = 0x0003;
    i2cTransaction.slaveAddress = OPT_ADDR;
    if (!I2C_transfer(i2c, &i2cTransaction)) {
        Display_printf(display, 0, 0, "Error. No OPT sensor found!");
        while(1);
    }

    /* Take 20 samples and print them out onto the console */
    for (sample = 0; sample < 20; sample++) {
        if (I2C_transfer(i2c, &i2cTransaction)) {

            /*
             * Extract lux from the received data;
             * 
             */

            Display_printf(display, 0, 0, "Sample %u: %d (C)",
                sample+1, lux);
        }
        else {
            Display_printf(display, 0, 0, "I2C Bus fault.");
        }

        /* Sleep for 1 second */
        sleep(1);
    }

    I2C_close(i2c);
    Display_printf(display, 0, 0, "I2C closed!");

    return (NULL);
}