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

Bug in Wire process() #100

Closed
rogerclarkmelbourne opened this issue Nov 10, 2014 · 1 comment
Closed

Bug in Wire process() #100

rogerclarkmelbourne opened this issue Nov 10, 2014 · 1 comment

Comments

@rogerclarkmelbourne
Copy link

Hi,
There is almost certainly a bug in Wire::process(), which occurs when you attempt to address a device that is not connected (and may occur under other circumstances)

What happens is that in i2c_get_ack, SCL is left low at the end of the function (see below)

bool TwoWire::i2c_get_ack() {
set_scl(LOW);
set_sda(HIGH);
set_scl(HIGH);
bool ret = !digitalRead(this->sda_pin);
set_scl(LOW);
return ret;
}

And in process() the function returns if there has not been an ACT (this happens in 2 places in process()

if (!i2c_get_ack()) {
return ENACKADDR;
}

Then when the next call to process() occurs (via Wire::endTransmission() ) SCL is low when it should be high, and the first clock falling edge, doesn't occur, hence only 6 address bits and the RW flag are clocked out.

So once there has been an error where ACK has not been received.

Wire totally breaks and never recovers.

The simple solution appears to be to Set SCL HIGH before exiting if there has been a failure to get an ACT

e.g.

if (!i2c_get_ack()) {
set_scl(HIGH);// Set SCL high ready for next transfer
return ENACKADDR;
}

This needs to happen in both locations.

On another associated note.

Please can someone tell me if this version of Wire is the latest version, as I've noticed its dated 2012, however on the LeafLabs server http://static.leaflabs.com/pub/leaflabs/maple-ide/
The latest IDE is dated 2013, but contains a completely different implementation of Wire

So either this Repo has not been updated with the latest wire from the static copy of IDE or vice versa

@mbolivar
Copy link
Contributor

Hi,

I pushed 40bffe3, which should fix the issue. Please let me know if it works for you.

Regarding dates, the later IDE version was just to fix up some Windows issues; the version of Wire it contains is older than this one in libmaple.

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