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

Scanner accesses 'reserved' I2C addresses #2

Open
Tech-TX opened this issue Sep 27, 2019 · 1 comment
Open

Scanner accesses 'reserved' I2C addresses #2

Tech-TX opened this issue Sep 27, 2019 · 1 comment

Comments

@Tech-TX
Copy link

Tech-TX commented Sep 27, 2019

All the way back to rev 2.0 of the spec, up to current rev 6:
https://www.nxp.com/docs/en/user-guide/UM10204.pdf page 17, 3.1.12 Reserved addresses,
the bottom 8 and top 8 addresses are reserved for special purposes. Following that, line 31 is:

	  for (address = 8; address < 120; address++ )

If you do that, you might be able to remove that unusual Wire.endTransmission(); at line 29. I couldn't see a reason for it, and commented it out in the file I downloaded. I'd presumed it was a hack for something weird you saw, and banging reserved addresses might cause weird operation with some slaves.

Additionally, for more reliable operation with slow slaves on the ESP8266 using the software wire library, I'd add Wire.setClockStretchLimit(500); or higher just after the Wire.begin(); as the default stretch limit is ridiculously short (230uS). I've seen people pushing that up to 1500us for some parts due to the non-static nature of the 8266 wire library. The ESP32 has a different library with a much longer timeout, so it doesn't need this. I've set my code to 1500us default clock stretch limit until I get hold of a fully-static 8266 library done more like the Arduino library.

Just after Wire.begin(); add

#ifdef ESP8266
Wire.setClockStretchLimit(500);  //may need to increase this to 1500us for slow parts
#endif

Other than that, I've been enjoying your scanner. Thanks! :-)

@Tech-TX
Copy link
Author

Tech-TX commented Oct 13, 2019

Update: I found why you'd added that extra Wire.endTransmission(); at the top of the loop. The Wire.endTransmission(); at line 101 is being immediately followed by Wire.requestFrom(address, 1); at line 102, and it's occurring less than 1 clock afterwards and locking the bus low, depending on the Wire library used. Add delayMicroseconds(20); after the Wire.endTransmission(); at line 101 and you don't need that extra endTransmission at the top of the loop.

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

1 participant