mirror of
https://github.com/elua/elua.git
synced 2025-01-08 20:56:17 +08:00
Implement STOP and repeated START condition setup times from I2C spec.
The code for the bitbanger, taken from wikipedia, in turn taken from http://www.nctutwt.net/wiki/doku.php?id=wiki:summer2010:i2c does a STOP condition by raising SCL and immediately raising SDA, but in the I2C spec, there is a minimum STOP setup time of 4ms between these transitions (I2C spec, doc UM10204, table 6/figure 27, pp.37-38). Similarly, a repeated START has a setup time of minimum 4.7us between SCL going high and SDA going low, which the code did not contain. This patch inserts these delays to conform better to the I2C spec, even though all tested devices "seemed to work" without them.
This commit is contained in:
parent
22f08c454d
commit
5d5443d67e
@ -214,7 +214,9 @@ void i2c_stop_cond(void)
|
||||
/* Clock stretching */
|
||||
while (READSCL() == 0)
|
||||
; /* You should add timeout to this loop */
|
||||
/* SCL is high, set SDA from 0 to 1 */
|
||||
/* SCL is high. Respect I2C spec's minimum stop setup time of 4ms. */
|
||||
I2CDELAY();
|
||||
/* set SDA from 0 to 1 */
|
||||
if (READSDA() == 0)
|
||||
ARBITRATION_LOST();
|
||||
I2CDELAY();
|
||||
|
Loading…
x
Reference in New Issue
Block a user