Reply by Joerg March 28, 20082008-03-28
ChrisQuayle wrote:
> 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. >> >> > > > 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... >
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 by ChrisQuayle March 27, 20082008-03-27
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. > >
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 by Not Really Me March 25, 20082008-03-25
"dohzer" <dohzer@hotmail.com> wrote in message 
news:rcOdnS-4VZE3dHnanZ2dnUVZ_hisnZ2d@giganews.com...
> 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. > >
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 by Joerg March 24, 20082008-03-24
Paul Urbanus wrote:
> 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. >
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.
> If the slave is powered from the master, then power can be wired > separately.
-- Regards, Joerg http://www.analogconsultants.com/
Reply by Paul Urbanus March 24, 20082008-03-24
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.
Reply by Uwe Bonnes March 24, 20082008-03-24
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 ----------
Reply by dohzer March 23, 20082008-03-23
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. :)
Reply by Anton Erasmus March 23, 20082008-03-23
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
Reply by Joerg March 22, 20082008-03-22
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/
Reply by Tim Wescott March 22, 20082008-03-22
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