GrumpyOldPizza / ArduinoCore-stm32l0

Arduino Core for STM32L0
125 stars 67 forks source link

I2C clock stretching or associated issue with SCD30 sensor #94

Open SloMusti opened 4 years ago

SloMusti commented 4 years ago

I have been testing the SCD30 sensor(https://www.sensirion.com/en/environmental-sensors/carbon-dioxide-sensors-co2/) with https://github.com/sparkfun/SparkFun_SCD30_Arduino_Library library and the sensor does not work with this core. What occurs is that the measurement start commands do not get recognized and the sensor does not start measuring.

Minor modifications for this library to work with the core: https://github.com/sparkfun/SparkFun_SCD30_Arduino_Library/blob/master/src/SparkFun_SCD30_Arduino_Library.cpp#L43 adding _i2cPort->setClockLowTimeout(250); to enable clock stretching correctly

Same library works well on ESP32 and other boards used for testing.

Issue breakdown: Communication seems to work with the decoder as all writes get acknowledged and the protocol decoder will give the identical printout, however we can see two key differences in the logical levels of SDA and SCL.

Possible causes of this issue:

working_scd30_esp32_clock-stretch working_scd30_esp32_clock-stretch working_scd30_esp32_sda_released_stratching working_scd30_esp32_sda_released_stratching not-working_scd30_stm32l0_no_stretch_at_end not-working_scd30_stm32l0_no_stretch_at_end not-working_stm32l0_no_sda_release not-working_stm32l0_no_sda_release

@GrumpyOldPizza any thoughts?

GrumpyOldPizza commented 4 years ago

Interesting. The Wire.setClockLowTimeout(250) command actually just enables the timeout to abort a transfer if the slave stretched SCL for too long. Per default (and I2C spec) this timeout is disabled.

Which of the images is "good" and which one is "bad" ?

SloMusti commented 4 years ago

@GrumpyOldPizza updated the post with description of images, my bad as they were only specified in filenames. Should be clear now.

Abort does not seem to happen here, more like that the clock stretching is ignored.