meminoglu
Posts: 29
Joined: Sun Mar 05, 2017 3:15 pm

i2c and SPI cable length

Tue Dec 04, 2018 9:59 am

I used SPI and i2c connections together with ethernet cable. There are 8 wires, I used MOSI, MISO, SS, RST and SCLK For SPI, SDA and SCL for i2C, last wire is Ground. (I also used level shifters for Arduino Raspberry communication)

In my system, there are 4 RC-522 module, 4 Arduino. I Control RC 522 with SPI Cable and i control Arduino with i2c and yes i have 4 ethernet cables.

I use Raspberry Pi SPI0 and SPI 1, each spi have 2 slaves (RC-522), and my i2c connection has 4 arduinos (Same bus)

I have no problem with short cables. (it is about 30 cm) But when i use long cable, i got serious problems. I mean long is more than 5 mt, maybe 10 mt...

I don't know what is real problem but my RC-522 modules not work with long cables. i tried lower speed of spi 1.000.000 to 100.000, and it doesn't work. I also not sure about i2c, probably it is not working too. How can i solve this problem?

scotty101
Posts: 3343
Joined: Fri Jun 08, 2012 6:03 pm

Re: i2c and SPI cable length

Tue Dec 04, 2018 10:10 am

The basic problem is that neither SPI nor I2C are designed to work over long cable lengths. They are typically designed to work from one side of a PCB to another.

With I2C, if you aren't using twisted pair cables and if you haven't considered the capacitance of the cables, you are unlikely to succeed.

This (https://electronics.stackexchange.com/q ... bus-length) suggests that 2.25m with I2C is the maximum length.

Use a protocol designed for these long distances.
Electronic and Computer Engineer
Pi Interests: Home Automation, IOT, Python and Tkinter

meminoglu
Posts: 29
Joined: Sun Mar 05, 2017 3:15 pm

Re: i2c and SPI cable length

Tue Dec 04, 2018 10:14 am

scotty101 wrote:
Tue Dec 04, 2018 10:10 am
The basic problem is that neither SPI nor I2C are designed to work over long cable lengths. They are typically designed to work from one side of a PCB to another.

With I2C, if you aren't using twisted pair cables and if you haven't considered the capacitance of the cables, you are unlikely to succeed.

This (https://electronics.stackexchange.com/q ... bus-length) suggests that 2.25m with I2C is the maximum length.

Use a protocol designed for these long distances.
You mean RS-485? and there is still problem with RC522 module, it doesnt support rs485, and i guess i will need spi to rs 485 converter.

scotty101
Posts: 3343
Joined: Fri Jun 08, 2012 6:03 pm

Re: i2c and SPI cable length

Tue Dec 04, 2018 10:26 am

RS-485 might be overkill.

Does the RC522 not support a UART connection? Might be possible to use this in conjunction with some logic level converters to "amplify" the UART signal over the cable and then step it back down to 3.3v at the Pi end. If it does support UART, it could support RS-485.
Electronic and Computer Engineer
Pi Interests: Home Automation, IOT, Python and Tkinter

meminoglu
Posts: 29
Joined: Sun Mar 05, 2017 3:15 pm

Re: i2c and SPI cable length

Tue Dec 04, 2018 10:36 am

scotty101 wrote:
Tue Dec 04, 2018 10:26 am
RS-485 might be overkill.

Does the RC522 not support a UART connection? Might be possible to use this in conjunction with some logic level converters to "amplify" the UART signal over the cable and then step it back down to 3.3v at the Pi end. If it does support UART, it could support RS-485.
Yeah in datasheet, it says supports UART

Brandon92
Posts: 616
Joined: Wed Jul 25, 2018 9:29 pm
Location: Netherlands

Re: i2c and SPI cable length

Tue Dec 04, 2018 10:50 am

I2C indeed original designed for communication between IC on one single PCB. However there are two options to drive the I2C over a long wire (>50 Meter): The differential pair is the best option to get a large distance. But, it is also the most expensive one.

*first part-number I could find.

edit:
As a example, you could use this:
Qwiic Differential I2C Bus Extender (PCA9615) Hookup Guide

And it is almost the same story for SPI

Return to “Interfacing (DSI, CSI, I2C, etc.)”