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

I2C getting struck and SDA stays low

We are using I2C bus for communication with a RTC and Accelerometer. But sometimes the I2C get struck in i2c_write. It does not happens always it may happen randomly. We are able to generate it in two ways:

1. Let the device run for some time and suddenly I2C will stop working

2. Other way we had tried is by resetting the MCU after few seconds of operation and  there will be a time when I2C will not work anymore.

Once the device is struck soft reboot, reset pin reboot and reprogramming does not helps in bringing it back.

We are able to recover it in two ways but does not always happens:

1. Power reboot the board

2. Touch the I2C test point with oscilloscope probes.

The firmware is based on SDK 1.2 and we also had same issue in SDK 1.1. The I2C clock speed is configured to 100Khz. 

Here is my code for I2C init

int i2c_init()
{
    int iError = 0;

    _sI2C2 = device_get_binding("I2C_2");

    if (!_sI2C2) 
    {
          print_error(TAG, "I2C Device driver not found.");
          return -ENODEV;
    }
      
    iError = i2c_configure(_sI2C2, I2C_SPEED_SET(I2C_SPEED_STANDARD));

    if(iError == 0) 
       print_info(TAG, "I2C Device configure sucess");
    else
       print_error(TAG, "I2C Device speed configure fail");


    return iError;
    
}

This is settings in prj.conf

#I2C
CONFIG_I2C=y
CONFIG_I2C_NRFX=y
CONFIG_I2C_2=y
CONFIG_I2C_2_NRF_TWIM=y

and this is in .dts

&i2c2 {
	compatible = "nordic,nrf-twim";
	status = "okay";
	sda-pin = <12>;
	scl-pin = <11>;
};

Parents Reply Children
No Data
Related