I2C over cat5e problem - Page 1
Forum section: electronics / projects

author: Morgoroth
author_rank: Regular Contributor
timestamp: November 23, 2015, 09:00:37 am
content: Hi to all, well, hope someone can help me with this problem.I have to connect (and design in near future) several devices connected to a controller for data acquisition/processing. Now, between software development and hardware cost/benefit I think the best choice is to use I2C over twisted pair (cat5e, is everywhere) as communication protocol, given the noise immunity (PCA9600page 14) I could get, and with daisy chain for power and communication (just for low power devices).12v-------------------------------------------------| | | |MAIN BOARD ----> device1 -----> device2 -----> device3| | | |GND-------------------------------------------------At first I was looking for PoE design as references, but they use a higher voltage that make too expensive my design because I will only use that voltage for that purpose and is a waste of hardware, given other solutions in market.After that I was looking for NXP series of I2C extenders, but all of them are not isolated. I have sensitive devices at side of mechanical relays with 1KW loads and I want my ground full isolated, I tested a prototype with 250W and I got a noise fest.Now I wanted to use 12V as level for i2c extender after an isolation chip, but between the isolation and i2c extender I must use 3.3v (or 5v) which would break my isolation ground, or use another power supply (I don't want to), and I have peristaltic pumps sharing 12v power line and I think that could inject noise (400mA).I don't know what to do, I can't find a cheap solution for this, maybe I'm too worried about noise and the practical solution is only isolate 3.3v for main board and put another regulator, and/or isolate 12V too for i2c, or none.Or maybe I've reading too much, 6:00am here and I'm going to bed more worried than yesterday.Share any experience or idea is very welcome.Thanks in advance,JPPD: sorry for my spanglish.

author: Marco
author_rank: Super Contributor
timestamp: November 23, 2015, 09:11:52 am
content: That's what the PCA9600 does, it doesn't use the i2c physical layer.Any kind of active isolation can be as trivially destroyed as a normal receiver, it protects the circuits behind it, but your electronics still goes down. If you want relative fool proof isolation you'll need magnetic isolation (ie. ethernet isolators). Otherwise don't bother and just put some clamp on ferrite on the cat5 cable near every transceiver.

author: tszaboo
author_rank: Super Contributor
timestamp: November 23, 2015, 09:16:51 am
content: Although, I think I2C is a bad choice for long distance (it is designed for some 30cm) I'll give you some pointers.Texas instruments and Analog devices makes I2C isolators. It is ISO1540, ISO1541 and ADUM1250 , ADUM1251, ADUM2250 ...You need 3,3 or 5 volt on both sides. You can use the buffer after the isolator. Probaby speed will be 100 kbaud, not 400.But I have to say it again, I2C is not a good choice. Try learining CAN or RS485. I've seen 485 working over a kilometer, with 32 nodes and 38400 baud.

author: Psi
author_rank: Super Contributor
timestamp: November 23, 2015, 09:18:20 am
content: I did differential SPI over 100m of cat5 once, worked okAll data 'passed' through each nodes SPI shift reg in a loop and back to the master at the start.

author: Jeroen3
author_rank: Super Contributor
timestamp: November 23, 2015, 09:57:50 am
content: Use the CAN bus phy. Very robust both electrically and logically, isolation is cheap and it is highly modular.You can build a cheap isolated port with an mcp2551, si86xx isolator and sn6501 with transformer.If you have bus power you can maybe get away with an ISO1050 and a linear regulator.

author: TiN
author_rank: Super Contributor
timestamp: November 23, 2015, 10:03:04 am
content: Ditch I2C, it's not always good working even on same PCB with multiple devices, leave alone over long cables. Most of devices are just not meant to drive long capacitive/inductive lines.Use RS485 or RS232 instead if your datarates low, or dedicated interface like proper hot-plug SPI drivers/isolators.

author: Fungus
author_rank: Super Contributor
timestamp: November 23, 2015, 03:02:48 pm
content: Quote from: TiN on November 23, 2015, 10:03:04 amAt what speed? The great thing about I2C is that you can just slow it down until it works.With shielded cable, slow speeds and well chosen pullups I'll put I2C up against almost anything.So... the first job is to find out what data speeds you NEED instead of blindly relying on the half-assed library to choose for you.

author: poorchava
author_rank: Super Contributor
timestamp: November 23, 2015, 03:24:54 pm
content: I'd go with RS485. Analog makes some sweet isolators for it. Some of those even have an isolated power supply too (pretty low power though)Sent from my HTC One M8s using Tapatalk.

author: Dago
author_rank: Frequent Contributor
timestamp: November 23, 2015, 03:29:28 pm
content: Quote from: poorchava on November 23, 2015, 03:24:54 pmYes definitely RS422/485 and not I2C... I2C is not even meant for this kind of applications (though some abuse it for longer distances).

author: poorchava
author_rank: Super Contributor
timestamp: November 23, 2015, 04:25:24 pm
content: Another merit behind RS485 is that you can get off-the-shelf parts rated at 20mbps (though this will work over short distances only and EMC / signal integrity problems are to be expected)Sent from my HTC One M8s using Tapatalk.

author: mikerj
author_rank: Super Contributor
timestamp: November 23, 2015, 04:34:53 pm
content: Quote from: Fungus on November 23, 2015, 03:02:48 pmSlowing down I2C bit rate only fixes rise time problems caused by high cable capacitance, it doesn't offer any additional noise immunity. If it's an electrically noisy environment you would be barking mad to choose I2C over a fully differential signalling standard such as RS485.Additionally Cat5 cable is twisted pair which is perfect for differential signalling and rubbish for single ended clock/data signals such as I2C.

author: Morgoroth
author_rank: Regular Contributor
timestamp: November 24, 2015, 03:07:53 am
content: Thanks to all for your comments, I'll give a try to i2c, seems to be reliable over differential lines, documentation shows a bunch of test results in many situations and seems to be work well for my needs (25m and less of 400Khz), and in parallel I'll build some prototypes for RS485 as plan B.Anyway, there is a nice LTM2883 that seems to be useful, it have +12v/-12v output that I could use on ethernet transformers and simulate PoE with that levels, is just an idea, I'll try to simulate that to see if it is valid, I'll update that later here.Thanks to all !!JP

author: Jay_Diddy_B
author_rank: Super Contributor
timestamp: November 24, 2015, 03:59:07 am
content: Hi,I don't know if SPI is an option. Have a look at the LTC6820.Link:http://www.linear.com/product/LTC6820This works like this:Regards,Jay_Diddy_B

author: Morgoroth
author_rank: Regular Contributor
timestamp: November 24, 2015, 04:19:49 am
content: Yeah, I've saw that, but SDA line is bidirectional

author: Fungus
author_rank: Super Contributor
timestamp: November 24, 2015, 10:06:01 am
content: Quote from: mikerj on November 23, 2015, 04:34:53 pmI guess it all depends on how "electrically noisy" the environment is and how much control you have over the type of cables.eg. HDMI cable has a lot more shielding than cat5e.Quote from: mikerj on November 23, 2015, 04:34:53 pmIf the specified protocol is 'I2C' and there are 'several devices' then "use RS485" is a knee-jerk reaction that doesn't help. I2C lines are bidirectional and multiconnected.

author: Fungus
author_rank: Super Contributor
timestamp: November 24, 2015, 10:16:56 am
content: Quote from: Morgoroth on November 23, 2015, 09:00:37 amCan you add some DC voltage boosters to get the 12V?eg.http://www.ebay.com/itm/271812105443(or whatever)

author: nuno
author_rank: Frequent Contributor
timestamp: November 24, 2015, 10:51:23 am
content: I have done I2C over 0.5m at 500kbps on cat5 cable in a noisy environment, but 25m, ehhhhhh...First of all I also advise strongly against I2C, but if you really want to go that route,- I would test that asap, I2C over 25m. You may slow down the datarate, but the slew rate of the transitions is the same.- I sent SDA and SCL each on its own twisted pair with GND wires connected on both sides. Watch for crosstalk (you should actually be able to calculate it if you some some cable specs).- I used an I2C isolator (ADMU... from Analog) at the receiving end. Besides the obvious advantages, it has the extra advantage of helping you debug the bus, as you will be able to know who's pulling a line low, master or slave.- Watchout for I2C hw bugs at the master and slave devices.- Add message integrity "checksums", and design your protocol to cope well with message errors or failures. In my system the messages have integrity checks and the "dangerous" commands (250W motor control) are idempotent and sent many times a second (and the slave must receive one at a certain minimum rate or it will assume the master is gone and take protective measures).Quote from: Morgoroth on November 24, 2015, 03:07:53 am

author: mikerj
author_rank: Super Contributor
timestamp: November 24, 2015, 10:53:24 am
content: Quote from: Fungus on November 24, 2015, 10:06:01 amKnee jerk reaction? That is a bizarre statement in this context, did you really mean to type that?RS485 works perfectly well for multi-drop networks, which is just as well since it was designed for exactly this purpose. The lines are bi-directional (half duplex two wire) and "multi-connected".The "specified protocol" is a very poor choice for the application, I'm simply telling you (and the OP) why. Since the OP has not yet designed or implemented his system, pointing out the pitfalls of his plan and suggesting more suitable alternatives seems exactly the right thing to do at this point.

author: Fungus
author_rank: Super Contributor
timestamp: November 24, 2015, 11:10:48 am
content: Quote from: mikerj on November 24, 2015, 10:53:24 amYes.Something about "long wire" and "communication" in the same sentence always brings out the word "RS485" in some people.Quote from: mikerj on November 24, 2015, 10:53:24 amWell Icouldbe wrong, but:...what happens when two devices simultaneously pull a wire low ("START") then wait for the other device to release it?...why are there hundreds of RS485 to I2C adapters out there?...why would they bother making special I2C extender hardware if industry-standard RS485 can already do the job?eg.http://www.nxp.com/documents/data_sheet/P82B715.pdf

author: Marco
author_rank: Super Contributor
timestamp: November 24, 2015, 12:30:53 pm
content: Quote from: Fungus on November 24, 2015, 11:10:48 amUse CSMA or a busmaster?

author: mikeselectricstuff
author_rank: Super Contributor
timestamp: November 24, 2015, 12:47:36 pm
content: Quote from: Morgoroth on November 23, 2015, 09:00:37 amThere is no planet where I2C over twisted pair is the best choice. I2C is not designed to go off the PCB.RS485, or for short distances, single-ended TTL levels are far more appropriate.

author: Fungus
author_rank: Super Contributor
timestamp: November 24, 2015, 12:56:12 pm
content: Quote from: Marco on November 24, 2015, 12:30:53 pmTwo devices holding a line low during a "START" isn't a clash between devices in I2C, it's a normal part of the protocol. It happens even when there's only a single master and single slave device.Master and slave both pulling a line low also happens in other situations, eg. "clock stretching" where the slave can hold the clock line low to slow down the master while it processes data, responds to an interrupt, or whatever (masters have to wait for the clock line to go high before they can continue).

author: Fungus
author_rank: Super Contributor
timestamp: November 24, 2015, 01:00:05 pm
content: Quote from: mikeselectricstuff on November 24, 2015, 12:47:36 pmSo what's all thatPCA9600nonsense about?"enables the SDA and SCL signals to be transmitted via balanced transmission lines (twisted pairs)""1 MHz operation on up to 20 meters of wire"etc.Why would that be any worse than RS485?

author: mikeselectricstuff
author_rank: Super Contributor
timestamp: November 24, 2015, 01:19:36 pm
content: Quote from: Fungus on November 24, 2015, 01:00:05 pmThat's not really I2C anymoreQuoteWay more expensive, lower data rate, shorter distances, single source

author: Marco
author_rank: Super Contributor
timestamp: November 24, 2015, 01:38:32 pm
content: Quote from: Fungus on November 24, 2015, 12:56:12 pmSorry I wasn't awake, I thought you were wondering how you would solve the problem of simultaneous access on RS485.You seem to be thinking from the point of view of using the RS485 physical layer directly for I2C, that indeed doesn't make a whole lot of sense. Why would you want to? If you're not forced to use i2c, don't use it at all.

author: Morgoroth
author_rank: Regular Contributor
timestamp: November 24, 2015, 01:39:12 pm
content: RS485 require balanced lines and this is a control device for hydroponic systems, can't say to a regular user "hey, please remember to put a resistor at the end of the line", with luck they will know how to turn on the machine.Now, if we have in marker several protocol using differential lines, working very well at long distances, why I can't keep the protocol part of i2c and use differential lines as physical layer ?, it should work keeping low the bps, adn checksum error using more registers for that (as mentioned before).I'll show the results as soon I get the prototypes, for both, rs485 and i2c, would be interesting.JP

author: Codemonkey
author_rank: Regular Contributor
timestamp: November 24, 2015, 02:00:02 pm
content: Having no terminating resistors won't really affect things with RS485 if your data rate isn't that high. I've done RS485 in large buildings and sites with cable runs well over 1000m in an application where each device on the network switches inductive loads of a few hundred watts on & off and found it to be fine even when the electrician's that did the install forgot to fit the resistor. Its not ideal but its really not that hard to build a terminating resistor into each product and have a jumper that can be removed to disconnect it.I'd be more concerned about getting your transient protection right.

author: mikeselectricstuff
author_rank: Super Contributor
timestamp: November 24, 2015, 02:03:27 pm
content: Yes, termination only becomes an issue when the time for a signal to bounce from the end of the cable is a similar order to the baudrate. below about 100kbaud it's rarely an issue.At low rates termination can reduce useable cable length due to resistive losses in the cable.

author: Marco
author_rank: Super Contributor
timestamp: November 24, 2015, 02:08:43 pm
content: Quote from: Morgoroth on November 24, 2015, 01:39:12 pmSince you are daisy chaining you could just make it point to point and put two transceivers on each drop instead of electrically connecting the two RJ45's.

author: BradC
author_rank: Super Contributor
timestamp: November 24, 2015, 02:18:40 pm
content: Quote from: Codemonkey on November 24, 2015, 02:00:02 pmI've run RS485 over a pair of 10m wet strings (admittedly they were wet with a strong brine, but it still stands) and the only way to run it *was* un-terminated.

author: Fungus
author_rank: Super Contributor
timestamp: November 24, 2015, 02:23:32 pm
content: Quote from: Marco on November 24, 2015, 01:38:32 pmNope, not me. The other people here. I'm the one saying RS485 doesn't work for I2C.Quote from: Marco on November 24, 2015, 01:38:32 pmThat's up to the OP. He said he wanted to use I2C, and that he was looking at the PCA9600 chipset.( ...which made sense to me.)

author: Fungus
author_rank: Super Contributor
timestamp: November 24, 2015, 02:31:12 pm
content: Quote from: Morgoroth on November 24, 2015, 01:39:12 pmThere's no reason. You just need a chipset that's designed to handle I2C instead of RS232 (ie. PCA9600 or equivalent instead of RS485).If you switch to RS485 you'll need to add microcontrollers at each node to decode some sort of protocol, figure out which device you're talking to, pass messages along, etc.Quote from: Morgoroth on November 24, 2015, 01:39:12 pmFrom the point of view of signal integrity they should be similar. After that it's just data rates. I2C makes it easier to fiddle with the data rate because it uses a clock signal and you don't have to update all the slaves with the new speed.

author: Morgoroth
author_rank: Regular Contributor
timestamp: November 24, 2015, 02:53:16 pm
content: Quote from: Fungus on November 24, 2015, 02:31:12 pmexactly !!, that's why I choose i2c over serial protocol, life is far more easy from software point of view. Now, physical layer is the problem to solve, I think I have a solution for this, I'll let you know as soon I check few things, could be useful for other people with same problem.

author: nuno
author_rank: Frequent Contributor
timestamp: November 24, 2015, 09:46:40 pm
content: Quote from: Morgoroth on November 24, 2015, 02:53:16 pmEhhhhhh... I'm not sure it is, I2C hw (and sw) is far more buggy (seen quite some bugs on hw and sw) than UART hw (never seen a bug). I hope you're not planning on using a RaspPI, last time I looked it ignored slave clock stretching in some conditions.

author: PChi
author_rank: Frequent Contributor
timestamp: November 24, 2015, 10:02:02 pm
content: It might seem easier from a software point of view until it is time to debug it. Which device has been messing with the SDA line is difficult to determine. I think that I2C has low noise immunity, hence the requirement for Fast-mode devices to include spike supression and Schmitt trigger inputs.If you can spare the extra wires can't you use SPI with a separate chip select for each slave?

author: Morgoroth
author_rank: Regular Contributor
timestamp: November 24, 2015, 11:29:53 pm
content: No, I can't, just the selection for each device is a nightmare, and UART kind communication it is too, I'll search for other alternative.What about to use rs485 through ethernet transformers for sda_tx, sda_rx and clock, plus one more line for interrupt (to MCU) ?i2c isolator -> rs485 (just physic layer) -> eth transformer -> eth cable ...(LTC4310) ( LTC490 )If I have problems with impedances most probably could be solved.JP

author: nctnico
author_rank: Super Contributor
timestamp: November 25, 2015, 12:03:49 am
content: Quote from: Fungus on November 23, 2015, 03:02:48 pmNo you can't. A spike will still cause an extra clock edge.

author: bitslice
author_rank: Frequent Contributor
timestamp: November 25, 2015, 12:34:59 am
content: Quote from: Fungus on November 24, 2015, 11:10:48 amOne of the suggestions for a potential I2C lockup, was to drop the power line and reset everything on the bus. Of course, whatever was on the bus then had to be able to deal with that.Personally, I2C is a chip to chip solution and that is it, and anything further than that must have the ability to handle random errors, drop outs, dead devices, corrupted data and being unplugged by the cleaner looking for a spare mains socket.

author: DanielS
author_rank: Frequent Contributor
timestamp: November 25, 2015, 02:43:38 am
content: Quote from: BradC on November 24, 2015, 02:18:40 pmTermination is only to prevent signal reflections but you get negligible signal reflections from the open end of very lossy transmission lines.

author: BradC
author_rank: Super Contributor
timestamp: November 25, 2015, 03:30:24 am
content: Quote from: DanielS on November 25, 2015, 02:43:38 amIndeed, and the thing most people miss is the termination needs to be matched to the characteristic impedance of the media.

author: Morgoroth
author_rank: Regular Contributor
timestamp: November 25, 2015, 03:46:31 am
content: If I want to simulate ethernet transformers, would be enough to do 1:1 with inductance values on LTspice ?

author: technix
author_rank: Super Contributor
timestamp: November 25, 2015, 08:39:49 am
content: Been there, done that. My solution was running I2C protocol over two pairs of CAN physical layer.Break the two I2C signals into two pairs of TX and RX using P82B96 and use two CAN PHY chips to make them bidirectional differential pairs, and then send them down Cat5e pairs 1/2 and 3/6. PoE pairs 4/5 and 7/8 are used to send power. This in fact comes directly from NXP's app notes and supports multidrop and daisy chaining.

author: Marco
author_rank: Super Contributor
timestamp: November 25, 2015, 08:44:09 am
content: Quote from: Morgoroth on November 24, 2015, 11:29:53 pmThat's an interesting IC, removes the necessity of having to make a protocol with Manchester coding or 8b/10b yourself.Why didn't they just make it suitable to drive cables while they were at it though? So close.

author: Fungus
author_rank: Super Contributor
timestamp: November 25, 2015, 08:52:18 am
content: Quote from: nctnico on November 25, 2015, 12:03:49 amTechnically true, but overly pedantic.You're forgetting that this isn't a TTL-level trace on a PCB.If you're running at 12V over twisted pairs with 60mA drive capability (eg. PCA9600 chipset) then somebody will have to set off an EMP device nearby to cause that spike.Would your RS485 setup survive that? Sure the line driver chips would recover but what about all the microcontrollers, etc., that you had to add to get RS485 working?

author: TiN
author_rank: Super Contributor
timestamp: November 25, 2015, 10:21:12 am
content: Had multiple devices working with having 130V common voltage on RS485 (with proper driver and isolation ofc)

author: Fungus
author_rank: Super Contributor
timestamp: November 25, 2015, 12:30:00 pm
content: Quote from: bitslice on November 25, 2015, 12:34:59 amThat wasn't the lockup being discussed there. The discussion there was about what happens if you try to use RS485 chips for I2C (it doesn't work!)But...there ARE conditions where I2C can get into a "stuck bus" situation, eg. if the cleaning lady unplugs the master half way though an I2C transaction.These problems (and their solutions) are discussedhere.Quote from: bitslice on November 25, 2015, 12:34:59 amAll of that also applies to RS485.Any system designed for high reliability should have watchdogs, alarms, fault logging, the ability to reset all the slave devices, etc. It's probably more constructive to discuss that than anything else.

author: mikerj
author_rank: Super Contributor
timestamp: November 25, 2015, 03:10:52 pm
content: Quote from: Fungus on November 24, 2015, 02:23:32 pmWho on earth is making this ridiculous suggestion of using an I2C protocol over RS485? Certainly not me.

author: Fungus
author_rank: Super Contributor
timestamp: November 25, 2015, 04:19:00 pm
content: Quote from: mikerj on November 25, 2015, 03:10:52 pmYou said this when I said RS585 doesn't work for I2C:Quote from: mikerj on November 25, 2015, 03:10:52 pm

author: technix
author_rank: Super Contributor
timestamp: December 01, 2015, 07:05:10 pm
content: Quote from: Fungus on November 25, 2015, 04:19:00 pmThe problem is that I2C hardware lacked a few signals that implementing a multi-drop RS485 requires - namely CTS and RTS. CAN, on the other side, does have a physical layer that is compatible with I2C so you can in fact run I2C over CAN PHY, just like NXP suggested. If you have long runs of signal you need to make sure the rise/fall time meets the requirements though, and keep clock skew in check.Also running RS485 requires some kind of collision avoidance mechanism (usually a crappy-implemented CSMA/CD) which I2C does not have.RS422, on the other hand, is easier to implement if you use a "hub" mechanism where signals meet (a few RS422 transceivers and a few diodes to implement.) CSMA/CD is still a problem though.

author: Morgoroth
author_rank: Regular Contributor
timestamp: December 01, 2015, 07:11:29 pm
content: I'll go for i2c over CAN, there is a few nice Freescale chips perfect for this. There is any problem to use ethernet transformers to isolate the signals ?, I'm not convinced about chip isolation alone and seems just fixing impedance is all I need.

author: Marco
author_rank: Super Contributor
timestamp: December 02, 2015, 10:25:56 pm
content: Doesn't use zero DC signalling so won't work across a transformer.MIL-STD-1553 can do itOr you could roll your own RS485 protocol with Manchester coding. Collision avoidance could be handled with the same driven/undriven identification pre-amble CAN uses.

author: Jeroen3
author_rank: Super Contributor
timestamp: December 03, 2015, 05:27:02 am
content: What is wrong with digital isolators? And why are transformers better?

author: Marco
author_rank: Super Contributor
timestamp: December 03, 2015, 01:18:25 pm
content: Cheaper than a digital isolators with build in DC/DC, less complex than alternatives and most robust.That said, for a system which transfers DC power across the cables any way I'd say it's a bit silly to insist on galvanic isolation for communication. I don't see what it adds compared to differential signalling and a common mode choke.Which brings us back to CAN bus.

author: macboy
author_rank: Super Contributor
timestamp: December 03, 2015, 03:16:34 pm
content: Curious that someone mentioned HDMI cables but didn't see the parallel to that. HDMI (and DVI and VGA) all carry a pair of conductors to do EDID identification of the display and its capabilities, and for HDCP handshaking, etc. EDID is implemented with the I2C protocol. There are electrical differences with pull-up strength, speed, and other things due to the need to operate over long cables, but logically it is I2C. So if you want to know how to do this, look up how they did it. Specifically look at DDC2.This pdfmay prove valuable.

author: Morgoroth
author_rank: Regular Contributor
timestamp: December 03, 2015, 03:19:40 pm
content: page 18, table 4.1, SDA and SCL

author: mikerj
author_rank: Super Contributor
timestamp: December 03, 2015, 05:21:30 pm
content: Quote from: Fungus on November 25, 2015, 04:19:00 pmI2C and RS485 are completely different physical layers, at no point have I suggested anyone use the I2C protocol over an RS485 link. When I mentioned RS485, my perfectly reasonable assumption was that a normal packet based asynchronous comms protocol would be used on it (e.g. something lightweight likeMIN). Just like it is on pretty much all RS485 multi-drop systems.

author: Fungus
author_rank: Super Contributor
timestamp: December 03, 2015, 06:44:34 pm
content: Quote from: mikerj on December 03, 2015, 05:21:30 pmOK...