EmbeddedRelated.com
Forums
The 2024 Embedded Online Conference

SPI noise, shielded cable required?

Started by dohzer March 22, 2008
I've got an SPI master/slave test circuit set up between two Atmel ATmega8
microcontrollers, with the master on an STK500 development board and the
slave on a breadboard.

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

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

Doing this has solved my problem, but I was still curious, so I removed
the foil and tied all the wires tightly together with string. The errors
disappeared again.
The errors only seem to appear when the data cables are separated from the
power cables. Shielding the data and power cables separately (rather than
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 data
lines?
Thanks for any suggestions.


On Mar 22, 12:12=A0pm, "dohzer" <doh...@hotmail.com> wrote:
> I've got an SPI master/slave test circuit set up between two Atmel ATmega8=
> microcontrollers, with the master on an STK500 development board and the > slave on a breadboard. > > I noticed that sometimes I would get noisy communications and other times > I would not get any noise at all, but it seems to depend on how the wires > are positioned. The cables I'm using to connect master and slave are some > "random" ones I've ripped out of an old computer (used to link the > motherboard to the LEDs and switches on the front of the case). There's a > pair of wires for 5V and 0V, and four SPI data wires. They're only about > 30cm long. > > One time when I held all the cables tightly I noticed that the noise > stopped, and when I moved them apart, the noise returned. > I thought this may have been something to do with external noise, so I > wrapped some aluminium foil around the six wires (all together) and the > communications be came error free. > > Doing this has solved my problem, but I was still curious, so I removed > the foil and tied all the wires tightly together with string. The errors > disappeared again. > The errors only seem to appear when the data cables are separated from the=
> power cables. Shielding the data and power cables separately (rather than > 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 data > lines? > Thanks for any suggestions.
SPI was really designed for communiucation between ICs, like I2C. You could try something like RS-422. Leon
>SPI was really designed for communiucation between ICs, like I2C. You >could try something like RS-422. > >Leon
Yeah, I know it isn't the best method of communicating, but it's the method I'm using. But I was more interested in the phenomenon that I'm seeing where running the 5V and 0V/Ground wires directly next to the data cables wires results in perfect communication, but when they are moved away from the data cables errors start appearing. Is there anything that could explain that?
dohzer wrote:
> But I was more interested in the phenomenon that I'm seeing where running > the 5V and 0V/Ground wires directly next to the data cables wires results > in perfect communication, but when they are moved away from the data > cables errors start appearing. > Is there anything that could explain that?
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.
On Sat, 22 Mar 2008 06:12:42 -0500, dohzer wrote:

> I've got an SPI master/slave test circuit set up between two Atmel > ATmega8 microcontrollers, with the master on an STK500 development board > and the slave on a breadboard. > > I noticed that sometimes I would get noisy communications and other > times I would not get any noise at all, but it seems to depend on how > the wires are positioned. The cables I'm using to connect master and > slave are some "random" ones I've ripped out of an old computer (used to > link the motherboard to the LEDs and switches on the front of the case). > There's a pair of wires for 5V and 0V, and four SPI data wires. They're > only about 30cm long. > > One time when I held all the cables tightly I noticed that the noise > stopped, and when I moved them apart, the noise returned. I thought this > may have been something to do with external noise, so I wrapped some > aluminium foil around the six wires (all together) and the > communications be came error free. > > Doing this has solved my problem, but I was still curious, so I removed > the foil and tied all the wires tightly together with string. The errors > disappeared again. > The errors only seem to appear when the data cables are separated from > the power cables. Shielding the data and power cables separately (rather > than 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 data lines? > Thanks for any suggestions.
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
Leon wrote:
> On Mar 22, 12:12 pm, "dohzer" <doh...@hotmail.com> wrote: >> I've got an SPI master/slave test circuit set up between two Atmel ATmega8 >> microcontrollers, with the master on an STK500 development board and the >> slave on a breadboard. >> >> I noticed that sometimes I would get noisy communications and other times >> I would not get any noise at all, but it seems to depend on how the wires >> are positioned. The cables I'm using to connect master and slave are some >> "random" ones I've ripped out of an old computer (used to link the >> motherboard to the LEDs and switches on the front of the case). There's a >> pair of wires for 5V and 0V, and four SPI data wires. They're only about >> 30cm long. >> >> One time when I held all the cables tightly I noticed that the noise >> stopped, and when I moved them apart, the noise returned. >> I thought this may have been something to do with external noise, so I >> wrapped some aluminium foil around the six wires (all together) and the >> communications be came error free. >> >> Doing this has solved my problem, but I was still curious, so I removed >> the foil and tied all the wires tightly together with string. The errors >> disappeared again. >> The errors only seem to appear when the data cables are separated from the >> power cables. Shielding the data and power cables separately (rather than >> 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 data >> lines? >> Thanks for any suggestions. > > SPI was really designed for communiucation between ICs, like I2C. You > could try something like RS-422. >
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/
On Sat, 22 Mar 2008 14:01:13 -0500, Tim Wescott <tim@seemywebsite.com>
wrote:

>On Sat, 22 Mar 2008 06:12:42 -0500, dohzer wrote: > >> I've got an SPI master/slave test circuit set up between two Atmel >> ATmega8 microcontrollers, with the master on an STK500 development board >> and the slave on a breadboard. >> >> I noticed that sometimes I would get noisy communications and other >> times I would not get any noise at all, but it seems to depend on how >> the wires are positioned. The cables I'm using to connect master and >> slave are some "random" ones I've ripped out of an old computer (used to >> link the motherboard to the LEDs and switches on the front of the case). >> There's a pair of wires for 5V and 0V, and four SPI data wires. They're >> only about 30cm long. >> >> One time when I held all the cables tightly I noticed that the noise >> stopped, and when I moved them apart, the noise returned. I thought this >> may have been something to do with external noise, so I wrapped some >> aluminium foil around the six wires (all together) and the >> communications be came error free. >> >> Doing this has solved my problem, but I was still curious, so I removed >> the foil and tied all the wires tightly together with string. The errors >> disappeared again. >> The errors only seem to appear when the data cables are separated from >> the power cables. Shielding the data and power cables separately (rather >> than 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 data lines? >> Thanks for any suggestions. > >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.
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
Thanks for all the posts. I guess the problems are due to the current
loops.
I just connected 1m of 6-core shielded cable between the master and slave
and it's running fine. :)
Leon <leon355@btinternet.com> wrote:
...
> SPI was really designed for communiucation between ICs, like I2C. You > could try something like RS-422.
I do SPI over RS-422 for off-module communication... -- Uwe Bonnes bon@elektron.ikp.physik.tu-darmstadt.de Institut fuer Kernphysik Schlossgartenstrasse 9 64289 Darmstadt --------- Tel. 06151 162516 -------- Fax. 06151 164321 ----------
Tim Wescott wrote:
> On Sat, 22 Mar 2008 06:12:42 -0500, dohzer wrote: > >> I've got an SPI master/slave test circuit set up between two Atmel >> ATmega8 microcontrollers, with the master on an STK500 development board >> and the slave on a breadboard. >> >> I noticed that sometimes I would get noisy communications and other >> times I would not get any noise at all, but it seems to depend on how >> the wires are positioned. The cables I'm using to connect master and >> slave are some "random" ones I've ripped out of an old computer (used to >> link the motherboard to the LEDs and switches on the front of the case). >> There's a pair of wires for 5V and 0V, and four SPI data wires. They're >> only about 30cm long. >> >> One time when I held all the cables tightly I noticed that the noise >> stopped, and when I moved them apart, the noise returned. I thought this >> may have been something to do with external noise, so I wrapped some >> aluminium foil around the six wires (all together) and the >> communications be came error free. >> >> Doing this has solved my problem, but I was still curious, so I removed >> the foil and tied all the wires tightly together with string. The errors >> disappeared again. >> The errors only seem to appear when the data cables are separated from >> the power cables. Shielding the data and power cables separately (rather >> than 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 data lines? >> Thanks for any suggestions. > > 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. >
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.

The 2024 Embedded Online Conference