I2C hanging over long wires

Thread Starter

Johnny1010

Joined Jul 13, 2014
96
Hi guys,

I have interfaced two IMU sensors i.e. MPU6050 with an nrf51 controller chip. I read both the sensors and everything works fine when the circuit is made over a breadboard (so no issues in the code). In this case, I use the desired length of wires i.e. almost 6 inches for one MPU6050 and 1 inch for the other MPU6050.
Now as soon as I shift all this to a PCB Board i.e. one MPU6050 is with the NRF chip on the board having short connections and the other MPU connected off the board via 6-inch wires to the PCB board, the I2C starts hanging.
The supply voltage is 3.3V and pull ups used are 2.2k ohm. I have tried multiple things. Decreasing the pull-up value to 1k has improved the I2C performance as it now runs for a longer time on the PCB board. But the hanging still persists. Moreover, decreasing the wire length also solves the problem but can't do that due to design constraints.
On the breadboard, the I2C runs smoothly up to 10 inches of wire length, above that it also starts to hang but on the PCB I start getting issues above 3 inches.
What could be the potential things that I might be missing out on? Could there be a problem in the PCB design, what considerations should I keep in mind? The wires are directly soldered to the PCB board could that be causing some sort of interference?

Thanks in advance.
 

Thread Starter

Johnny1010

Joined Jul 13, 2014
96
@AlbertHall The I2C speed is 400 kHz, which is the max possible but due to time constraints can't decrease the speed. But the system on the breadboard runs smoothly even at this speed of 400 kHz.
 

Larry4911

Joined Mar 15, 2012
27
I would look for mistakenly designed capacitance on the board first.

Then try shielded cable. The length could be allowing stray RFI problems.

Larry
 

ErnieM

Joined Apr 24, 2011
8,377
Define "hanging." Is this a NAK you ignore in the code?

What does your oscilloscope say about the signals and their voltage and timing margins. Got noise?
 

Papabravo

Joined Feb 24, 2006
21,225
It sounds like something else is going on. Can you provide a schematic of the setup between the I2C chips, with some indication of the distances. Are the chips coupled directly, that is no intervening chips or repeaters or other such stuff?

Maybe try twisting SDA and SCL with a ground wire going board to board.
 
Last edited:

MrChips

Joined Oct 2, 2009
30,810
+1
Take the SDA wire and pair it with a GND wire. Twist the wire pair, about 2 or 3 twists per cm.
Do the same with the SCL wire, i.e. a separate twisted pair, SCL and GND.
 

Thread Starter

Johnny1010

Joined Jul 13, 2014
96
It sounds like something else is going on. Can you provide a schematic of the setup between the I2C chips, with some indication of the distances. Are the chips coupled directly, that is no intervening chips or repeaters or other such stuff?

Maybe try twisting SDA and SCL with a ground wire going board to board.
I'll give the twisting thing a try and let you know. Can I do something like twisting the ground, SCL, SDA all three wires together or something @MrChips suggested. I have made a block level diagram.
Block Diagram.png
 

MrChips

Joined Oct 2, 2009
30,810
I'll give the twisting thing a try and let you know. Can I do something like twisting the ground, SCL, SDA all three wires together or something @MrChips suggested. I have made a block level diagram.
View attachment 125920
No. You need four wires in all.

SCL + GND twisted.
SDA + GND twisted.

You end up with two pairs. Do not bring the pairs together. Keep them away from each other if possible.
 

SgtWookie

Joined Jul 17, 2007
22,230
The signal may be "ringing" on the wire due to inductance in combination with a rapid rise/fall time; you may need to add some resistance in the long wire to lower that rise/fall time and reduce/eliminate the ringing. Try values of 10 to 200 Ohms, and see if it improves. Make certain that your ICs have 0.1uF caps across their Vdd/Vee/GND leads, as close as possible, and larger electrolytic caps across the supplies nearby.
 

DickCappels

Joined Aug 21, 2008
10,180
While doing the above, make sure that your power supplies are well bypassed at both chips.

By the way, in case it was not entirely clear, SgtWookie's recommendation is to put some resistance in series with the SCL and SDA lines to reduce ringing.
 

Thread Starter

Johnny1010

Joined Jul 13, 2014
96
@SgtWookie and @DickCappels , I have added 100 ohm resistors in series with SDA and SCL and the problem seems to have solved. I had a question that would increasing the pull up resistor by 100 ohm have the same effect. I mean is this series resistor also in series with the pull up resistor? Moreover, how would the ringing effect appear in the waveform of SDA and SCL.
 

Papabravo

Joined Feb 24, 2006
21,225
@SgtWookie and @DickCappels , I have added 100 ohm resistors in series with SDA and SCL and the problem seems to have solved. I had a question that would increasing the pull up resistor by 100 ohm have the same effect. I mean is this series resistor also in series with the pull up resistor? Moreover, how would the ringing effect appear in the waveform of SDA and SCL.
No, the series resistor and the pullup serve different functions.
 

SgtWookie

Joined Jul 17, 2007
22,230
Thank you, @DickCappels, for clarifying my reply.

@Johnny1010: no, the 100 Ohm resistors that are in series serve only to slow the rise/fall times and dampen any oscillation. The IC pins electrically appear to be small capacitors on the order of picofarads, and the wire has an inductance value of roughly 15nH per inch. If there is very low resistance in the circuit, then when one pin pulls the line low suddenly, the signal path "rings" like a bell that has been struck. It is, in fact, a series resonant circuit. The added resistance prevents the circuit from resonating.
 

BobaMosfet

Joined Jul 1, 2009
2,113
The values for pullups on i2c are normally calculated by formula based on frequency. A 400kHz i2c bus actually communicates at about 100kHz. You have to have pullups that are just strong enough to hold voltage either high or low, but weak enough that the slave can pull them the other way when needed.

The primary reason for 'hangup's in i2c is simply because the slave pulls the signal down and never releases (meaning it got an incomplete command or didn't understand or didn't get everything). If this happens, you need to have a watchdog timer reset the bus from the master end, and retry. It is not unusual for i2c to require tens to hundreds of retries in noisy environments, but this usually equates to a 50-60ms and is unnoticed by most human interaction.

I've found that 1K6 and 1K8 pullups on the SDA and SDC lines work pretty well in 5VDC environments on PCBs at the 400khz rate.

As mentioned by others, pullups and pull down resistors are NOT in series with something else, they are parallel to each line.
 

shteii01

Joined Feb 19, 2010
4,644
Kinda funny.
It would be easier to decrease the speed since it is in software.

Also. There are chips that extend the distance.
 

Thread Starter

Johnny1010

Joined Jul 13, 2014
96
@SgtWookie sorry for bringing this up again. Adding the 100 ohm resistor had solved the issue but I had to add another I2C component on the same lines and the issue started to appear again as now I have three instead of two i2c components connected. I am thinking of increasing the 100 ohm resistance to see if it works. Just wanted to confirm that the resistance needs to be increased in order to further dampen the ringing effect.
 

SgtWookie

Joined Jul 17, 2007
22,230
So, you've added another device, which would add more capacitance to the circuit, and probably added more wire which added more inductance. Yes, you may need to add more resistance in the signal lines -- but not just adding to the existing; put the resistance in the new wiring to your new device.

You have posted no schematics, no layout, so I'm taking potshots in the dark. If you want better answers, you will need to provide much more complete information. This will save you a lot of time and frustration in the long run.

I do not check the forum very often, my life in retirement is quite busy. 1chance and I are taking the grandson in the motor home for the weekend, so I will be out of touch.

Good luck solving the problem.

Go back and document the circuit how it was when it was working.

Then describe how you wish to add to it.
 
Last edited:
Top