I2C design constraints

A brilliant find!

1 Like

Hi Guys
I have been having some thoughts on this I2C business.
As I see it the operation is much like the following sketch. The IO of both master and slave is basically open collector (or drain) requiring pull ups


At least 1 pull up is required on each line (SCL and SDA). If several slaves are fitted there may be more.

Of concern is too much rounding of positive going transitions. This will be caused by capacitance in the position shown. Too much C or too large a pull up takes longer to charge and realise the full Vcc.

This capacitance is the real bogey man. Could be made up of fitted caps (there should be NONE in this position) and stray C of which there could be quite a bit. Can be in any position with the same result.

A lot of this stray will be in the cable used. It is this which I believe would be the single element that will restrict cable length used. A low capacitance cable will limit this. Adding more pull up resistors to get a “stronger” pull up will decrease this cap charging time thus squaring up and apparently “cleaning up” the pulses. It will also increase the required “sink” current and would have to be a compromise or a happy balance between acceptable current and waveform shape.

I think the object here if the cable length is getting a bit long (more than about 300mm or so) stray cap has to be kept to a minimum. Using low cap cable is one way to do this.

Be careful if logic level converters are needed as these (the simple cheap bi directional ones anyway) have a resistor on both the high V and low V sides which will become pull ups for the respective lines so when they are switched you have 2 more resistors in the collector circuit to consider when estimating sink current.

I think I am correct with the preceding statements. If I am wrong feel free to correct and point out mistakes.
Cheers Bob
Be a bit careful when using breadboards. They have stray capacitance everywhere. I once had an astable 555 circuit running quite happily with NO timing capacitor fitted. Operating quite OK with stray cap as the timer.

1 Like

Trevor, I just relised, in this thread I have not posted any of my own images, rather I posted one of the other images where I marked up some things of interest.

In my setup, its way worse then that, but still fine for my use case.
I have the same shark-fin signal and other things that look really bad in quick test I did last night, but as I said, it still works. In theory the protocol should be fairly robust, as its should be wait for clock to go high, sample data, so as long as the data is at the correct level when the clock goes high, it should be ok.

What would be good to see is the the bus at each end (master and failing slave) when it fails. If you only have a 2 channel scope, then one sample where you have the clock at each and, then a 2nd sample with the data at each end.
What I am looking for is to see if and how the signal is changed. over the lines.

1 Like

Ah.. I see. I didn’t look back far enough - I now see the lovely square clock pulses were from Gerard’s early post with 300R pullups.

I am in the middle of redesigning a PCB for my own project… I might knock up a 2nd prototype on breadboard and insert some 300R pullups… see if I get a similar results.

I confess the finer points of circuit theory on this are a bit above my pay grade…I’m more a programmer than electronics dude, so I don’t know if my reference to using coax earlier is misguided. Did you look at the Element14 Youtube clip? I think they went nearly 4 meters without a signal booster, at reasonable high Hz. (I better go watch it again…)

Still, I guess the core issue is why Gerard sees such a catastrophic failure on adding a 3rd device. On my bench I have crappy wiring, 5x I2C devices… and things work at 400k. It would not surprise me if other makers have 5 (or more) I2C devices. The traces I posted are from this prototype. There are 4K7 pullups on-board the PiicoDev Dev platform thing… plus something (Bob thinks 10K) on a Waveshare 1602 display.

Maybe we should run a poll/competiton… who’s got the most devices working happily :wink:

Cheers, T.

Edit: I was wrong about the 4 meter thing… the test @ Element14, between two Pico’s, ran @ 100kHz, over 10 meters! Downside is, you need two RG58 cables, SDA and SCL. That’s not nice…

1 Like

Hi Trevor,

I used the 300R as an extreme to get to a base point and then work back from there. 300R is about 10mA and the ESP32 GPIO can sink ~28mA so it shouldn’t hurt.

Earlier, Bob suggested that it might be getting to a ‘tipping point’ and I suspect he’s correct. Adding those extra Adafruit devices may just tip the whole thing over the edge.

When I look at my very neat traces on my PCB, I can see SCL and SDA running parallel across the PCB but, even more to the point, the traces running vertically down to the I2C connections at the bottom of the PCB also have SCL & SDA at 5v so I would not be surprised if cross talk is an issue.

1 Like

In my opinion, when dealing with things like i2c (a data bus), then the homework (reading datasheets and collecting the needed data) for every device you plan to use is key.
e.g. lets say 3 of the 4 nodes can sink 5ma, then the strongest pull up on a 3.3V bus would be V/I = R => 3.3/0.005 = 660 ohms (over all pull ups)
But if you then have 1 node that can only deal with 1mA sink then you need to design to that… 3.3/0.001 = 3300 ohms.
Now what happens if you have some 5V on the same base or what happens of 3.3K is too weak for the speed you want to run it at…
At some point you may need to have more then one bus.

Also when reading peoples comments, then see if their setup applies to yours. This is one of the key reasons people here try to get as much information about your project as they can. e.g. (made up example) billy bob might have 10 I2C devices working perfect on a 20 long run end to end with each device at 2m apart. So you think “I only have 3 over 1 meter it should work!”. Sounds logical. But Billy Bob’s devices may be able to sink 30mA, so he put in a very strong pull ups; but you cant do that as your devices may not handle that.

3 Likes

The OP has a “bus connection” which has relatively short length (~100mm?) then a run of ~1m to 5 or so I2C devices? Not sure if all were moisture sensors (not enough addresses - only 4 supported with 2 address lines).

The SAMD11’s I2C that the Moisture Sensors use can sink 3mA @ 100Khz and that’s why I tested with 1k resistors.

Have I got this correct?

Billy Bob :wink:

Edit> What devices is the @Gerard163258 using? I mistakenly referenced another commenter’s post where they were using Adafruit Moisture sensors.

2 Likes

Hi Michael
You might like to add that even though a device (pico or whatever) might specify Xma per GPIO but will also specify YmA over the whole device. For instance one device that came up recently I think (from memory here) that X is 12mA but Y is only 50mA so if you are pushing GPIO to the limit your max would be 4 GPIO. All this has to be considered. Allowing plenty of headroom for everything is my philosophy so possible additions don’t cause any bother.

As I mentioned about the Camel earlier this is where Gerard could be falling over. Only considering one thing, in this case I2C, could be where it all falls apart.
Cheers Bob
Edit: Reading Gerard’s last post I think he realises this.

2 Likes

Hi Gerard

The capacitance between tracks on the board would be very tiny as they are very thin and it is adjacent cross section area that determines this. There might be a tiny bit in the connector but I think most in the cabling. You are always going to get a bit of cross talk in this sort of installation, there is no getting away from that. But I am not convinced that what you see is going to be a problem. I don’t know how much I2C can tolerate. They may not matter much as they will occur when transitions are taking place, NOT where the data is being actually read. More importantly stray capacitance to ground which has to be charged during the positive going transition. Check this link for a better description of this.
https://www.allaboutcircuits.com/tools/resistor-capacitor-time-constant-calculator/
If the pulse has not reached the required value to initiate a read you might miss a read or get an incorrect one which probably give errors. Don’t know, not up on this bit.

I still don’t think this would cause the effect you describe. Still think power oscillating (rapidly failing and recovering) is your problem.
Cheers Bob

Add On
Gerard, I just went back and had a look at your earlier oscilloscope screen shots. In particular post 29, The shot prior to the 300Ω pull up.
I don’t think you have much of a stray C problem here. The positive going transitions look pretty good, very little rounding. The one with 300Ω pull up just confirms my earlier statements about the lower value pull up shorten the charging time constant and negate the stray C to an extent. But I reckon 300Ω is far too low f0r the GPIO and should not be considered. You have some headroom here as the 300Ω pull ups produce a very good transient response but as I say is too low.

1 Like

Hi Trevor
I just had a look at that Element 14 video. I was a bit disappointed actually. I thought Element 14 would do better than that. All it showed is that the little set up worked. It would have been nice to see what the signals looked like on the 2 lines in question.

What they showed was using a known amount of stray capacitance in a controlled situation, bottled up in the form of RG 58 Co-ax. With the short connection between boards they could have just as well connected a known capacitor from each line to ground. The RG 58 characteristics are known and can be pretty much relied on.

From Element 14 we could assume quality cable.
The specs for Belden RG 58 say capacitance 24.3pF / foot = very close to 800pF / 10 Metre
Time constant for 10kΩ (62% of applied voltage) would be about 8µSec
More detail here. Suggest you read.
https://www.allaboutcircuits.com/tools/resistor-capacitor-time-constant-calculator/
This would put a fair bit of “Shark fin” (as it has been called) curve at the top of the positive going transition which could be close to I2C limits, I don’t know about this, I might simulate this later if I get time just to see what it actually looks like.
Cheers Bob

1 Like

Yeah, scope traces would sure have been nice…Still, the outcome shows it worked OK @ 100kHz for somewhere between 10 and 20 meters…not bad for a system designed to communicate between IC’s!

The fly in the ointment is likely needing not one but two coax cables to each device. That sucks, even if it works!

Back to Gerard’s issue… if it is power supply insuffciency, could that possibiity not be easily eliminated by attaching an alternative source? Then we could focus on what remains… like pull-ups or whatever.

Your comments about Mike’s concern re capacitance on his PCB are very relevant for my own project, we have a nice bit of cross-over between projects going on here! I’ve never really designed a PCB (well, ignoring some amateurish attempts as a teenage kid messing about).

I’l try to avoid hi-jacking this thread to talk a lot about my project… might start a new thread for that… and post some KiCAD stuff there.

Cheers, T.

Hi Trevor

Yes we could.
Right from the start I have been advocating a power supply deficiency but no one has taken any notice.
I just had a look and I still can’t find any reference as to where the power is coming from, what it is and what value, 5V or 3.3V.
2 devices working OK and a third fouls everything up. Power supply problems in my book. The first thing to check anyway. Assuming all devices work properly in isolation. We don’t even know that although the question has been asked.
Does a working device work in every connector ??? Or does the system fail if a particular connector is used. It would not be the first time a connector has been wired incorrectly. These sort of checks are pretty basic fault finding techniques.
Has anything like this been done ?? I suspect not.
I did suggest putting everything on paper as an overall block diagram or something. No luck here either.
About ready to give up actually.
Cheers Bob

I’ve been crook that last couple of days. I’ve got it down to check the power thing today. I have a number of these Adafruits and it’s conceivable that there’s some bad ones in the mix so I need to eliminate that as a possible issue.

The power is from the 3v3 supply.

As per I2C design constraints - #30 by Gerard163258
I can see a 12V feed into LM2596S-5V 3 Amp output, which then feeds into AMS1117-3.3V 1 Amp output.
for completeness, what is the 12V support (output current rating) ?

Hi Michael
OK I saw that when it was posted.
It does not show which output is being used for what.
There are 2 I2C outputs shown. J3 and J7. I did comment (I think) on this and noted that maybe he could use 5V I2C or 3.3V I2C but maybe not both. I did think that 3.3V is being used as his original oscilloscope screen shots indicate this but there again Gerard went on about logic level converters. That opened another can of worms. At some time I suggested sitting down and producing some sort of diagram on what he actually had but have yet to see anything. That was 11 days ago.
Cheers Bob

Yep. if we are talking about not enough power, unless I missed something major, I could not see anything that should be pulling anywhere near the 3.3V 1 Amp. So as long as the 5v reg got the power it needed from the 12V side supply should be ok. But if for some reason the 12V is o small plug pack that only has lower current supply, it would add to power issues; hence my comment.

Hi Michael
Yes agreed.
But the 3.3V regulator is a linear device (a modern version of the old LM317) so the 5V current through this will be the 3.3V current plus a bit for the reg innards.
So the 12V current will be the 5V plus 3.3V currents. Could be the 5V current too high although 3A is a fair bit. Don’t forget I believe the 3A and 1A are absolute maximum ratings.

Unless there is something radically amiss I too would tend to suspect the 12V supply. I don’t we know exactly what that is. This could be anything. But I think Gerard has built this from the ground up on that PCB he pictured. So there might be something else of a current hungry nature that has been overlooked.

I reckon that we are all guessing at the moment which is proving a complete waste of time. An accurate detailed overview and some sort of system diagram would be nice. But reviewing the original problem I would almost put money on a power issue.
Cheers Bob

As I said earlier, the 5v is legacy from when we were using RS485 but now the comms is by ESP Now.

So, the 5v is only used to drive the LEDs (when they’re on which is not currently). And, also, there’s provision for a 5v I2C but that was only there to drive a 2004 LCD display which is also gone…unused.

I left the PSU design “as is” for now. I’m sure there are better/cheaper ways of getting 3v3 from 12v DC.

My bench power supply shows that the total current going in is 50mA.

Hi Gerard

Ah, so the 12V power is a bench supply. That should have plenty of grunt, enough anyway.
But could the current limit accidentally have been set to a low value. If it reaches current limit some sort of indicator like a LED flash while it is limiting should show up. Easy enough to check.
Firstly make sure it has a current limiting function. If it has, disconnect it from everything else, short the _ and + leads together. The meter should read the set current, the voltage will drop to near zero but this is normal. That is how limiting is normally achieved. The voltage is reduced until the set current point is reached.
Cheers Bob