Skip to content

Commit 4465231

Browse files
authored
Merge pull request #2 from paulvha/master
added clockstretch support for ESP8266 board
2 parents 61115eb + 7004555 commit 4465231

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

src/SparkFun_SCD30_Arduino_Library.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,23 @@ boolean SCD30::begin(TwoWire &wirePort)
4040
//We expect caller to begin their I2C port, with the speed of their choice external to the library
4141
//But if they forget, we start the hardware here.
4242
_i2cPort->begin();
43+
44+
/* Especially during obtaining the ACK BIT after a byte sent the SCD30 is using clock stretching (but NOT only there)!
45+
* The need for clock stretching is described in the Sensirion_CO2_Sensors_SCD30_Interface_Description.pdf
46+
*
47+
* The default clock stretch (maximum wait time) on the ESP8266-library (2.4.2) is 230us which is set during _i2cPort->begin();
48+
* In the current implementation of the ESP8266 I2C driver there is NO error message when this time expired, while
49+
* the clock stretch is still happening, causing uncontrolled behaviour of the hardware combination.
50+
*
51+
* To set ClockStretchlimit() a check for ESP8266 boards has been added in the driver.
52+
*
53+
* With setting to 20000, we set a max timeout of 20mS (> 20x the maximum measured) basically disabling the time-out
54+
* and now wait for clock stretch to be controlled by the client.
55+
*/
56+
57+
#if defined(ARDUINO_ARCH_ESP32) || defined(ARDUINO_ARCH_ESP8266)
58+
_i2cPort->setClockStretchLimit(200000);
59+
#endif
4360

4461
//Check for device to respond correctly
4562
if(beginMeasuring() == true) //Start continuous measurements

0 commit comments

Comments
 (0)