SPI noise, shielded cable required?

I've got an SPI master/slave test circuit set up between two Atmel ATmega microcontrollers, with the master on an STK500 development board and th slave on a breadboard.

I noticed that sometimes I would get noisy communications and other time I would not get any noise at all, but it seems to depend on how the wire are positioned. The cables I'm using to connect master and slave are som "random" ones I've ripped out of an old computer (used to link th motherboard to the LEDs and switches on the front of the case). There's pair of wires for 5V and 0V, and four SPI data wires. They're only abou

30cm long.

One time when I held all the cables tightly I noticed that the nois stopped, and when I moved them apart, the noise returned. I thought this may have been something to do with external noise, so wrapped some aluminium foil around the six wires (all together) and th communications be came error free.

Doing this has solved my problem, but I was still curious, so I remove the foil and tied all the wires tightly together with string. The error disappeared again. The errors only seem to appear when the data cables are separated from th power cables. Shielding the data and power cables separately (rather tha together in one sheet of foil) results in the errors returning.

Does anyone know the reason for this? Is it something to do with the coupling between the ground and dat lines? Thanks for any suggestions.

Reply to
dohzer
Loading thread data ...

SPI was really designed for communiucation between ICs, like I2C. You could try something like RS-422.

Leon

Reply to
Leon

Yeah, I know it isn't the best method of communicating, but it's th method I'm using.

But I was more interested in the phenomenon that I'm seeing where runnin the 5V and 0V/Ground wires directly next to the data cables wires result in perfect communication, but when they are moved away from the dat cables errors start appearing. Is there anything that could explain that?

Reply to
dohzer

Induced currents for one thing. Separation between the 5V, Ground, and signal lines creates several one-turn coils each enclosing a significant area. Any magnetic hum, etc. in the neighbourhood can induce currents, which read as voltages across the input impedances, which create signal noise.

Mel.

Reply to
Mel Wilson

It has lots to do with coupling between the ground and data lines. When you send a pulse down a data line from one board to another, there has to be a return path for the current. When that return path (the lone ground wire, and to some extent the power wire if it is capacitively coupled in a correct manner) is close to the data lines the pulses you send down the wire have the best chance of retaining their shape.

If you really had to use SPI at those distances, you'd want to use twisted pair wire for each data port, with one wire to ground at each end and the other carrying your data. These wires would be acting like transmission lines, so you'd want to properly terminate them. If you were _really_ serious about SPI over long distances you'd use RS-422, but if you were getting to that point you'd probably be wiser to use some other means of interprocessor communication.

If you're doing a prototype, and if bundling up the wires is sufficient, then do it and be happy.

--
Tim Wescott
Control systems and communications consulting
http://www.wescottdesign.com

Need to learn how to apply control theory in your embedded system?
"Applied Control Theory for Embedded Systems" by Tim Wescott
Elsevier/Newnes, http://www.wescottdesign.com/actfes/actfes.html
Reply to
Tim Wescott

He just needs to bundle them together. I've run SPI over more than 3ft (about a meter), using scraps of CAT-5. Just leave the bundle together, don't tear them out of the jacket.

--
Regards, Joerg

http://www.analogconsultants.com/
Reply to
Joerg

Thanks for all the posts. I guess the problems are due to the curren loops. I just connected 1m of 6-core shielded cable between the master and slav and it's running fine. :)

Reply to
dohzer

Using RS-422 for SPI can actually cause problems. The delay through many of the available RS-422 and RS-485 buffers can be significant and can change over time and temperature. One can easily end up where the the difference in delay for the SPI signals are enough to cause errors. We had a situation in the past where we had a 1V clock pulse which were used for synchronizing. The pulse was level shifted to 5V using a RS-485 buffer. This worked fine, until they changed the manufacturer for the RS-485 buffer halfway through production. The delay difference was enough to shift our syncing with one clock width. Finding this of course took up a fait amount of time. We were initially not looking at the phase shift between the incomming signal, and the signal after the 485 buffer.

Regards Anton Erasmus

Reply to
Anton Erasmus

Leon wrote: ...

I do SPI over RS-422 for off-module communication...

-- Uwe Bonnes snipped-for-privacy@elektron.ikp.physik.tu-darmstadt.de

Institut fuer Kernphysik Schlossgartenstrasse 9 64289 Darmstadt

--------- Tel. 06151 162516 -------- Fax. 06151 164321 ----------

Reply to
Uwe Bonnes

I agree with Tim that using a twisted pair for each signal, where the signal is on one wire and the ground on the other in pair, is the way to go. This is standard practice for any custom cable I make.

CAT5 cable is perfect for short SPI runs, as the 4 pairs will accommodate CS, CLK, MOSI, MISO. The SPI interface should run fairly fast over this cable, given the speed rating for CAT5.

If the slave is powered from the master, then power can be wired separately.

Reply to
Paul Urbanus

That way I ran an SPI link over 3ft or 1m. Default at 4MHz because one of the devices couldn't do more than 5MHz SCLK. But once I stepped on it and revved it to 20MHz since all the other parts could go that high. It worked fine.

--
Regards, Joerg

http://www.analogconsultants.com/
Reply to
Joerg

I agree with the comment on cat5 cable. For a test jig we used hand made twisted pairs where one wire was signal the other ground. It made a lot of difference. Our data rate was fairly low, around 1 Mbs if I remember right. Our cable was also short, only about 6 - 8 inches. The actual application used a board to board connector, so the effective length was only about 2 inches from cpu to peripheral.

You might also trying to foil wrap your existing cable and grounding the foil.

As others have said, SPI is not meant for cabled board to board interfaces.

Scott

Reply to
Not Really Me

You don't say what data rate you are running at, but keeping circuit impedances low via the use of 1 or 2 k pullups may help. Use ribbon cable to carry the signals and interleaving gnd wires with each signal line will help as well. Open wires are a waste of time at anything above a few khz data rate.

1/2 to 1 foot at should be possible at a 1 meg data rate with the above techniques, but you really need to look at the signals on a scope to see what's really happening and to make sure data sheet setup and hold times are being met...

Chris

--

----------------------
Greenfield Designs Ltd
Electronic and Embedded System Design
Oxford, England
(44) 1865 750 681
Reply to
ChrisQuayle

You can go a lot faster and longer on SPI. But there comes a point where line impedance begins to matter. A wee AC termination can't hurt although I did 3ft without it.

--
Regards, Joerg

http://www.analogconsultants.com/
Reply to
Joerg

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.