Schorschi
Posts: 354
Joined: Thu Nov 22, 2012 9:38 pm

Reset i2c bus?

Mon Jan 21, 2019 12:20 am

I have found that once in a while the i2c bus goes blind, or at least the master device, reports no devices found. Whereas a simple reboot clears the i2c bus, and devices appear once again. Reading various sources via Google I came across two ideas to avoid a reboot to clear the i2c bus. Each is summarized below. But I wonder if either or both are valid, and if one or both is valid, which method is better?

1) Set the GPIO pin for SCL (clock line) of the i2c interface high then low, 9 times, with the GPIO frequency at 400 KHz. This seems possible, if you force the GPIO frequency from 100 to 400. To get the GPIO speed to 400 KHz, this requires a reboot, so it defeats the purpose, doing a i2c reset without a reboot.

2) Invoke the unbind and bind functions that exist in the i2c interface via the kernel driver on the Pi. I think the way to do this is as follows, but this idea was gleaned from other documentation of other devices, so I am not sure it is legit at all.

# echo '3f804000.i2c' > /sys/bus/platform/drivers/i2c-bcm2835/unbind
# echo '3f804000.i2c' > /sys/bus/platform/drivers/i2c-bcm2835/bind

The above seems to work by closing the communication with the i2c device bus, i.e. when I unbind, i2cdetect -y 1 returns a device not found error, i.e. no such file or directory. When I bind, the i2cdetect -y 1 returns the bus information as expected. But is this a reset condition because communication was lost? I suspect any slave device that has hung the bus, would still be doing so?

Any suggestions or thoughts welcome.

swahren
Posts: 172
Joined: Mon Sep 19, 2016 5:24 pm
Location: Germany

Re: Reset i2c bus?

Sat Jan 26, 2019 1:10 pm

Method 1 is called I2C recovery in the Linux kernel. Unfortunately the i2c driver for bcm2835 doesn't implement this feature yet.

https://www.kernel.org/doc/html/v4.19/d ... overy_info

Return to “Advanced users”