So, I bit the bullet today. Actually, two bullets.
Firstly: I decided to do some redesign on my Wicking Bed project by ditching the SPI and going to I2C.
The SPI is just too problematic with the Master/Slave handshaking and data transfer while the I2C is really straightforward. The trade-off between that and the hardware redesign comes out in favour of switching over to I2C.
Secondly: My next project which is hot on the heels of the Wicking Bed is going to be based on Raspberry Pi/ Python. Again, just a heap easier.
Anyway, my penultimate Semester at Swinburne is about to start!
I2C is super popular right now. Our PiicoDev modules use it, as do SparkFun’s Qwiic and Adafruit’s STEMMA QT modules all with the same JST SH connector. There’s also a selection of DFRobot’s Gravity and Seeed’s Grove lineup that use I2C with a different pinout so there are so many options to expand the functionality of your project by plugging in another module to the existing bus.
Best of luck with the upcoming semester
I suspect that SPI does too but doesn’t I2C have a very limited distance capability?
Yes, that’s the catch since it was designed for Inter-Integrated-Circuit communication the range is very small. That’s one of the reasons you won’t find a PiicoDev cable longer than 500mm, but since a lot of projects fit in a jiffy box that’s usually not a deal-breaker.
Thanks for the best wishes Trent. Appreciate it. We have the subject outlines for the CAD and OOL. AutoCAD and C#…for better or for worse!
With the I2C -vs- SPI, I most definitely need to exceed 0.5m. More like 16m. The I2C may lend itself to some kind of custom driver hardware however, the problem being that it’s a 2 way data stream. But I’ll look into it some more. If it was SPI, then we’d be OK since MOSI and MISO are distinct signals but I2C is a two way street.
16M might be a bit far even for RS232 without special techniques. I2C might be 2 way but isn’t it one way at a time like half duplex. If you can’t make I2C work over that distance you may have to consider conversion to RS485 which will work half duplex over a single circuit.
There is one thing you could try. RS232 is a 3 wire unbalanced system, TX RX and ground but has a very limited range. However, by using 2 pair low capacitance cable as 2 twisted pairs and using 1 pair for TX and one for RX, connect the second wire of each pair to the same ground connection at each end so each circuit has really its own twisted pair, distances of 70 or so metres are achievable with no problems.
As an experiment you could try the same thing with I2C. This has Data, Clock and ground, virtually unbalanced. Try having 2 pairs. Data and Clock each with its own twisted pair and the second wire of each pair connected together and to ground at each end.
I don’t recall nowadays if these pairs were individually screened but I believe the cable was overall screened. I will try to find my old Hartland catalog and find out. In any case these screens should be connected to ground AT ONE END ONLY.
Might be worth a try but you will need to use quality cable, NOT the el-cheapo stuff sometimes available.
Found that catalog would you believe. I don’t know if Hartland Cables still exist but That cable specs follow
Overall screened, Aluminium/Polyester laminate with tinned copper drain wire.
Pairs 2. Conductors 7/0.20 tinned copper.
Insulation Polypropelene, insulation thickness 0.30mm, capacitance 50pF/metre. (between conductors of a pair)
Nominal OD 5.7mm. Hartland part HCK602.
I would think most manufacturers these days would make a cable with similar specs. In fact demand for this better speced cable was so great that I think Hartland stopped production of their “ordinary” PVC insulated (100pF/metre) multipair cable.
PS: Others wishing to extend I2C capabilities (regarding distance) may care to try or experiment with this technique. The down side is finding suitable cable in relative small quantities. When we (my employers) were using this sort of thing cable up to 20 pair was being ordered by the Kilometre. (yes Kilometre)
Just re-read your post re distance. What I thought was 6M turns out to be 16M. While that cabling technique would work for RS232 I don’t think it will apply to I2C.
Transmission lines behave in funny ways when the length approaches one quarter wavelength. In fact at exactly that distance and every odd multiple they will reverse the situation when seen from the TX end, that is an open circuit at the RX will reflect a short circuit as seen at the TX end and vice versa, a capacitive load will be seen as an inductance and so on. As the length of line increases the effects become complex and varied. To prevent these “reflections” a line is terminated with a value equal to the characteristic impedance if the line. This ensures maximum power transfer into the load. For this type of cable this is 120Ω.
What I am getting at here is because I believe the devices involved are high impedance the line will have to be terminated and because the traffic is 2 way this means a terminating resistor at each end. Now this means 120Ω X 2 effectively in parallel which equates to 60Ω. Now I don’t believe the I2C system will drive this load. The same applies to RS485 but the drivers here are designed to drive a load of (I think) 56Ω or might be 54Ω. This is 2 X 120Ω parallel at the ends with up to 32 devices in parallel with that.
Now if your I2C does not work and you have to consider RS485 you will need 2 half duplex circuits, one for Data and one for Clock plus 2 wires for power if required. This means 4 X I2C / RS485 converters (2 at each end) plus any power.
When thinking about this maybe the inconvenience of SPI does not look too bad if it will handle the distance. The reflection problems still exist but the terminations now only need to go at the receiver end and although the signals are basically unbalanced (as RS232) the 2 pair cabling technique may increase the possible distance as it does with RS232. Think only experiment will confirm which system is best.
RS485 Will handle the distance. Published distance is 1200M with the ability to insert repeaters for extreme lengths.
Interested. Keep us posted,
Thanks for that well reasoned post and it explains a lot. I hadn’t realised about the transmission line theory.
I went with RS485 with the SPI iteration and was proposing to adopt something similar with the I2C version. I have attached schematics here with comments…
This is the slave side and I’ve used 2 x DB9 connectors. One goes “upstream” and the other goes “downstream”. This is because the wicking beds are all serially connected. MISO, MOSI, SS, SCK arrive at each slave and are also passed on through downstream. The protocol I’ve designed uses ENQ/ACK. The first TX from the Master has the slave bed number byte embedded. If the byte compares with the switch block value (read by the Atmega on boot up), then that slave will respond to whatever is being asked of it while all the others will ignore. The final slave needs a 120R termination arrangement as you point out.
The Master is simpler in the there’s no “upstream” and there’s a need for terminators regardless.
I use PD6 and PD7 as enables for the MOSI/MISO TX/RX as a tidyup really.
Interested to get your take on my madness!!
The concept looks good. You are running MISO and MOSI in full duplex mode. In order to convert this idea to I2C you will need to change this IC to a half duplex device as I2C is 2 way traffic. Half duplex is depicted in the top diagram in the data sheet. The one with the 2 Op amps connected internally. What you do with "DE " and “RE” I have no idea. I saw a diagram some time ago with a circuit for I2C to RS485 conversion. The 120Ω terminating resistors for half duplex should be fitted at the ENDS of the string, one at the “master” and one on the last “slave” in the string. 2 resistors required.
One thing is wrong with your circuit. 3 of the terminating resistors are in the wrong place. R14 is OK but you have R12, R13 and R15 connected at the TX end. They should be fitted to the RX lines at the LAST “Slave” device on that string otherwise they are doing nothing to stop echos from the end of the cable run.
If you go down the I2C path of course you will not need the Chip Select circuit.
I did mention previously to be careful with commercial I2C / RS485 converters. Some have these terminating resistors fitted internally and you will finish up with one at each point. The should ONLY be fitted at the RX ends of the cable run. Half duplex (I2C) both ends are receiver so a resistor needs to be fitted at each end. That is shown on the half duplex diagram in the data sheet. Some also have a pull up and pull down resistor between A and VCC and B and Gnd. As I said I don’t know what these achieve and I think they only unbalance the line so losing all the advantages of balanced lines. Stay clear of these unless they can be removed.