This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

I2C communication error

Hello, support team.

In my test board, lis3mdl chip is connected to nordic chip via I2C.

During initializing board, device ID of lis3mdl is checked.

Most of time it works fine. And sensor data is read correctly.

But time to time, I can't get device ID from lis3mdl.

After several times of power reset, It works again.

I don't have any idea for this phenomenon.

Could you suggest me any clue?

Parents Reply Children
  • Hello,

    I2C clock signal is checked with oscilloscope.

    When normal operation, clock signal is occurs cyclically.

    But when error occurs, there is no clock signal.

    - CLK when normal operation

    - CLK when error occurs

    In my source code, I made it to re-try to read sensor ID if response is incorrect.

    Should I do something else like reset sensor or reset I2C bus?

        /* read sensor id via I2C */
        lis3mdl_device_id_get(&lis_ctx, &whoamI);
        
        /* If incorrectly work, re-try */
        while (whoamI != LIS3MDL_ID)
        {   
            nrf_delay_ms(50);
            lis3mdl_device_id_get(&lis_ctx, &whoamI);
        }

    And error_code 3 is returned from nrf_drv_twi_xfer function.

    I can't debug deeper.

  • Which SDK version are you using? There are some fixes related to TWIM in the later releases. If you are not using the latest, I would recommend you to try to update.

    Can you post the code inside lis3mdl_device_id_get? Unless you have initialized the driver in blocking mode, it is a better approach to wait for events indicating that a transfer completed, rather than using a delay.

Related