Skip to content
This repository was archived by the owner on Sep 30, 2019. It is now read-only.

Commit b60b1da

Browse files
committed
Add require_repeated_start function to I2C as workaround for I2C issue on Raspberry Pi.
1 parent 38180a8 commit b60b1da

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

Adafruit_GPIO/I2C.py

+19-1
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
2020
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
2121
# THE SOFTWARE.
22-
2322
import logging
23+
import subprocess
2424

2525
import smbus
2626

@@ -65,6 +65,24 @@ def get_i2c_device(address, busnum=None, **kwargs):
6565
busnum = get_default_bus()
6666
return Device(address, busnum, **kwargs)
6767

68+
def require_repeated_start():
69+
"""Enable repeated start conditions for I2C register reads. This is the
70+
normal behavior for I2C, however on some platforms like the Raspberry Pi
71+
there are bugs which disable repeated starts unless explicitly enabled with
72+
this function. See this thread for more details:
73+
http://www.raspberrypi.org/forums/viewtopic.php?f=44&t=15840
74+
"""
75+
plat = Platform.platform_detect()
76+
if plat == Platform.RASPBERRY_PI:
77+
# On the Raspberry Pi there is a bug where register reads don't send a
78+
# repeated start condition like the kernel smbus I2C driver functions
79+
# define. As a workaround this bit in the BCM2708 driver sysfs tree can
80+
# be changed to enable I2C repeated starts.
81+
subprocess.check_call('chmod 666 /sys/module/i2c_bcm2708/parameters/combined', shell=True)
82+
subprocess.check_call('echo -n 1 > /sys/module/i2c_bcm2708/parameters/combined', shell=True)
83+
# Other platforms are a no-op because they (presumably) have the correct
84+
# behavior and send repeated starts.
85+
6886

6987
class Device(object):
7088
"""Class for communicating with an I2C device using the smbus library.

0 commit comments

Comments
 (0)