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.

AWR6843AOPEVM: read Temp via i2c

Part Number: AWR6843AOPEVM
Other Parts Discussed in Thread: TMP112,

Hi,I want to read the TMP112A's temperature of  xwr6843aopEVM via i2c. The rend function is  as follows:

float TMP_ReadTemp(I2C_Handle i2cHandle, uint8_t i2cSlaveAddress, uint8_t i2cSlaveRegAddress)
{
    uint8_t         txData[2];
    bool            retVal = false;
    uint8_t         rxData[2];
    I2C_Transaction i2cTransaction;
    int16_t         digitalTemp = 2;
    int32_t         errCode;

    /* Scan for the slave address */
    System_printf ("22222222222 \n");
    txData[0] = i2cSlaveRegAddress;
    System_printf ("333333333 \n");
    i2cTransaction.slaveAddress = i2cSlaveAddress;
    System_printf ("44444444444 \n");
    i2cTransaction.writeBuf = txData;
    System_printf ("55555555555 \n");
    i2cTransaction.writeCount = 1;
    System_printf ("666666666666 \n");
    i2cTransaction.readBuf = rxData;
    System_printf ("777777777777 \n");
    i2cTransaction.readCount = 0;
    System_printf ("8888888888888 \n");

    /* Writing to slave address */
    retVal = I2C_transfer(i2cHandle, &i2cTransaction);
    if (retVal == false)
    {
        System_printf ("I2C_transfer Failed \n");
    }
    else
    {
        /* Read from slave */
        System_printf ("99999999999 \n");
        i2cTransaction.slaveAddress = i2cSlaveAddress + 1;
        i2cTransaction.writeBuf = txData;
        i2cTransaction.writeCount = 0;
        i2cTransaction.readBuf = rxData;
        i2cTransaction.readCount = 2;

        retVal = I2C_transfer(i2cHandle, &i2cTransaction);
        if (retVal == false)
        {
            errCode = -1;
        }
        else
        {
            digitalTemp = (rxData[0]<<4) | (rxData[1]>>4);
            if(digitalTemp > 0x7FF)
            {
                digitalTemp |= 0xF000;
            }
        }
    }
    return digitalTemp * 0.0625;
}

and before I use the api I2C_Handle,I2C_transfer()..,I have done I2C_Init(), I2C_Params_init(&i2cParams) and  I2C_open(0, &i2cParams). The result when I debug is as follow:

 

It seems that when the code run to I2C_transfer(), it will stop. Is there anything wrong in my code about I2C?

Thx!

leiGong

  • Hi leiGong,

    I have a few questions to give me a better understanding of your situation:

    1. Which version of the mmWave SDK are you using?
    2. Based on your screenshot it appears you are running the Overhead Vehicle Occupant Detection Demo, Is this correct?
      1. If yes, is this the only modifications that you have made are there other modifications?
      2. If no, which if any demo firmware are you running? 
    3. Have you referred to the I2C test code provided in the SDK at the following location?
      <SDK_INSTALL>/packages/ti/drivers/i2c/test

    Best Regards,

    Josh

  • Hi Josh Dye,
    Thanks for your reply!
    And my answers are as follows:
    Q1:  mmWave SDk version: mmwave_sdk_03_05_00_04
    Q2: Yes, it's based the Overhead Vehicle Occupant Detection Demo, but I have changed many places including algorithms and so on. And it works well if I don't add the READ TEPM via I2C code.
    Q3: Yes, My code is based on the <SDK_INSTALL>/packages/ti/drivers/i2c/test. But there still seems to be problems.
    And I also have some questions:
    1. If I2C slave-devices is more than one, How to decide the index (Logical peripheral number for the I2C indexed into the I2C_config table) when I use the api I2C_open?
    In the <SDK_INSTALL>/packages/ti/drivers/i2c/test. the index is 0 (see the follow picture). But if there is more than more one device linked the I2C Bus, I don't know what to do. Do I need use I2C_open(0, &i2cParams),I2C_open(1, &i2cParams),I2C_open(2, &i2cParams)...?
    2. I'm not clear that in the struct i2cTransaction, i2cTransaction.slaveAddress is the real SlaveAddress (such as 0x90) or the index(Logical peripheral number, such as 0,1,...). These two I have see and I am not clear which one I should choose.
    In the <SDK_INSTALL>/packages/ti/drivers/i2c/test/master.c
    In the follow test, the SlaveAddress seems to be the real address.
    main_thread.c
    which one is right, or I have misunderstand them?
    Thanks!
    Lei Gong
  • Hi Lei Gong,

    I apologize for the late response. Please allow me 1-2 days to get back to you on these questions and attempt to replicate your issue. 

    Best Regards,

    Josh

  • Never mind and Happy Thanksgiving !

    Look forward to your reply. And in the thread: https://e2e.ti.com/support/sensors-group/sensors/f/sensors-forum/1173275/awr6843aopevm-read-temperature-via-i2c/4416261?tisearch=e2e-sitesearch&keymatch=read%2520temp#4416261 I repeated my questions, maybe it can help you realize my problems clearly.

    Thaks again for your sincere reply !

    Lei Gong

  • Hi Lei Gong,

    Do I need use I2C_open(0, &i2cParams),I2C_open(1, &i2cParams),I2C_open(2, &i2cParams)...?

    You should only need to use I2C_open(0, &i2cParams). 

    I'm not clear that in the struct i2cTransaction, i2cTransaction.slaveAddress is the real SlaveAddress (such as 0x90) or the index(Logical peripheral number, such as 0,1,...).

    For i2cTransaction.slaveAddress, the real address should be used. The I2C address for the TMP112 can be found in the AWR6843AOPEVM schematic.

    Best Regards,

    Josh

  • Hi Josh,

    Your reply is clear. And I have modified the code according your instruction. I have double checked the slave address and slave reg address according https://www.ti.com/document-viewer/lit/html/SWRU546E/GUID-00256656-BC54-48EF-B44F-3054031A4C73#TITLE-SWRU546ID-B1E452BD-DA85-44F4-AD00-B689124D4D94

    Both of these two slave address I have tried. But it still  can't work Cold sweat. The modified code -- Read_Temp_Function is as follow, Could u plz help me to check it ?

    /* Read Temp function*/
    float TMP_ReadTemp(I2C_Handle i2cHandle, uint8_t i2cSlaveAddress, uint8_t i2cSlaveRegAddress)
    {
        uint8_t         txData[2];
        bool            retVal = true;
        uint8_t         rxData[2];
        I2C_Transaction i2cTransaction;
        int16_t         digitalTemp = 2;
        int32_t         errCode;
    
        /* Reset the transmit and receive buffer */
        memset(&rxData, 0, sizeof (rxData));
    
        /* Scan for the slave address */
        txData[0] = i2cSlaveRegAddress;
        i2cTransaction.slaveAddress = i2cSlaveAddress;
        i2cTransaction.writeBuf = txData;
        i2cTransaction.writeCount = 1;
        i2cTransaction.readBuf = rxData;
        i2cTransaction.readCount = 0;
    
        System_printf ("2222222222 \n");
        /* Writing to slave address */
        retVal = I2C_transfer(i2cHandle, &i2cTransaction);
        if (retVal == false)
        {
            System_printf ("I2C_transfer Failed \n");
        }
        else
        {
            /* Read from slave */
            System_printf ("3333333333 \n");
            i2cTransaction.slaveAddress = i2cSlaveAddress + 1;
            i2cTransaction.writeBuf = txData;
            i2cTransaction.writeCount = 0;
            i2cTransaction.readBuf = rxData;
            i2cTransaction.readCount = 2;
    
            retVal = I2C_transfer(i2cHandle, &i2cTransaction);
    
            System_printf ("44444444444444 \n");
            if (retVal == false)
            {
                errCode = -1;
            }
            else
            {
                digitalTemp = (rxData[0]<<4) | (rxData[1]>>4);
                if(digitalTemp > 0x7FF)
                {
                    digitalTemp |= 0xF000;
                }
            }
        }
        return digitalTemp * 0.0625;
    }

    The Read_Task to call Read_Temp_Function is as follow:

    And the result when I run the code is:

    I2C_transfer() is always failed and I don't know why.

    Looking forward your reply.

    Best wishes,

    Lei Gong

  • Hi Lei Gong,

    Please note it is outside the scope of these forums for us to debug custom code on your behalf. If you have specific questions about how to use certain driver APIs I can answer those. 

    I would suggest you ensure that you are using the I2C driver in a way that is consistent with the test code in the SDK.

    Best Regards,

    Josh