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/CC2640R2F: I2C problem in CC2640r2f launchpad, required launchpad inbuilt temp-sensor code

Part Number: CC2640R2F
Other Parts Discussed in Thread: HDC1080

Tool/software: Code Composer Studio

hi,

     This is harish i am using cc2640r2f launchpad i want to do i2c communication . the launchpad inbuilt one temperature sensor is there how to read that one any code is there for reading inbuilt tempareture sensor. here main prob i2c is not working

/*
 * Copyright (c) 2018-2019, 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.
 */

/*
 *  ======== i2ctmp116.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

/*
 *  ======== TMP Registers ========
 */
#define TMP006_REG          0x0001  /* Die Temp Result Register for TMP006 */
#define TMP116_REG          0x0000  /* Die Temp Result Register for TMP116 */

#define TMP006_ADDR         0x40;
#define TMP116_BP_ADDR      0x40;
#define TMP116_LP_ADDR      0x40;

static Display_Handle display;

/*
 *  ======== mainThread ========
 */
void *mainThread(void *arg0)
{
    uint16_t        sample;
    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();

    /* Configure the LED and if applicable, the TMP116_EN pin */
    GPIO_setConfig(Board_GPIO_LED0, GPIO_CFG_OUT_STD | GPIO_CFG_OUT_LOW);
#ifdef Board_GPIO_TMP116_EN
    GPIO_setConfig(Board_GPIO_TMP116_EN, GPIO_CFG_OUT_STD | GPIO_CFG_OUT_HIGH);
    /* 1.5 ms reset time for the TMP116 */
    sleep(1);
#endif

    /* 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 i2ctmp example.");

    /* Create I2C for usage */
    I2C_Params_init(&i2cParams);
    i2cParams.bitRate = I2C_100kHz;
    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;

    /*
     * Determine which I2C sensor is present.
     * We will prefer sensors in this order: TMP116 (on BoosterPacks),
     * TMP116 (on-board CC32XX LaunchPads), and last TMP006
     * (on older CC32XX LaunchPads).
     */
    /* Try TMP116 values */
    txBuffer[0] = TMP116_REG;
    i2cTransaction.slaveAddress = TMP006_ADDR;
    if (!I2C_transfer(i2c, &i2cTransaction)) {
        /* Not BP TMP116, try LP TMP116 */
        i2cTransaction.slaveAddress = TMP006_ADDR;
        if (!I2C_transfer(i2c, &i2cTransaction)) {
            /* Not a TMP116 try TMP006*/
            txBuffer[0] = TMP006_ADDR;
            i2cTransaction.slaveAddress = TMP006_ADDR;
            if (!I2C_transfer(i2c, &i2cTransaction)) {
                /* Could not resolve a sensor, error */
                Display_printf(display, 0, 0, "Error. No TMP sensor found!");
                while(1);
            }
        }
    }

    /* Print which TMP is in use */
    if (TMP116_REG == txBuffer[0]) {
        Display_printf(display, 0, 0, "Detected TMP116 sensor.");
    }
    else {
        Display_printf(display, 0, 0, "Detected TMP006 sensor.");
    }

    /* Take 20 samples and print them out onto the console */
    for (sample = 0; sample < 20; sample++) {
        if (I2C_transfer(i2c, &i2cTransaction)) {
            /*
             * Extract degrees C from the received data;
             * see TMP116/006 datasheet
             */
            temperature = (rxBuffer[0] << 8) | (rxBuffer[1]);
            temperature *= 0.0078125;

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

            Display_printf(display, 0, 0, "Sample %u: %d (C)",
                sample, temperature);
        }
        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);
}

  • Not sure what you are asking about here. 

    The CC2640R2F does not have a external I2C temperature sensor.  

    For the built-in temperature sensor, check the API documentation hre: http://dev.ti.com/tirex/content/simplelink_cc2640r2_sdk_4_10_00_10/docs/driverlib_cc13xx_cc26xx/cc26x0r2/driverlib/group__aonbatmon__api.html

  • hi,

    actually i wrote code for i2c using cc2640r2f. i want read data from temperature sensor

    but it wont identify the i2c.

    i got problem  in this function ( status = I2C_transfer(g_i2cHandle, &i2cTrans); ) this function status always gave 0 value

    how to identify slave i2c ??

     /*
     * i2ccomm.c
     *
     *  Created on: 03-Jun-2020
     *      Author: harish
     */

    //#include <stdint.h>
    //#include <stddef.h>
    //#include <unistd.h>

    /* Driver Header files */
    #include "i2ccomm.h"
    #include <ti/drivers/GPIO.h>
    #include <ti/drivers/I2C.h>
    #include <ti/drivers/i2c/I2CCC26XX.h>
    #include <ti/drivers/PIN.h>
    #include <ti/drivers/UART.h>
    #include <ti/display/Display.h>

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

    UART_Params g_params;
    UART_Handle g_handle;
    I2C_Params  g_i2cparams;
    I2C_Handle  g_i2cHandle;
    I2C_Transaction i2cTrans;
    bool status;
    static Display_Handle display;

    uint8_t i2cInit()
    {
        I2C_init();
        I2C_Params_init(&g_i2cparams);
        g_i2cparams.transferMode = I2C_MODE_BLOCKING;
        g_i2cparams.transferCallbackFxn = NULL;
        g_i2cparams.custom = NULL;
        g_i2cparams.bitRate = I2C_100kHz;

    //    g_i2cHandle = I2C_open(Board_I2C0, &g_i2cparams);
        return 0;
    }


    uint8_t i2cScanner()
    {
        uint8_t nDevices = 0;

        for (uint8_t address = 1; address < 127; address++)
        {
            status =  i2cReadData(address);

            if (status == true)
            {
                nDevices++;
            }
        }
        return nDevices;
    }

    uint8_t i2cReadData(uint8_t address)
    {

        i2cTrans.slaveAddress = address;
        i2cTrans.writeBuf = NULL;
        i2cTrans.writeCount = 0;
        i2cTrans.readBuf = NULL;
        i2cTrans.readCount = 0;
    //    iparams.transferMode = I2C_MODE_BLOCKING;
        g_i2cHandle = I2C_open(Board_I2C0, &g_i2cparams);
        status = I2C_transfer(g_i2cHandle, &i2cTrans);
        if (status == NULL)
        {
            Display_printf(display, 0, 0, "Error Initializing I2C\n");
        }

        I2C_close(g_i2cHandle);
        return status;
    }

    uint8_t checkdata()
    {
    return 0;
    }





  • Which temperature sensor do you use and have have you connected it to the launchpad? 

  • Temperature sensor -Hd 1080  

  • And to which pins have you connected this? I assume that you have used the correct slave I2C device.

  • hi,

     i have one problem with i2c... cc2640r2f launch pad interface to HDC1080 tempareture sensor but it works at 400khz but it didn't work at 100khz

    any problem with 100khz please tell me

  • It would have helped if you provided this information in your first post. 

    The driver supports 100 kHz and 400 kHz and the sensor supports even lower datarates meaning that 100 kHz should not be an issue.

    Have you used a scope to compare what happens on the interface when you select 100 kHz and 400 kHz? 

  • hii,

     i did not connect scope, it will take some time then i will give replay