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.

TMDS243EVM: I2C Read Write API Function

Part Number: TMDS243EVM

Tool/software:

I am using the I2C lld API functions to access the I2C port on a EVM board.

When I use the read functions following the example. I can get good I2C data from the device.

Then tried to use the write functions before the read code to implement a write/read operation to verify if the data are written into device.

But it always gave me all 0 results from reading the device, even the I2C handle is initialized between write and read.

The codes are as below.

/* Get the Device Address */
deviceAddress = 0x74;

status = I2C_lld_probe(gI2cLldHandle0, deviceAddress);

if(status == I2C_STS_SUCCESS)

{
      
         DebugP_log("[I2C] Device found at device address 0x%02x \r\n", deviceAddress);
}

/* Initialize I2C_ExtendedParams objects*/
extendedParamsTx.deviceAddress = deviceAddress;
extendedParamsTx.buffer = txBuf;
extendedParamsTx.size = 1U;
extendedParamsTx.expandSA = false;

txBuf[0U] = 0x20;
/*Write to I2C*/
status = I2C_lld_write(gI2cLldHandle0, &extendedParamsTx, I2C_WAIT_FOREVER);
if(status == I2C_STS_SUCCESS)
{
    DebugP_log("[I2C] write done\n");
}

gI2cLldHandle[0]->Clock_uSleep(delayMsec * 1000U);

/*Init the I2C handle*/

I2C_lld_init(gI2cLldHandle0);


extendedParamsRx.deviceAddress = deviceAddress;
extendedParamsRx.buffer = rxBuf;
extendedParamsRx.size = 0U;
extendedParamsRx.expandSA = false;

/* A loop to read multiple registers from I2C */

for(uint8_t i = 0; i < 8; i++)
{
    rxBuf[0U] = (uint8_t)(0U);

    extendedParamsRx.size = 1U;
    status = I2C_lld_read(gI2cLldHandle0, &extendedParamsRx, I2C_WAIT_FOREVER);

    /*Print results*/

    if(status == I2C_STS_SUCCESS)
    {
          DebugP_log("[I2C] Sample %u: %u\r\n", i, rxBuf[0]);
    }


gI2cLldHandle[0]->Clock_uSleep(delayMsec * 100U);
}

It looked the write function is not successful.

I think it is very basic operation.

Can you please look into the codes to see if there is anything need to be taken for the write and read?

Please share some guidance.

Thanks.

Thanks & Best regards

Hao (Wang hao)

  • Hi Hao,

    Which MCU+SDK version are you using?

    It looked the write function is not successful.

    Which I2C instance are you using? Also can you please share the example.syscfg file with us.

    Regards,

    Tushar

  • Tushar

    I am using version am243x_09_02_00_50.

    I have created my program based on i2c_led_read_write_lld. The syscfg is as attachment.https://e2e.ti.com/cfs-file/__key/communityserver-discussions-components-files/908/1581.example.syscfg

    https://e2e.ti.com/cfs-file/__key/communityserver-discussions-components-files/908/1581.example.syscfg

    And I found the read API can only give correct data from the first I2C read action.

    The second read will always give me all 0 results. 

    From my understanding for I2C standard protocol, the first byte should be 7 bits device slave addresses and 1 bit acknowledge, then followed by register address, and then read/write byte.

    But it looked that, the I2C read/write APIs just perform the I2C access by slave address and the read/write data, while skip the register addresses.

    Can you please advise which APIs are able to define the register address to perform genius I2C access?

    *

    Thanks. 

    Thanks & Best regards

    Hao (Wang hao)

  • Hi Hao,

    Which I2C device are you using? In the above code I can see you are using 0x74 as device address, but in the I2C_led_read_write_lld example uses 0x60 as device address.

    Regards,

    Tushar