From c86df8e13eb52aea817c14221d0223fdb08bf8d1 Mon Sep 17 00:00:00 2001 From: whitequark Date: Mon, 19 Mar 2018 06:23:12 +0000 Subject: [PATCH] firmware: try to unstuck the I2C bus if it gets stuck. Fixes #957. --- artiq/firmware/libboard_artiq/i2c.rs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/artiq/firmware/libboard_artiq/i2c.rs b/artiq/firmware/libboard_artiq/i2c.rs index 819c21c1b..e46b3d0fd 100644 --- a/artiq/firmware/libboard_artiq/i2c.rs +++ b/artiq/firmware/libboard_artiq/i2c.rs @@ -59,7 +59,19 @@ mod imp { half_period(); half_period(); if !sda_i(busno) { - error!("SDA is stuck low on bus #{}", busno) + warn!("SDA is stuck low on bus #{}, trying to unstuck", busno); + + // Try toggling SCL a few times + for bit in 0..8 { + scl_o(busno, false); + half_period(); + scl_o(busno, true); + half_period(); + } + } + + if !sda_i(busno) { + error!("SDA is stuck low on bus #{} and doesn't get unstuck", busno); } } }