Skip to content

Commit 799c2c7

Browse files
committedMar 23, 2016
runtime/i2c: more conservative timings
1 parent 2bb4ad1 commit 799c2c7

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed
 

‎artiq/runtime/i2c.c

+4-1
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ int i2c_write(int busno, int b)
139139
for(i=7;i>=0;i--) {
140140
/* Set SCL low and set our bit on SDA */
141141
i2c_scl_o(busno, 0);
142+
i2c_halfperiod(); /* make sure SCL has settled low */
142143
i2c_sda_oe(busno, b & (1 << i) ? 0 : 1);
143144
i2c_halfperiod();
144145
/* Set SCL high ; data is shifted on the rising edge of SCL */
@@ -148,8 +149,9 @@ int i2c_write(int busno, int b)
148149
/* Check ack */
149150
/* Set SCL low, then release SDA so that the I2C target can respond */
150151
i2c_scl_o(busno, 0);
151-
i2c_halfperiod();
152+
i2c_halfperiod(); /* make sure SCL has settled low */
152153
i2c_sda_oe(busno, 0);
154+
i2c_halfperiod();
153155
/* Set SCL high and check for ack */
154156
i2c_scl_o(busno, 1);
155157
i2c_halfperiod();
@@ -182,6 +184,7 @@ int i2c_read(int busno, int ack)
182184
/* Send ack */
183185
/* Set SCL low and pull SDA low when acking */
184186
i2c_scl_o(busno, 0);
187+
i2c_halfperiod(); /* make sure SCL has settled low */
185188
if(ack)
186189
i2c_sda_oe(busno, 1);
187190
i2c_halfperiod();

0 commit comments

Comments
 (0)