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.

CC3220: I2C (Dealy in I2C read) interfacing in CC3220MODASF

Part Number: CC3220

Hi,

I am trying to interface and access HDC1080 sensor to my CC3220MODASlaunchpad.

I am done with reading the read only registers like manufacturer Id and Device Id with out issue.

The same I am repeating to read the Temperature sensor from address 0x00 and getting the I2C Bus Fault.


As per data sheet of My HDC1080 sensor (attached), the dealy of 6.5ms is need to read the data after write. So I am looking enter the delay between command code write and data read from My Slave. I am not getting the pointer function calling in the I2C.h of  "i2ctmp006 example project from SDK2.3"

Pleas any one help me resolve my issue, as of my knowledge I need to enter delay before read. Please see the attached data sheet and the my code below:

    txBuffer[0] = 0x00;
    i2cTransaction.slaveAddress = 0x40;
    i2cTransaction.writeBuf = txBuffer;
    i2cTransaction.writeCount = 1;
    i2cTransaction.readBuf = rxBuffer;
    i2cTransaction.readCount = 2;

    while(1){
        if (I2C_transfer(i2c, &i2cTransaction)) {
            temperature = rxBuffer[0];
            temperature = (temperature << 8)|rxBuffer[1];

            float newtemperature = (((float)temperature/65536) * 165)-40;


            Display_printf(display, 0, 0, "Temperature = %f ('C)\n", newtemperature);

        }
        else {
            Display_printf(display, 0, 0, "I2C Bus fault\n");
        }

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

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

    return (0);

Please let me know what is happening here:

/*!
 *  @brief      A function pointer to a driver-specific implementation of
 *              I2C_transfer().
 */
typedef bool (*I2C_TransferFxn) (I2C_Handle handle,
    I2C_Transaction *transaction);

hdc1080.pdf

Thank you

  • The HDC1080 requires a wait greater than or equal to HDC1080 Conversion Time after I2C Write pointer 0x00 (or 0x01) and before I2C Read. If you don't wait long enough, you will receive NACK. This is described on Page 11-12 of the HDC1080 datasheet. Conversion Time is ~4-7ms depending on configuration.

    Thanks,
    Ren
  • Dear Ren,
    I am asking the same, how to insert delay before read in CC3220 sdk project "i2ctmp00c".

    Thank you
  • Hello Raghu

    Use usleep(7000) for providing a delay of 7 ms and allowing the task to be suspended during the time.
  • Dear Amith, thank you response.
    As of my Knowledge I2C read data from Slave will work as
    Step-1 : Start to Write
    Step-2 : Send reg addr to read
    Step-3 : Start to Read
    Step-4 : Read MSB
    Step-5 : Read LSB
    Step-6 : Stop

    In my case I have to insert "usleep(7000)" after Step-2.
    In the code of SDK I have not seen where this Steps were happening. I want to know the place/part of code to insert delay.

    Thank you.
  • Hello Raghu

    As mentioned by Ren earlier, you need to write to register 0x0 before waiting for the data

    Step-1: I2C write to pointer register 0x0
    usleep(7000)
    Step-2: I2C read from pointer register 0x0
    Step-3: I2C read from pointer register 0x1

    Figure-12 in the datasheet shows how to perform Step-1 and Figure-14 shows how to perform Step-2 and 3
  • Can you pls tell, how can do the same here, as per I2C example in SDK


    txBuffer[0] = 0x00;
    i2cTransaction.slaveAddress = 0x40;
    i2cTransaction.writeBuf = txBuffer;
    i2cTransaction.writeCount = 1;
    i2cTransaction.readBuf = rxBuffer;
    i2cTransaction.readCount = 2;


    while(1){
    if (I2C_transfer(i2c, &i2cTransaction)) {
    temperature = rxBuffer[0];
    temperature = (temperature << 8)|rxBuffer[1];


    float newtemperature = (((float)temperature/65536) * 165)-40;




    Display_printf(display, 0, 0, "Temperature = %f ('C)\n", newtemperature);


    }
    else {
    Display_printf(display, 0, 0, "I2C Bus fault\n");
    }


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


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


    return (0);
    Please let me know what is happening here:


    /*!
    * @brief A function pointer to a driver-specific implementation of
    * I2C_transfer().
    */
    typedef bool (*I2C_TransferFxn) (I2C_Handle handle,
    I2C_Transaction *transaction);

  • Hello Raghu,

    I do not have an active setup to test it, but it should be

    txBuffer[0] = 0x00;
    i2cTransaction.slaveAddress = 0x40;
    i2cTransaction.writeBuf = txBuffer;
    i2cTransaction.writeCount = 1;
    i2cTransaction.readBuf = rxBuffer;
    i2cTransaction.readCount = 0;
    I2C_transfer(i2c, &i2cTransaction)

    usleep(7000);


    txBuffer[0] = 0x00;
    i2cTransaction.slaveAddress = 0x40;
    i2cTransaction.writeBuf = txBuffer;
    i2cTransaction.writeCount = 0;
    i2cTransaction.readBuf = rxBuffer;
    i2cTransaction.readCount = 4;

    while(!(I2C_transfer(i2c, &i2cTransaction));