Comments (7)
Can you please attach your code? What's the size of the pullup resistor you used?
from brzo_i2c.
Here's the code and the scope trace. The pull-up was 10k in this particular test, but I also tried others and you can see on the scope that it's adequate for the very low speed used. The slave device is BPS120, which only supports a 2-byte read. The same hardware works fine with the Wire library (otherwise I'd probably have never found the problem).
When you switch from Wire to BRZO, the first BRZO read() goes through but messes up the STOP in the end. Then the next read() fails with NACK of slave address, and it again messes up the STOP, so the next read after that also fails, etc. If you then switch back to Wire, or do ACK polling in BRZO, the first operation might fail, but it will have a correct STOP at the end and the slave will recover.
What you see in the scope pic is the repeated fail with NACK of slave address. The black trace is SCL, the green is SDA, the upper graticule is zoom-in on the last SCL falling edge. You can see that SDA falls just ever so slightly ahead of SCL, which is a no-no. When I reordered the instructions in the assembly, it fixed the problem.
from brzo_i2c.
When I designed the library, I've tested it mainly with 160 MHz CPU clock speed if I2C timings specifications are met, cf. pages 48—50 from "UM10204, I2C-bus specification from NXP".
Could you tell me what is the scale in the zoom in part of your scope trace, i.e. the dots? So that I can roughly check the time tHD;STA? (And having a look at the other specs as well).
For a START
condition tHD;STA should be minimal 4.0, 0.6, 0.26 usec for Standard-, Fast- and Fast-mode Plus accordingly. Since you did your testing in Standard-mode, i.e. with 100 KHz, it should be greater than 4.0 usec to be harmful.
from brzo_i2c.
The scale in the upper graticule is 400ns/div (it's shown there near the bottom). So the time from SDA fall to SCL fall is ~50ns. If we really wanted a reliable START condition that all compliant slaves would recognize, it wouldn't be nearly enough. But UM10204 also says in section 3.1.3, "The data on the SDA line must be stable during the HIGH period of the clock". So my understanding is, a change in SDA while SCL is high, unless it is a properly timed START or STOP, is a violation of 3.1.3. Some slaves may be robust to this violation, but BPS120 apparently is not.
BTW my CPU runs at 80MHz. If you run at 160MHz, time from SDA fall to SCL fall may be less than 50ns. But it's still a violation of 3.1.3 to drop SDA before SCL.
from brzo_i2c.
I could optimize it by setting SDA and SCL within one instruction, then it is the best :-)
from brzo_i2c.
I think all you need to do for this particular issue is swap lines 706 and 710, to set SCL LOW before updating SDA. That's what I did. It is legal to change SDA while SCL is LOW. Whereas if you update both with one instruction, there's still no guarantee which will happen first.
(I also considered adding an SDA hold time (i.e., a tiny delay after SCL LOW and before SDA update), just to make everything more robust. But other places in the code don't have an SDA hold, the standard doesn't seem to require it, and anyway there's already a 40ns hold just from using two instructions and a MEMW in between, so I didn't.)
from brzo_i2c.
Or, combine the two bitmasks and do it one S16I
... let's see...
from brzo_i2c.
Related Issues (20)
- I2C stucks after clock stretching time exceeds HOT 25
- Question: Logic Levels and ... HOT 2
- Cannot compile for Heltec Wifi Kit 32 HOT 3
- INA219 HOT 8
- Multiple I2C HOT 2
- gpio_init() will cause I2C bus busy (code: 1) HOT 5
- Migrating ADS1015 from Wire HOT 5
- AM2320 sensor not found HOT 11
- I2C bus handle for multiple instances posibility HOT 1
- Support speeds < 100KHz HOT 2
- after 1 slave fails others stop working HOT 4
- Have you thought about a i2c slave implementation. HOT 2
- Novice obsession HOT 2
- GCC 10 compilation issue with Arduino HOT 5
- MEMW not always present
- Clock stretch logic
- Arduino IDE compile error with new ESP8266 core 3.0.0 HOT 30
- SCL cock stretching HOT 3
- Platformio installation instructions confusing
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from brzo_i2c.