Skip to content

Commit

Permalink
I2C clock phase correction in START condition (#8383)
Browse files Browse the repository at this point in the history
* A clock phase correction in write_start(void)

Some devices require the data wire SDA to be held down at the moment while the clock wire is pulled down too to execute the start condition (e.g. devices using "TinyWires.h" library). This change follows a behaviour of Arduino Wire.h library, where the SCL signal is pulled down in half of period of start condition.

* Formatting of modification restyled

* Removing mathematical operations from delay

* Comments added
  • Loading branch information
xpalaa00 committed Nov 28, 2021
1 parent 076a4ed commit d5444c4
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions cores/esp8266/core_esp8266_si2c.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -247,8 +247,12 @@ bool Twi::write_start(void)
return false;
}
busywait(twi_dcount);
// A high-to-low transition on the SDA line while the SCL is high defines a START condition.
SDA_LOW(twi_sda);
busywait(twi_dcount);
// An additional delay between the SCL line high-to-low transition and setting up the SDA line to prevent a STOP condition execute.
SCL_LOW(twi_scl);
busywait(twi_dcount);
return true;
}

Expand All @@ -260,6 +264,7 @@ bool Twi::write_stop(void)
SCL_HIGH(twi_scl);
WAIT_CLOCK_STRETCH();
busywait(twi_dcount);
// A low-to-high transition on the SDA line while the SCL is high defines a STOP condition.
SDA_HIGH(twi_sda);
busywait(twi_dcount);
return true;
Expand Down

0 comments on commit d5444c4

Please sign in to comment.