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

Incorrect order of operations? #35

Open
mbenkmann opened this issue Jun 2, 2021 · 2 comments
Open

Incorrect order of operations? #35

mbenkmann opened this issue Jun 2, 2021 · 2 comments

Comments

@mbenkmann
Copy link

In void i2c_t3::resetBus_(struct i2cStruct* i2c, uint8_t bus) I see this:

digitalWrite(scl,HIGH);
pinMode(scl,OUTPUT);

Shouldn't these 2 lines be swapped?

@tonton81
Copy link

tonton81 commented Jun 2, 2021

on Teensy 3 at least, you can set it high before or after OUTPUT, because if they do it the other way around it will be LOW by default and affect something on the bus while switching back to HIGH from LOW :)

@nox771
Copy link
Owner

nox771 commented Jun 3, 2021

Previous comment is correct. The SCL/SDA buses operate with passive pullups. So if they are not being driven low they will be at high voltage. When using the I2C peripheral we cannot control the state of the lines directly (the peripheral controls it), but the assumption is that it is logic high (SCL/SDA are high between I2C sequences).

So to transfer control to direct control (away from the peripheral), as used in resetBus(), the SCL is preset high before enabling as an output. That is to prevent a driven-low glitch if it is done the other way around. If this manifested as just another clock it would not be such a big deal (resetBus is outputting clocks anyway), but the timing of that glitch low period would be uncontrolled, which could cause a problem in itself.

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

3 participants