Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wire.setClock() keeps SCL low with 800kHz #107

Open
Koepel opened this issue Aug 8, 2021 · 1 comment
Open

Wire.setClock() keeps SCL low with 800kHz #107

Koepel opened this issue Aug 8, 2021 · 1 comment

Comments

@Koepel
Copy link

Koepel commented Aug 8, 2021

The default 100 kHz works, and the Wire.setClock(100000L) works.
If the clock is set to 800 kHz or above, then the SCL signal stays low because of a missing stop condition.
The I2C speed for normal signals should be from 100kHz to 400kHz, but someone might try 800kHz.

Tested with Arduino IDE 1.8.15 and Nano Every board. Nothing is connected to the I2C bus.
Test sketch:

#include <Wire.h>

void setup()
{
  Wire.begin();
  Wire.setClock( 100000L);
}

void loop()
{
  Wire.beginTransmission( 0x2B);
  Wire.endTransmission();

  delay( 100);
}

Result with a sample rate of 24 MHz with LHT00SU1 and PulseView/sigrok).
The measured frequency of SCL varies a few percentage. It is 99 kHz with no pullup resistors here:
100

With Wire.setClock(400000L); the measured frequency of SCL is 303 kHz with no pullup resistors:
400

With Wire.setClock(800000L); the SCL signal stays low. There is no stop condition. The SCL raises before the next start condition. The measured frequency of SCL is 525 kHz with no pullup resistors.
800wide

[Update] I have edited this Issue because I learned that not the clock speed of SCL is set, but that the resulting clock speed is relative to the rise time.

@Koepel Koepel changed the title Wire.setClock() keeps SCL low with 800kHz and 400kHz turns into 300kHz. Wire.setClock() keeps SCL low with 800kHz Aug 9, 2021
@softhack007
Copy link

softhack007 commented Dec 4, 2021

Just looked into DxCore, and saw that two things are done differently:

  • TWI baud rate calculation has an offset that depends on CPU speed
  • setting of a register bit "FMPEN" for TWI speed above 600KHz

Would this also help in megaavr core?

https://github.com/SpenceKonde/DxCore/blob/f49e0d61e066b4c9d606a5f8297da90574c93012/megaavr/libraries/Wire/src/twi.c#L230-L234

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants