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-CC1310: Read data from sensor HDC1080 via I2C

Part Number: LAUNCHXL-CC1310
Other Parts Discussed in Thread: HDC1080, , CC1310, CC2650, CC2560, TMP102

Tool/software: TI-RTOS

Hello everybody,

I want to read data from the sensor HDC1080. I connected it to the LAUNCHXL-CC1310's I2C ports.

I added the following line to CC1310_LAUNCHXL.h:

#define Board_I2C_TMP CC1310_LAUNCHXL_I2C0

and I'm trying the code linked here for my purpose.

When I run the program, it returns an error when he tries to open the comunication with the following line of code:

i2c = I2C_open(Board_I2C_TMP, &i2cParams);

How can i fix this problem?

Thanks in advance for the help.

  • I'm already trying that example. I get an error when the code executes the following line:

    i2c = I2C_open(Board_I2C_TMP, &i2cParams);

    The function I2C_open returns a null value.

  • If you run i2ctmp007 example without modification, does it work?

  • Have you made sure that you connec to the correct IOs? The link you have for the CC2650 says that IOID_5 and 6 are used, but both the CC2560 and the CC13xx LPs uses IOID_4 and IOID_5 for I2C (see the CC1310_LAUNCHXL.h)
  • Yes, the examples works. It can open the communication. I don't understand why this happens, because the two codes seem equivalent.

  • Yes, I'm using the right IOs
  • I fixed the code and now the function I2C_open works.
    Now the problem is in the function I2C_transfer. I'm trying to write the configuration for the HDC1080 using the following code:
    txBuffer[0] = 0x02;
    txBuffer[1] = 0x10;
    txBuffer[2] = 0x00;
    i2cTransaction.slaveAddress = 0x40;//HDC1080 ADDR;
    i2cTransaction.writeBuf = txBuffer;
    i2cTransaction.writeCount = 3;
    i2cTransaction.readBuf = rxBuffer;
    i2cTransaction.readCount = 0;

    if (I2C_transfer(i2c, &i2cTransaction)){
    System_printf("Configurazione OK\n");
    } else {
    System_printf("Configurazione fallita\n");
    }
    But it crashes when I2C_transfer is execute.
    How can I fix this?
  • Try the following codes

    /*
     * Copyright (c) 2016-2017, Texas Instruments Incorporated
     * All rights reserved.
     *
     * Redistribution and use in source and binary forms, with or without
     * modification, are permitted provided that the following conditions
     * are met:
     *
     * *  Redistributions of source code must retain the above copyright
     *    notice, this list of conditions and the following disclaimer.
     *
     * *  Redistributions in binary form must reproduce the above copyright
     *    notice, this list of conditions and the following disclaimer in the
     *    documentation and/or other materials provided with the distribution.
     *
     * *  Neither the name of Texas Instruments Incorporated nor the names of
     *    its contributors may be used to endorse or promote products derived
     *    from this software without specific prior written permission.
     *
     * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
     * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
     * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
     * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
     * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
     * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
     * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
     * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
     * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
     * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     */

    /*
     *    ======== i2ctmp007.c ========
     */
    #include <stdint.h>
    #include <stddef.h>
    #include <unistd.h>

    /* Driver Header files */
    #include <ti/drivers/GPIO.h>
    #include <ti/drivers/I2C.h>
    #include <ti/display/Display.h>

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

    #define TASKSTACKSIZE       640

    #define TMP007_DIE_TEMP     0x0001  /* Die Temp Result Register */
    #define TMP007_OBJ_TEMP     0x0003  /* Object Temp Result Register */

    static Display_Handle display;

    /*
     *  ======== mainThread ========
     */
    void *mainThread(void *arg0)
    {
        unsigned int    i;
        uint16_t        temperature;
        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();

        /* 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 i2ctmp007 example\n");

        /* 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");
        }

        /* Point to the T ambient register and read its 2 bytes */

        /* Take 20 samples and print them out onto the console */
        for (i = 0; i < 20; i++) {
            txBuffer[0] = 0x00;
            i2cTransaction.slaveAddress = 0x40;
            i2cTransaction.writeBuf = txBuffer;
            i2cTransaction.writeCount = 1;
            i2cTransaction.readBuf = rxBuffer;
            i2cTransaction.readCount = 0;
            if (I2C_transfer(i2c, &i2cTransaction)) {
                Display_printf(display, 0, 0, "Temp/Humd!\n");
            }else{
                Display_printf(display, 0, 0, "Temp/Humd failed!\n");
            }
            sleep(1);
            txBuffer[0] = 0x00;
            i2cTransaction.slaveAddress = 0x40;
            i2cTransaction.writeBuf = txBuffer;
            i2cTransaction.writeCount = 0;
            i2cTransaction.readBuf = rxBuffer;
            i2cTransaction.readCount = 4;
            if (I2C_transfer(i2c, &i2cTransaction)) {
                /* Extract degrees C from the received data; see TMP102 datasheet */
                temperature = (rxBuffer[2] << 8) | (rxBuffer[3]);

                /*
                 * If the MSB is set '1', then we have a 2's complement
                 * negative value which needs to be sign extended
                 */
                /*
                * For simplicity, divide the temperature value by 32 to get rid of
                * the decimal precision; see TI's TMP007 datasheet
                */
                temperature = ((double)temperature / 65536)*100;

                //Display_printf(display, 0, 0, "Sample %u: %d (C)\n", i, temperature);
                Display_printf(display, 0, 0, "Sample H %u: %d (%)\n", i, temperature);
                //Display_printf(display, 0, 0, "MID %x: %x (C)\n", i, rxBuffer[1],rxBuffer[0]);
            }
            else {
                Display_printf(display, 0, 0, "I2C Bus fault\n");
            }

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

        /* Deinitialized I2C */
        I2C_close(i2c);
        Display_printf(display, 0, 0, "I2C closed!\n");

        return (NULL);
    }

    /*
     * Copyright (c) 2016-2017, Texas Instruments Incorporated
     * All rights reserved.
     *
     * Redistribution and use in source and binary forms, with or without
     * modification, are permitted provided that the following conditions
     * are met:
     *
     * *  Redistributions of source code must retain the above copyright
     *    notice, this list of conditions and the following disclaimer.
     *
     * *  Redistributions in binary form must reproduce the above copyright
     *    notice, this list of conditions and the following disclaimer in the
     *    documentation and/or other materials provided with the distribution.
     *
     * *  Neither the name of Texas Instruments Incorporated nor the names of
     *    its contributors may be used to endorse or promote products derived
     *    from this software without specific prior written permission.
     *
     * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
     * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
     * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
     * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
     * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
     * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
     * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
     * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
     * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
     * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     */

    /*
     *    ======== i2ctmp007.c ========
     */
    #include <stdint.h>
    #include <stddef.h>
    #include <unistd.h>

    /* Driver Header files */
    #include <ti/drivers/GPIO.h>
    #include <ti/drivers/I2C.h>
    #include <ti/display/Display.h>

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

    #define TASKSTACKSIZE       640

    #define TMP007_DIE_TEMP     0x0001  /* Die Temp Result Register */
    #define TMP007_OBJ_TEMP     0x0003  /* Object Temp Result Register */

    static Display_Handle display;

    /*
     *  ======== mainThread ========
     */
    void *mainThread(void *arg0)
    {
        unsigned int    i;
        uint16_t        temperature;
        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();

        /* 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 i2ctmp007 example\n");

        /* 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");
        }

        /* Point to the T ambient register and read its 2 bytes */

        /* Take 20 samples and print them out onto the console */
        for (i = 0; i < 20; i++) {
            txBuffer[0] = 0x00;
            i2cTransaction.slaveAddress = 0x40;
            i2cTransaction.writeBuf = txBuffer;
            i2cTransaction.writeCount = 1;
            i2cTransaction.readBuf = rxBuffer;
            i2cTransaction.readCount = 0;
            if (I2C_transfer(i2c, &i2cTransaction)) {
                Display_printf(display, 0, 0, "Temp/Humd!\n");
            }else{
                Display_printf(display, 0, 0, "Temp/Humd failed!\n");
            }
            sleep(1);
            txBuffer[0] = 0x00;
            i2cTransaction.slaveAddress = 0x40;
            i2cTransaction.writeBuf = txBuffer;
            i2cTransaction.writeCount = 0;
            i2cTransaction.readBuf = rxBuffer;
            i2cTransaction.readCount = 4;
            if (I2C_transfer(i2c, &i2cTransaction)) {
                /* Extract degrees C from the received data; see TMP102 datasheet */
                temperature = (rxBuffer[2] << 8) | (rxBuffer[3]);

                /*
                 * If the MSB is set '1', then we have a 2's complement
                 * negative value which needs to be sign extended
                 */
                /*
                * For simplicity, divide the temperature value by 32 to get rid of
                * the decimal precision; see TI's TMP007 datasheet
                */
                temperature = ((double)temperature / 65536)*100;

                //Display_printf(display, 0, 0, "Sample %u: %d (C)\n", i, temperature);
                Display_printf(display, 0, 0, "Sample H %u: %d (%)\n", i, temperature);
                //Display_printf(display, 0, 0, "MID %x: %x (C)\n", i, rxBuffer[1],rxBuffer[0]);
            }
            else {
                Display_printf(display, 0, 0, "I2C Bus fault\n");
            }

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

        /* Deinitialized I2C */
        I2C_close(i2c);
        Display_printf(display, 0, 0, "I2C closed!\n");

        return (NULL);
    }

  • Yes, it works. Thank you for the help.