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/CC3220SF-LAUNCHXL: CC3220 SF I2c Interfacing

Part Number: CC3220SF-LAUNCHXL
Other Parts Discussed in Thread: TMP006, TMP102, CC3220SF

Tool/software: Code Composer Studio

Hey guys,

I am trying to interface AM2315 temperature sensor with cc3220 sf via I2C communication. The sensor works on 5V logic level and the board works on 3.3 V logic level, so I am using a level shifter between the board and the sensor. In firmware i am using I2c006tmp example:

//#define TMP006_ADDR         0x41

//#define TMP006_DIE_TEMP     0x0001  /* Die Temp Result Register */

//#ifndef Board_TMP_ADDR

//#define Board_TMP_ADDR       TMP006_ADDR

//#endif

static Display_Handle display;

/*

 *  ======== mainThread ========

 */

void *mainThread(void *arg0)

{

    unsigned int    i;

    uint16_t        temperature;

    uint16_t        humidity;

    uint8_t         txBuffer[3];

    uint8_t         rxBuffer[10];

    I2C_Handle      i2c;

    I2C_Params      i2cParams;

    I2C_Transaction i2cTransaction;

    /* Call driver init functions */

    Display_init();

    GPIO_init();

    I2C_init();

    /* Configure the LED 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 i2ctmp006 example\n");

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

    }

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

    txBuffer[0] = 0x03;

    txBuffer[1] = 0x00;

    txBuffer[2] = 4;

    i2cTransaction.slaveAddress = 0x5C;

    i2cTransaction.writeBuf = txBuffer;

    i2cTransaction.writeCount = 3;

    i2cTransaction.readBuf = rxBuffer;

    i2cTransaction.readCount = 2;

    /* Take 5 samples and print them out onto the console */

    for (i = 0; i < 5; i++)

    {

        if (I2C_transfer(i2c, &i2cTransaction))

        {

            /* Extract degrees C from the received data; see TMP102 datasheet */

            humidity = rxBuffer[2];

            humidity = humidity * 256;

            humidity = humidity + rxBuffer[3];

            humidity = humidity /10;

            temperature = rxBuffer[4] & 0x7F;

            temperature = temperature * 256;

            temperature = temperature + rxBuffer[5];

            temperature = temperature / 10;

            if(rxBuffer[4] >> 7)

            {

                temperature = -temperature;

            }

            /*

//            if (rxBuffer[0] & 0x80) {

//                temperature |= 0xF000;

//            }

//           /*

//            * For simplicity, divide the temperature value by 32 to get rid of

//            * the decimal precision; see TI's TMP006 datasheet

//            */

//            temperature /= 32;

            Display_printf(display, 0, 0, "Sample %u: %d (C)\n", i, temperature);

        }

        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");

}

All I am getting at the console is "I2c bus fault). Please tell me what I am doing wrong.

 

  • Hi Saksham,

    You're seeing that because I2C_transfer is return false which signifies an error. Do you have any logic analyzer captures so you can see what is going wrong? At first glance it looks like your basing your implementation on our I2C example so it should work assuming you make the proper modifications for your specific sensor.

    Jesu

  • Sir,

    I don't have an logic analyser. I changed the library according to AM 2315 data sheet. But I am not sure I made the right changes.

  • Hello Saksham,

    According to this datasheet, the slave address for the device you're using is 0xB8. You set it to 0x56, if that was a mistake, make sure you correct it.

    Also, you set your rxBuff size to 10 and i2cTransaction.readCount to 2. I don't think that will give you an error but the I2C peripheral will not use the full range for the rx buffer you created. 

    Make sure you have pull up resistors on your SDA and SCL lines. I understand you're using a level-shifter so check if it already has pull ups integrated by reviewing the level-shifter datasheet. If it doesn't you will wan't to add some on both sides of the shfiter. Values between 3kOhm and 10kOhm are acceptable. 

    Here is our I2C API documentation if you'd like to learn more about our I2C drivers. 

    I recommend you review the datasheet further if you continue having issues with your device.

    Jesu

  • Sir,

    I am using the library provided here github.com/.../Adafruit_AM2315 and merging it with the I2c temp library that's provided by CC3220SF. There the address is provided 0x5C which is 1 bit right shift of 0xB8. I still don't know what I am doing wrong.

  • Saksham,

    The i2c library and example works as is. Unless you can accurately describe your problem I cannot assist you.

    Jesu
  • Sir,

    I used a level shifter between the board and the sensor. I am using this example to read temp/humidity from the AM2315 sensor. I am unable to read from the sensor.

    I edited the basic I2c program for the sensor:

    /*

     * Copyright (c) 2015-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.

     */

    /*

     *    ======== i2ctmp006.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 TMP006_ADDR         0x41

    //#define TMP006_DIE_TEMP     0x0001  /* Die Temp Result Register */

    //#ifndef Board_TMP_ADDR

    //#define Board_TMP_ADDR       TMP006_ADDR

    //#endif

    static Display_Handle display;

    /*

     *  ======== mainThread ========

     */

    void *mainThread(void *arg0)

    {

        unsigned int    i;

        uint16_t        temperature;

        uint16_t        humidity;

        uint8_t         txBuffer[3];

        uint8_t         rxBuffer[10];

        I2C_Handle      i2c;

        I2C_Params      i2cParams;

        I2C_Transaction i2cTransaction;

        /* Call driver init functions */

        Display_init();

        GPIO_init();

        I2C_init();

        /* Configure the LED 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 i2ctmp006 example\n");

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

        }

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

        txBuffer[0] = 0x03;

        txBuffer[1] = 0x00;

        txBuffer[2] = 4;

        i2cTransaction.slaveAddress = 0xB8;

        i2cTransaction.writeBuf = txBuffer;

        i2cTransaction.writeCount = 3;

        i2cTransaction.readBuf = rxBuffer;

        i2cTransaction.readCount = 1;

        /* Take 20 samples and print them out onto the console */

        for (i = 0; i < 5; i++)

        {

            if (I2C_transfer(i2c, &i2cTransaction))

            {

                /* Extract degrees C from the received data; see TMP102 datasheet */

                humidity = rxBuffer[2];

                humidity = humidity * 256;

                humidity = humidity + rxBuffer[3];

                humidity = humidity /10;

                temperature = rxBuffer[4] & 0x7F;

                temperature = temperature * 256;

                temperature = temperature + rxBuffer[5];

                temperature = temperature / 10;

                if(rxBuffer[4] >> 7)

                {

                    temperature = -temperature;

                }

                /*

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

    //            }

    //           /*

    //            * For simplicity, divide the temperature value by 32 to get rid of

    //            * the decimal precision; see TI's TMP006 datasheet

    //            */

    //            temperature /= 32;

                Display_printf(display, 0, 0, "Sample %u: %d (C)\n", i, temperature);

            }

            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 (0);

    }

    Please assist me for a solution to this problem.

  • I changed the program a bit. Also, I am using pull-ups(4.7K) only on the sensor side and the level shifter dosent have internal pull-ups. Still no change in the output. Bus fault is getting printed.
    /*
    * Copyright (c) 2015-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.
    */

    /*
    * ======== i2ctmp006.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 TMP006_ADDR 0x41
    //#define TMP006_DIE_TEMP 0x0001 /* Die Temp Result Register */

    //#ifndef Board_TMP_ADDR
    //#define Board_TMP_ADDR TMP006_ADDR
    //#endif

    static Display_Handle display;

    /*
    * ======== mainThread ========
    */
    void *mainThread(void *arg0)
    {
    unsigned int i;
    uint16_t temperature;
    uint16_t humidity;
    uint8_t txBuffer[3];
    uint8_t rxBuffer[10];
    I2C_Handle i2c;
    I2C_Params i2cParams;
    I2C_Transaction i2cTransaction;

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

    /* Configure the LED 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 i2ctmp006 example\n");

    /* 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");
    }
    /* Point to the T ambient register and read its 2 bytes */

    txBuffer[0] = 0x03;
    txBuffer[1] = 0x00;
    txBuffer[2] = 4;
    i2cTransaction.slaveAddress = 0xB8;
    i2cTransaction.writeBuf = txBuffer;
    i2cTransaction.writeCount = 3;
    i2cTransaction.readBuf = rxBuffer;
    i2cTransaction.readCount = 10;

    /* Take 20 samples and print them out onto the console */
    for (i = 0; i < 5; i++)
    {
    if (I2C_transfer(i2c, &i2cTransaction))
    {
    /* Extract degrees C from the received data; see TMP102 datasheet */
    humidity = rxBuffer[2];
    humidity = humidity * 256;
    humidity = humidity + rxBuffer[3];
    humidity = humidity /10;


    temperature = rxBuffer[4] & 0x7F;
    temperature = temperature * 256;
    temperature = temperature + rxBuffer[5];
    temperature = temperature / 10;

    if(rxBuffer[4] >> 7)
    {
    temperature = -temperature;
    }


    /*
    * 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;
    // }
    // /*
    // * For simplicity, divide the temperature value by 32 to get rid of
    // * the decimal precision; see TI's TMP006 datasheet
    // */
    // temperature /= 32;

    Display_printf(display, 0, 0, "Sample %u: %d (C)\n", i, temperature);
    }
    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 (0);
    }
  • Paste the I2CCC332XX.c file into your project which you can find at SDK_ROOT/source/ti/i2c.

    Run the project in debug mode and set a break point in I2CCC32XX_transfer() to debug what the problem is.

    Jesu
  • Sir,

    I am able to read from the default I2c pins(GPIO 10 and GPIO 11). But, when I am declaring GPIO12 as CLK and GPIO13 as SDA, their is no data transfer. What can be the reason.?

  • Sir,

    Even commented out GPIO 12 and GPIO 13 in the CC3220SF_LAUNCHPADXL_C config files
    // GPIOCC32XX_GPIO_12 | GPIO_DO_NOT_CONFIG
    //GPIOCC32XX_GPIO_13 | GPIO_CFG_INPUT | GPIO_CFG_IN_INT_RISING,
  • Hi,

    Please make sure that you have proper pull-ups at your I2C line. Ale you should check that 10k pull-down resistor (R141) at GPIO_13 does not cause your issue.

    Jan
  • Sir,


    I am having a level shifter IC. I am not using pull-ups. How can I remove the pulldown resistor(10k)?
  • Hi,

    You should check how looks voltage levels at pin GPIO_13. In case of levels are not correct, you can remove R141 from LunchPad board.

    Are you sure that you don't need pull-up resistors at 3.3V side? In case of that you have I2C at GPIO_10/11 and you not have removed jumpers J15, J16, there 3.3K pull-up are already there (R118, R119).

    Jan
  • Sir,

    I have removed J15, J16 and J24 when I interfaced with GPIO10 and GPIO 11. Also, how to remove the R141 from the launchpad.?
  • Hi,

    By the solder iron or by hot air. Before removing R141 you should check voltage levels on I2C pins (at 3.3V side).

    Another option can be that your I2C driver is no properly configured. For TI-Drivers configuration you can use www.ti.com/.../PINMUXTOOL

    Jan
  • Hi,

    The voltage of PIN4 is 2.7 V and SCL is 3.3
  • Hi,

    I don't understand. Where do you measure voltages?

    Jan
  • Hey,

    The pin03(SCL) has 3.3V and pin 04(SDA) has voltage 2.7 with respect to ground.
  • Hi,

    Yes, 2.7V is not good voltage level for I2C bus definitely.

    Jan
  • Sir,

    So I should go ahead with removing the pulldown resisto(R141) right?
  • HI,

    Yes, I suppose that it should be this one. Before removing resistor you should check schematic for you LaunchPad ( www.ti.com/.../getliterature.tsp ). Please make sure that you have selected proper type of LP.

    Jan