I want to do a connection of multiple current and voltage meters, they connect by I2C. Is for to monitor solar panels and batteries, they will be a considerable distance from the master. I thinking use a 6P6C or RJ45 connectors for this. But first I want to know if there is a standard for cable colors or another type of connector for this, just for follow the protocols in case I want to expand my system or buy a new device.
Electronic – If there is a cable and jack standard for I2C
i2cstandard
Related Solutions
I designed[1] something like this using I2C once. (Since I did it for work, I can't post the code.) As long as you have control over all the nodes (they're all MCUs programmed by you), this should work.
Basically, the devices are arranged in a daisy-chain using I2C as normal. In addition to the I2C, you have a point-to-point logic line, using two PIO pins per node. One pin ("upstream sense") is input-only and pulled up, while the other pin ("downstream sense") is output-only, but initially tri-stated (high-Z out) and optionally pulled up. Each node's upstream sense pin is connected to the downstream sense pin of the next chip upstream. The farthest-upstream and farthest-downstream pins are left unconnected. Optionally, each node can have an external FET which connects pull-up resistors to the I2C bus.
On power up, all nodes have their I2C ports as slaves with address 0 or some such (doesn't really matter), drive their downstream sense pins to 0, and wait for a fixed time (depends on how long it takes for all your nodes to power up and initialize). What they're looking to receive is an "all call" (broadcast) message.
Whichever node is farthest upstream will not see its upstream sense pulled low in this time. So it goes first (if pull-ups are FET-controlled, it turns its pull-up on), sets its port as a master, and broadcasts an all-call message identifying itself to the other nodes, including its address (whatever you want to use for the first one) and any other information identifying what it is to the other nodes. Then it waits for a fixed amount of time for another node (should be none, but who knows) to send an all-call message saying that they are in fact at the first address. If it gets such a message, it then repeats its identification, but with the next address. This cycle repeats until it finds an available address. (This pattern allows a node to reset and get its address back without confusing the bus.)
Once it is sure of its address, it sets it in the I2C peripheral and goes to slave mode, to listen for other nodes, and drives its downstream sense line high, which tells the next node downstream to go through the same process to get its address. At this point, it just listens for people trying to claim its address, and records the identification information of the other nodes. (Nodes also listen for other nodes' identification prior to getting a rising edge on upstream sense, building a network table, but they don't have a claimed address yet, so they don't check for collisions. When it comes time to claim an address, it can use the table data to pick a likely unclaimed address.)
After all this, everyone should have unique I2C addresses and be ready to go. Then you just use I2C as normal. (Needless to say, whatever initial address all nodes had could not be used post-configuration.) In our setup, all-call was only used for configuration, and direct addressing was only used for real work. If you want to use all-call after configuration, you'll need to design your all-call message to flag which mode it's in.
There's probably plenty that can be optimized here, but it should give you a start. We used this on a piggyback board for a half-brick power supply, so you could just snap together whatever bricks you needed (we added edge-mating connectors to our boards to carry I2C and the other lines) and then plug into a serial port on any one of the bricks to get voltage, current, and temperature information on all of them. It was pretty sweet and got our student (who did the heavy lifting) an A in senior lab. (Then he ran as fast as he could to grad school across the country...)
[1] By "designed" I mean I wrote up something similar to the text above, the 1% inspiration per Edison. The 99% perspiration was provided by my undergrad student.
Where did you get the idea that SDA and SCL lines should be twisted?
This is the second worst thing you can do to I2C communication next to cutting the wires.
Twisting is suitable for differential lines such as CAN or RS485/422.
With slow enough communication you probably won't even need repeater/extender on 2.5m. Especially, if this a 5V system. Just untwist those I2C lines.
If you have some spare lines on the ribbon cable try to put some GND lines in between I2C (non-twisted )pairs or even between SDA and SCL of same channel.
EDIT: there is a way where twisted-pair might come in handy for I2C. It is where each of the two signals is transmitted differentialy (some kind of 4-wire I2C).
Driving I2C-bus signals over twisted pair cables with PCA9605 transmits SDA bidirectionally over a twisted pair of wires.
Sending I2C-bus signals via long communications cables with P82B96 or PCA9600 explains the advantages of transmitting SDA using a unidirectional "4-wire driving method".
Related Topic
- Electronic – arduino – How to connect ATTiny45 to Arduino via serial/spi/i2c and send data
- Electronic – arduino – i2C : pull-up resistors “design pattern”, Shielded cable and connector
- Electronic – Connecting i2c slaves to master over RJ45 style cable
- Electronic – Parallel differential signals
- Electronic – Correct SPI, I2C termination and EMI limiter for external bus
- Electronic – Multiple slave I2C on different power rails
Best Answer
I2C specification does not specify any connector, as it is not a specification for an external interface. Many technologies that are based on I2C do specify a connector and pinout for an external interface, for example Access.bus has 4-pin connector. Lego Mindstorms also implements I2C over 6P6C connectors.