Go Down

### Topic: Maximum SPI Length? (Read 9767 times)previous topic - next topic

#### Qdeathstar

##### Sep 20, 2014, 02:21 pm
I think this question is asked a lot, but i can't seem to find a straight forward answer.

What is the maximum SPI length?

I want to control 6803 LED strips, and place the controller about 15-25ft (3-5 meters) away from the LEDs, I will be driving about 400 LEDs connected end to end (but the power is separate).

Or would i be better off getting another arduino and somthing like two xbee wireless controllers to send a couple of a variables from the controller to an arduino really close to the LEDs, and send data too the LED's from the slave Arduino?
A creaking creeping shadow
stiff against the freezing fog
glares at a tickless watch.

Time has failed him -- all things shall pass.

#### AussieSusan

#1
##### Sep 22, 2014, 01:05 am
This is not quite the right question as the distance between the 2 devices has nothing to do with wither you use SPI or not. You would have the same situation if you used RS232 or 20mA or any other transmission protocol.
One of the reasons why RS232 is specified to use +3 to +25 for one "level" and -3 to -25 for the other is so that you can get a detectable voltage difference by the time the signal gets to the other end of the wire, taking in to account all of the losses (due to the impedance of the cable) along the way. 20mA loops work slightly differently in that you need a complete circuit of the 20mA current but it relies on the fact that you can drive the line with sufficiently high voltages to sustain 20mA through the circuit and still detect whether there is a current flow or not at the far end.
Now, SPI is  a data exchange protocol and does not say anything about the way the SPI master and slave are connected together. When they are on the same circuit board (and therefore typically the distance is measured in a few centimeters) you can use the normal data voltages of the devices (often 3.3v or 5v etc.). You *might* be able to drive those voltages over a length of cable a few meters long but you will probably need to add in w=something to boost the signal to overcome the cable losses - in other words you will have the same problems that the RS232 and 20mA transmission standards are designed to overcome.
Personally, I would use a couple of MAX232 (or similar) line drivers at either end of the cable to sole the transmission protocol issue, and then use SPI or whatever other data transmission protocol you want.
Susan

#### CrossRoads

#2
##### Sep 22, 2014, 05:36 am
How fast are you planning to run the SPI? Full 8 MHz? Default speed of 4 MHz?
You need a somewhat specialized buffer for those speeds.
http://www.digikey.com/product-search/en?pv448=139&FV=fff40027%2Cfff801a4&k=rs232&mnonly=0&newproducts=0&ColumnSort=0&page=1&stock=1&quantity=0&ptm=0&fid=0&pageSize=25

Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

#### Qdeathstar

#3
##### Sep 22, 2014, 06:04 amLast Edit: Sep 22, 2014, 06:09 am by Qdeathstar Reason: 1

This is not quite the right question as the distance between the 2 devices has nothing to do with wither you use SPI or not. You would have the same situation if you used RS232 or 20mA or any other transmission protocol.
One of the reasons why RS232 is specified to use +3 to +25 for one "level" and -3 to -25 for the other is so that you can get a detectable voltage difference by the time the signal gets to the other end of the wire, taking in to account all of the losses (due to the impedance of the cable) along the way. 20mA loops work slightly differently in that you need a complete circuit of the 20mA current but it relies on the fact that you can drive the line with sufficiently high voltages to sustain 20mA through the circuit and still detect whether there is a current flow or not at the far end.
Now, SPI is  a data exchange protocol and does not say anything about the way the SPI master and slave are connected together. When they are on the same circuit board (and therefore typically the distance is measured in a few centimeters) you can use the normal data voltages of the devices (often 3.3v or 5v etc.). You *might* be able to drive those voltages over a length of cable a few meters long but you will probably need to add in w=something to boost the signal to overcome the cable losses - in other words you will have the same problems that the RS232 and 20mA transmission standards are designed to overcome.
Personally, I would use a couple of MAX232 (or similar) line drivers at either end of the cable to sole the transmission protocol issue, and then use SPI or whatever other data transmission protocol you want.
Susan

interesting. Why do rj45/cat6 Ethernet cables have ranges of 100m while spi (or other meathods you mention) are restricted to a few meters?  Voltage?

I'm using the fastLed spi library, so... what ever speed that runs at.
https://code.google.com/p/fastspi/

A creaking creeping shadow
stiff against the freezing fog
glares at a tickless watch.

Time has failed him -- all things shall pass.

#### CrossRoads

#4
##### Sep 22, 2014, 06:16 am
Nothing is faster than the internal hardware running SPI clock at 8 MHz.
8 bytes at nearly 1uS/byte rate:
Code: [Select]
`PORTD = PORTD & 0b11111011; // low on slave select on port D, bit 2spdr = dataArray[0]; nop;nop;nop;nop;nop;nop;nop;nop;nop;nop;nop;nop;nop;nop;nop;spdr = dataArray[1]; nop;nop;nop;nop;nop;nop;nop;nop;nop;nop;nop;nop;nop;nop;nop;spdr = dataArray[2]; nop;nop;nop;nop;nop;nop;nop;nop;nop;nop;nop;nop;nop;nop;nop;spdr = dataArray[3]; nop;nop;nop;nop;nop;nop;nop;nop;nop;nop;nop;nop;nop;nop;nop;spdr = dataArray[4]; nop;nop;nop;nop;nop;nop;nop;nop;nop;nop;nop;nop;nop;nop;nop;spdr = dataArray[5]; nop;nop;nop;nop;nop;nop;nop;nop;nop;nop;nop;nop;nop;nop;nop;spdr = dataArray[6]; nop;nop;nop;nop;nop;nop;nop;nop;nop;nop;nop;nop;nop;nop;nop;spdr = dataArray[7]; nop;nop;nop;nop;nop;nop;nop;nop;nop;nop;nop;nop;nop;nop;nop;PORTD = PORTD | 0b00000100; // high on slave select`
Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

#### Grumpy_Mike

#5
##### Sep 22, 2014, 08:52 am
Quote
Why do rj45/cat6 Ethernet cables have ranges of 100m while spi (or other meathods you mention) are restricted to a few meters?

Not just voltage but protocol and specilist hardware at both ends.
You have not found a definitive answer because there is not one.
All maximum length questions depend  exactly on the individual circuits involved and your defination of "working". That is over what temprature range and what levels of external interference, what capacity of cable and what data rate error you can tolerate.

#### Qdeathstar

#6
##### Sep 22, 2014, 01:39 pm
I'm using cat 6 cable, using the "blue" for clock and "orange" for data, and every thing else tied to ground.

I guess I'll have to get a long cable and try it.

I would think for led strips the tolerable error is quite hig
A creaking creeping shadow
stiff against the freezing fog
glares at a tickless watch.

Time has failed him -- all things shall pass.

#### AussieSusan

#7
##### Sep 23, 2014, 01:29 am
You are confusing two separate things: the data protocol (which is the SPI, I2C etc.) which defines the interpretation of the bits as they are passed from one device to another, and the transmission protocol which defines how the bits are actually sent from one device to another.
The type of cable you are using has only a small impact on the ability to send a signal through it. The reason Ethernet signals can go for long distances is, as Grump-Mike has said, they have specialised hardware at both ends that drive the signal in such a way that it can be reliably received at the far end. This has almost nothing to do with the nature of the signal being sent.
What is the hardware that you are using to connect to the cable? If it is coming straight from the Arduino board then it is probably not enough to travel many meters. However if you use some line drivers, then you will probably get a reliable signal to the far end.
You ask about the reason why this is so, and the answer is to do with the impedance of the line. The wires connecting the two devices has resistance, inductance and capacitance (collectively known as impedance) with the inductance and capacitance having a frequency-dependent component. While the resistance of a piece of wire is generally quite small, as the frequency of the signal increases, the inductance and capacitance can grow to be rather large. This is why you were asked about the speed of the transmissions - the losses in the cable might be small for a 10KHz signal but can rapidly rise for a 10MHz signal.
You need to think of the device doing the sending as a (say) voltage source, the wire going to the other device as an impedance, the other device also as an impedance and finally wire coming back (after all you need a complete circuit for the current to flow) as also being an impedance. Therefore the source sees all of these impedance's as begin in series which makes a voltage divider. Therefore the receiving device only ever sees a portion of the sending voltage.
In order to tell if the signal being sent is a 0 or a 1, the voltage that is seen must be within certain limits. Typically, a zero is represented by a voltage that is between 0 and 1/3x the maximum defined voltage, and a 1 is represented as  between the 2/3x and 1x the maximum defined voltage.
Putting this all together, you can see that the device might only ever see a small portion of the signal that is being sent (the impedance of the cable taking the rest) and the variation if the signal that it does see might not be enough for it to reliably detect the difference between a 0 and a 1.
Transmission protocols try to solve this in several ways. RS232 for example uses a voltage difference from between -3 and -12 volts for a 0 and between +3 and +12 volts for a 1. The difference between the two is much greater than (for example) a 5V system (used with some Arduino systems) and therefore the signal is received more reliably, even over a longer distance which has greater impedance.
Hope this gives you some idea of what is going on and why you are getting the answers you are to your question.
Susan

#### nickgammon

#8
##### Sep 23, 2014, 10:04 am

interesting. Why do rj45/cat6 Ethernet cables have ranges of 100m while spi (or other meathods you mention) are restricted to a few meters?  Voltage?

I suspect one of the reasons for this is that they use a "balanced" protocol (like RS485) which is fairly tolerant to noise (and I believe USB is similar).

However I also suspect that AussieSusan know more about this than I do.
Please post technical questions on the forum, not by personal message. Thanks!

More info: http://www.gammon.com.au/electronics

#### tylernt

#9
##### Sep 23, 2014, 08:10 pm
The reason Ethernet is length limited has less to do with signal quality and more to do with signal propagation delay:

http://www.wildpackets.com/resources/compendium/ethernet/propagation_delay

Go Up