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

I2C ReSTART returns Success #2141

Merged
merged 3 commits into from Dec 3, 2018
Merged

Conversation

stickbreaker
Copy link
Contributor

This change restores compatibility with preexisting Arduino libraries that use Wire(). The ReSTART queuing operation is now hidden. Wire.endTransmission(id,len,FALSE); now returns I2C_ERROR_OK(0) to indicate success, though, Wire.lastError() will correctly return I2C_ERROR_CONTINUE to indicate the last Wire() operation was added to the command queue, and not executed. Since Wire.lastError() does not exist in main branch Arduino, this dichotomy is not obvious.

The number of queued operation is limited by the depth of the Wire() Tx/Rx buffers, currently 128 bytes each. Each Wire.Write() operation uses one byte of the Tx buffer, Wire.requestFrom(id,LEN,false); uses LEN bytes of the 128byte Rx buffer. If either buffer is exhausted before a STOP condition is issued, I2C_ERROR_MEMORY will be returned.

ReSTART operations on the ESP32 have to be handled differently than on AVR chips, so ReSTART operations(`Wire.endTransmission(false), Wire.requestFrom(id,size,false);` are queued until a STOP is send (`Wire.endTransmission(TRUE), Wire.endTransmission(), Wire.requestFrom(id,size), Wire.requestFrom(id,size,TRUE)). To indicate the queuing I had used `I2C_ERROR_CONTINUE`, this caused compatibility issues with the existing Arduino I2C Code base. So, back to Lying to the public(for their own good of course) about success!  This update just returns `I2C_ERROR_OK` on ReSTART commands.
add comments
This change restores compatibility with pre-existing Arduino Libraries.  The ReSTART queuing operations are hidden behind the scenes.  Wire.endTransmission(id,len,FALSE); will know return I2C_ERROR_OK instead of I2C_ERROR_CONTINUE, Wire.lastError() will return the true condition of I2C_ERROR_CONTINUE.
@me-no-dev me-no-dev merged commit 7a33286 into espressif:master Dec 3, 2018
@me-no-dev me-no-dev deleted the patch-3 branch December 3, 2018 15:16
@digi-z
Copy link

digi-z commented Jan 30, 2019

Hello Stickbreaker
I use your wire.cpp and wire,h but get compilation erros for nodeMCU: i2cDebug and i2cGetStatus not declared. If I try to include esp32-hal-i2c.h I get faults that #includes are nested too deeply. How do I have to configure the libraries to be able to compile them?
Regards!

@stickbreaker
Copy link
Contributor Author

@digi-z If you are using V1.0.1, either from an Arduino Boards Manager install, or the Cloned Github repo, All you need to do is include the Wire.h library in your sketch:

#include <Wire.h>

void setup(){
Serial.begin(115200);
Wire.begin(); // default 100khz, SDA and SCL as defined in pins.h
}

void loop(){
// use it
}

Chuck.

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

Successfully merging this pull request may close these issues.

None yet

3 participants