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)