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.

LP-AM263: I2C transfer and reset

Part Number: LP-AM263

Hi Teams,

I have the same problem in e2e(Link).

I can't recover the I2C state after a read to a non-existent device address(0xFF).

Moreover, I tried to create the re-init function to reset the I2C but it also fails to reset.

The source code based on i2c_read_am263x-lp_r5fss0-0_nortos_ti-arm-clang.

#include <drivers/i2c.h>
#include <kernel/dpl/DebugP.h>
#include "ti_drivers_config.h"
#include "ti_drivers_open_close.h"
#include "ti_board_open_close.h"

extern uint32_t Board_i2cGetEepromDeviceAddr(void);
#define I2C_READ_LEN                    (1U)

static void i2c_read_error_handler(uint16_t sample, int32_t status);
int api_i2c_reinit();

void i2c_read_main(void *arg0)
{
    uint16_t        sample;
    int32_t         status;
    uint32_t        i2cReadTargetAddr;
    uint8_t         rxBuffer[I2C_READ_LEN];
    I2C_Handle      i2cHandle;
    I2C_Transaction i2cTransaction;

    Drivers_open();
    Board_driversOpen();

    i2cHandle = gI2cHandle[CONFIG_I2C0];
    i2cReadTargetAddr     = 0xFF;

    DebugP_log("[I2C] Read data in 0xFF... !!!\r\n");

    /* Set default transaction parameters */
    I2C_Transaction_init(&i2cTransaction);

    /* Override with required transaction parameters */
    i2cTransaction.readBuf      = rxBuffer;
    i2cTransaction.readCount    = I2C_READ_LEN;
    i2cTransaction.targetAddress = i2cReadTargetAddr;

    I2C_probe(i2cHandle, i2cReadTargetAddr);

    status = I2C_transfer(i2cHandle, &i2cTransaction);

    DebugP_log("[I2C] rxBuffer[0] = %u, 0x%x\r\n", rxBuffer[0], status);

    DebugP_log("[I2C] Read data in i2cReadTargetAddr ... !!!\r\n");

    i2cReadTargetAddr     = Board_i2cGetEepromDeviceAddr();

    api_i2c_reinit();

    /* Set default transaction parameters */
    I2C_Transaction_init(&i2cTransaction);

    /* Override with required transaction parameters */
    i2cTransaction.readBuf      = rxBuffer;
    i2cTransaction.readCount    = I2C_READ_LEN;
    i2cTransaction.targetAddress = i2cReadTargetAddr;

    /* Read 20 samples and log them */
    for(sample = 0; sample < 20; sample++)
    {
        status = 0;
        I2C_probe(i2cHandle, i2cReadTargetAddr);
        status = I2C_transfer(i2cHandle, &i2cTransaction);

        if(status == I2C_STS_SUCCESS)
        {
            DebugP_log("[I2C] Sample %u: %u\r\n", sample, rxBuffer[0]);
        }
        else
        {
            i2c_read_error_handler(sample, status);
            DebugP_log("[I2C] rxBuffer[0] = %u, 0x%x\r\n", rxBuffer[0], status);
        }
    }

    DebugP_log("[I2C] Read data ... DONE !!!");
    if(status == SystemP_SUCCESS)
    {
        DebugP_log("All tests have passed!!\r\n");
    }
    else
    {
        DebugP_log("Some tests have failed!!\r\n");
    }

    Board_driversClose();
    Drivers_close();

    return;
}

static void i2c_read_error_handler(uint16_t sample, int32_t status)
{
    switch(status)
    {
        case I2C_STS_ERR:
            DebugP_logError("[I2C] Sample %u: Generic error occurred\r\n", sample);
            break;
        case I2C_STS_ERR_TIMEOUT:
            DebugP_logError("[I2C] Sample %u: Timeout error occurred\r\n", sample);
            break;
        case I2C_STS_ERR_NO_ACK:
            DebugP_logError("[I2C] Sample %u: No acknowledgement received\r\n", sample);
            break;
        case I2C_STS_ERR_ARBITRATION_LOST:
            DebugP_logError("[I2C] Sample %u: Arbitration lost\r\n", sample);
            break;
        case I2C_STS_ERR_ACCESS_ERROR:
            DebugP_logError("[I2C] Sample %u: Bus Access error occurred\r\n", sample);
            break;
    }

    return;
}

int api_i2c_reinit()
{
    I2C_Params      params;

    Drivers_i2cClose();
    I2C_deinit();
    ClockP_sleep(1);
    I2C_Params_init(&params);
    params.transferMode  = I2C_MODE_BLOCKING;
    params.bitRate = I2C_400KHZ;
    I2C_init();
    I2C_open(CONFIG_I2C0, &params);

    return 0;
}

Thanks!

Louis,