J784S4XEVM: I2C in vision_apps

Part Number: J784S4XEVM

Tool/software:

Hello TI,

After writing simple bare metal app for reading temperature sensor values over I2C (csl example), I tried using the same code in vision app but I get error "core aborted" on I2C_open function call.

I'm calling I2C_open from our custom app which is similar to app_c7x_kernel app except that we use our custom kernel for r5f on MCU2_0.
We are using Linux + RTOS SDK version v10 on J784S4 EVM board.

vx_status VX_CALLBACK app_r5f_target_kernel_bringup_create(tivx_target_kernel_instance kernel, tivx_obj_desc_t *param_obj_desc[], uint16_t num_params, void *priv_arg)
{
    printf("\n%s -13- %d\n", __FUNCTION__, __LINE__);

    I2C_Params i2c_params;
    I2C_Params_init(&i2c_params);
    i2c_params.bitRate = I2C_400kHz; /* 400KHz */

    // Open the I2C instance (instance 0)
    if (i2c_handle == NULL)
    {
        i2c_handle = I2C_open(BOARD_TEMP_SENSOR_I2C_INSTANCE, &i2c_params);
        printf("\n%s %d i2c_handle = %p\n", __FUNCTION__, __LINE__, i2c_handle);
    }
    
    return VX_SUCCESS;
}


What am I missing here?

Best Regards,

Milos

  • Hi Milos,

    Here are a few queries to understand your issue:

    - Can you tell us what line in I2C_Open is getting into "core aborted"? 
    - What core are you using to run your I2C code? Is it on R5F - Main MCU2_0?
    - Which instance of I2C is used? Have you "turned on" the clock and the specific I2C instance?

    Thanks.

  • Hi Praveen,

    - I traced the code execution to the beginning of I2C_open_v1 function, but didn't go further because it seemed that I'm doing something basic wrong and that the problem likely isn't in I2C API itself but in the way I use it.

    - Yes, I'm using Main MCU2_0 core.

    - I'm trying to use BOARD_TEMP_SENSOR_I2C_INSTANCE (instance 0). From what I saw in other vision app (app_dss_soc.c), there I2C_open is called without any prior clock enable procedure.

  • I traced the code execution to the beginning of I2C_open_v1 function, but didn't go further because it seemed that I'm doing something basic wrong and that the problem likely isn't in I2C API itself but in the way I use it.

    Suggest checking at what point you see the crash so we can help you further. Please ensure you have enabled the clock and the I2C device before you call I2C_open. Also, ensure that Linux running on A72 does not use this I2C instance since it may conflict with mcu2_0 usage of this. 

    - I'm trying to use BOARD_TEMP_SENSOR_I2C_INSTANCE (instance 0). From what I saw in other vision app (app_dss_soc.c), there I2C_open is called without any prior clock enable procedure.

    Can you tell us what code is being referred to here? 

    Thanks.

  • Ok, I added a clock enable part and now I2C_open returns what seems to be a valid handle. Here's how the code looks like at the moment:

    vx_status VX_CALLBACK app_r5f_target_kernel_bringup_create(tivx_target_kernel_instance kernel, tivx_obj_desc_t *param_obj_desc[], uint16_t num_params, void *priv_arg)
    {
        printf("\n%s -13- %d\n", __FUNCTION__, __LINE__);
    
        Board_initCfg boardCfg;
        Board_STATUS  boardStatus;
    
        boardCfg = BOARD_INIT_MODULE_CLOCK |
                   BOARD_INIT_PINMUX_CONFIG |
                   BOARD_INIT_UNLOCK_MMR |
                   BOARD_DEINIT_LOCK_MMR;
    
        boardStatus = Board_init(boardCfg);
        if (boardStatus != BOARD_SOK)
        {
            printf("\n[Error] Board init failed!!\n");
        }
    
        I2C_Params i2c_params;
        I2C_Params_init(&i2c_params);
        i2c_params.bitRate = I2C_400kHz; /* 400KHz */
    
        // Open the I2C instance (instance 0)
        if (i2c_handle == NULL)
        {
            i2c_handle = I2C_open(BOARD_TEMP_SENSOR_I2C_INSTANCE, &i2c_params);
            printf("\n%s %d i2c_handle = %p\n", __FUNCTION__, __LINE__, i2c_handle);
        }
    
        // Configure temp sensor
        uint8_t data_to_write = 0xE0;
        uint8_t temp_sensor = BOARD_TEMP_SENSOR_I2C_SLAVE_DEVICE2_ADDR; // 0x49
        Board_STATUS status = Board_i2c8BitRegWr(i2c_handle, temp_sensor, 0x01, &data_to_write, 1, BOARD_I2C_TRANSACTION_TIMEOUT);
    
        if (status == BOARD_SOK)
        {
            printf("\n%s %d I2C write 1 successful\n", __FUNCTION__, __LINE__);
        }
        else
        {
            printf("\n%s %d I2C write 1 failed\n", __FUNCTION__, __LINE__);
        }
        
        return VX_SUCCESS;
    }


    However, call to Board_i2c8BitRegWr fails. I checked the return value of I2C_Transfer function call inside Board_i2c8BitRegWr and it's -3 (I2C_STS_ERR_NO_ACK).

  • Thanks for the details. Let me redirect this query to the PDK expert to comment.

  • Hi Milos,

    Are you able to tell where the NACK error code is returned?

    Is the initial read successful?

    Thanks,

    Neehar

  • Hi Neehar,
    It seems that NACK error flag is set inside I2C_v1_hwiFxnMaster interrupt handler. We use the same physical pin connections that we used when testing I2C communication from csl application and there it was working.
    No, neither writes nor reads work.

  • Any updates on this issue?