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

[Due] (I2C) Wire.endTransmission always returns non-zero. #1251

Closed
chriskner opened this Issue Jan 28, 2013 · 6 comments

Comments

@chriskner

chriskner commented Jan 28, 2013

1.5.1r2

It looks like endTransmission returns the number of bytes sent from the transmit buffer, not an indication of success, as http://arduino.cc/en/Reference/WireEndTransmission suggests.

from \arduino-1.5.1r2\hardware\arduino\sam\system\libsam\source\twi.c :

uint8_t TwoWire::endTransmission(uint8_t sendStop) {
    ...
    while (sent < txBufferLength) {
        ...
    }
    ...
    return sent;
}
@nathanhere

This comment has been minimized.

Show comment
Hide comment
@nathanhere

nathanhere Jan 31, 2013

I also just tested the return value of endTransmission, and it definitely has a bug. I tried sending 5 bytes over I2C, and it returned the number 5. This is only supposed to return a value of 0 - 4.

nathanhere commented Jan 31, 2013

I also just tested the return value of endTransmission, and it definitely has a bug. I tried sending 5 bytes over I2C, and it returned the number 5. This is only supposed to return a value of 0 - 4.

@lestofante

This comment has been minimized.

Show comment
Hide comment
@lestofante

lestofante Jan 31, 2013

The bug is in the lib or in the reference?
Il giorno 31/gen/2013 23:11, "Nathan" notifications@github.com ha scritto:

I also just tested the return value of endTransmission, and it definitely
has a bug. I tried sending 5 bytes over I2C, and it returned the number 5.
This is only supposed to return a value of 0 - 4.


Reply to this email directly or view it on GitHubhttps://github.com//issues/1251#issuecomment-12968881.

lestofante commented Jan 31, 2013

The bug is in the lib or in the reference?
Il giorno 31/gen/2013 23:11, "Nathan" notifications@github.com ha scritto:

I also just tested the return value of endTransmission, and it definitely
has a bug. I tried sending 5 bytes over I2C, and it returned the number 5.
This is only supposed to return a value of 0 - 4.


Reply to this email directly or view it on GitHubhttps://github.com//issues/1251#issuecomment-12968881.

@chriskner

This comment has been minimized.

Show comment
Hide comment
@chriskner

chriskner Jan 31, 2013

Unfortunately, the more you dig, the worse it gets.

It appears to me the devs at one point realized the work ahead of them was not trivial, and decided to supply a base-line functionality (below current standards). This is not a meant as a dig, just reality.

Any proc in the Wire library that accesses the I2C status register has been, or needs to be neutered (which is why I believe endTransmission got mangled in this version). Basically, any marginally serious I2C communication must bypass this version of the library, and twiddle the MCU registers directly.

Just scan the datasheet and look for bits that are "clear[ed] on read". This is totally not handled properly in 1.5.1r2.

chriskner commented Jan 31, 2013

Unfortunately, the more you dig, the worse it gets.

It appears to me the devs at one point realized the work ahead of them was not trivial, and decided to supply a base-line functionality (below current standards). This is not a meant as a dig, just reality.

Any proc in the Wire library that accesses the I2C status register has been, or needs to be neutered (which is why I believe endTransmission got mangled in this version). Basically, any marginally serious I2C communication must bypass this version of the library, and twiddle the MCU registers directly.

Just scan the datasheet and look for bits that are "clear[ed] on read". This is totally not handled properly in 1.5.1r2.

@chriskner chriskner closed this Jan 31, 2013

@chriskner chriskner reopened this Jan 31, 2013

@leszekru

This comment has been minimized.

Show comment
Hide comment
@leszekru

leszekru Apr 14, 2013

does not work in 1.5.2...
Is there a software i2c lib that works on Due???

leszekru commented Apr 14, 2013

does not work in 1.5.2...
Is there a software i2c lib that works on Due???

@zelfkoelman

This comment has been minimized.

Show comment
Hide comment
@zelfkoelman

zelfkoelman Oct 16, 2013

Any news on this topic? I'm totally stuck in getting a PCA9622 Led driver to work over i2c... The Arduino gets stuck in the endTransmission function.

zelfkoelman commented Oct 16, 2013

Any news on this topic? I'm totally stuck in getting a PCA9622 Led driver to work over i2c... The Arduino gets stuck in the endTransmission function.

@ffissore ffissore added the New label Feb 27, 2014

@cmaglie cmaglie removed the New label Feb 27, 2014

@sandeepmistry

This comment has been minimized.

Show comment
Hide comment
@sandeepmistry

sandeepmistry Oct 6, 2015

Member

The return code has been addressed by @bluesign2k's commit e079baa and is already in master.

Member

sandeepmistry commented Oct 6, 2015

The return code has been addressed by @bluesign2k's commit e079baa and is already in master.

@ffissore ffissore modified the milestone: Release 1.6.6 Oct 7, 2015

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment