9
\$\begingroup\$

Overview:

I am communicating among 3 custom pcb boards with dspic33's on them using SPI. I have a master and 2 slaves, but I am sending both the slaves the same data (and letting them choose what to pay attention to).

Hardware setup:

The two slaves have built in BLDC motor controllers and the Master is controlling these motor controllers over SPI. The wires are run about 3 feet from the master to each slave and the headers are typical .1" pitch through hole SAMTECH headers. Each motor controller has it's own 3.3 volt regulator that runs the dsPIC/LV electronics. I use one motor controller regulator(lets call him A) to also power the SPI master DSPIC. To the other motor controller(lets call him B), I just run the SPI lines and ground from the master. The SPI clk is running at 100KHz

Getting to the point (Finally):

With no motors running this all works fine, all data comes through as expected to both slaves. However, when I start up the motors, Bslave no longer gets the correct data. He is either picking up extra clocks or dropping them, I am supposing do to the extra noise. In any event his checksums start failing. Aslave works like a champ no matter what.

1) Would you expect that all these devices need to be ran off the same 3.3 volt source? If so, can you convince me by talking about the longer inductance loop and black magic such as that.

2) Do you have any kind of rule of thumb as to how fast I can expect to be able to run the SPI clk and have success with a hardware setup such as above?

\$\endgroup\$
1
  • \$\begingroup\$ Simulation is needed to estimate how fast the clock will be able to run. Assuming you have double or single layered boards a good rule of thumb is to route a ground trace or a ground copper plane (on the opposite layer) under or adjacent to the SPI lines in order to decrease the noise coupled into the traces. \$\endgroup\$
    – Steinar
    Commented Aug 3, 2013 at 22:29

4 Answers 4

5
\$\begingroup\$

I've run SPI (2MHz clock) about 5m from 1 box to another box and I didn't hesitate in designing the clock and data to be balanced output. The (custom) cable between the two also used twisted pair and screen on both data and clock .

I also sent isolated power to the remote box via dc-to-dc convertors. I didn't have enough time to get this one wrong so possibly my solution was an overkill but hey, it worked. My reasoning behind this decision is that I didn't want "current consumption" spikes going down the screens of the twisted pair. The screenes were not connected to ground at the PC sending end. Treat digital signals like precious analogue signals to get the best performance - always have your screen terminated at the receiving end and if you must (for whatever reason) terminate grudgingly (as well) at the send end.

It was for transmitting 128 channels of low speed analogue signals to a break out box from a PC. I suspect, that if I'd needed to I could operate this at 20MHz clock.

\$\endgroup\$
5
  • 1
    \$\begingroup\$ When you say "screen" do you mean "shield" when referring to the custom cable? \$\endgroup\$
    – JYelton
    Commented Aug 3, 2013 at 0:42
  • 1
    \$\begingroup\$ @JYelton in UK it's called screen. What country are you in? \$\endgroup\$
    – Andy aka
    Commented Aug 3, 2013 at 7:16
  • 1
    \$\begingroup\$ I'm in USA. One of my best friends is British, so we often have unusual discussions about word choice. :) A "screen" to me is either a display or monitor, or the mesh cloth that keeps flies out of the house when the window is open. \$\endgroup\$
    – JYelton
    Commented Aug 4, 2013 at 3:49
  • \$\begingroup\$ @JYelton. Aha a meshed cloth that keeps stuff out. Sounds like a screen to me LOL \$\endgroup\$
    – Andy aka
    Commented Aug 4, 2013 at 10:12
  • \$\begingroup\$ Chosen as answer because it is the only answer where both 1) and 2) were addressed. Although, as many suggested, if I were to redesign the board I would probably just change protocols instead of going differential signaled. I do believe that this would work though. In this case I am just using SPI because it was readily available on my prototype. \$\endgroup\$
    – Matt
    Commented Aug 5, 2013 at 13:27
5
\$\begingroup\$

SPI is no different than any other electrical interface. Pay attention to the usual signal integrity issues (shielding, loop area, impedance, signal termination, etc.) and you can run it a reasonable distance. What's a reasonable distance, it depends on what you are doing with it and how well you can control the various factors.

Can you run it 3 feet? Certainly. Should you? Well, there are better things to use. As others have pointed out, there is RS-4xx that could work well. You can also run SPI, but use the differential signaling over the cable like RS-4xx. This will use up more wires, but those are the breaks. You can also do normal RS-485, using a UART and the like.

I personally have ran SPI over 1 foot cables, inside a chassis, at rates up to 32 MHz with no issues. I have also ran I2C over 4 feet at 100 KHz in a high EMI environment and SPI is a whole lot better than I2C-- so it can be done. But if you don't pay attention to the details then you can easily run into problems. But honestly, you need to pay attention to the details regardless of what you use.

\$\endgroup\$
2
  • 1
    \$\begingroup\$ Many interfaces like RS232 are relatively immune to things like ringing and overshoot, provided that any such effects resulting from a line transition are resolved within half a bit time. Even if a line can't support high baud rates, slowing down the baud rate will help. By contrast, if things like ringing cause problems with SPI at any speed, slowing it down may not help unless one can reduce the slope of line transitions. \$\endgroup\$
    – supercat
    Commented Aug 2, 2013 at 23:31
  • \$\begingroup\$ This is a good answer, especially the numbers of systems you have implemented. I think I will try series resistors on the driver side to see if that helps. However, I am afraid that the noise is causing extra clocks...so in that case it may not help. \$\endgroup\$
    – Matt
    Commented Aug 5, 2013 at 13:31
5
\$\begingroup\$

Carefully consider your grounding scheme. Shield the data lines, if it helps, and ground the shield properly. Don't run data and clock on the same twisted pair. Use galvanic isolation if needed. Other than that, there are no rules of thumb that I aware of.

SPI was designed for (1) short range communication, usually within one PCB and (2) in the environment with not a lot of EMI. Perhaps, the only buses that perform worse than SPI in presence of EMI are I2C and 1-wire. There are buses, which were designed for long range communication in the presence of EMI (RS-485, CAN, Ethernet).

It's possible to extend and ruggedize the SPI. Here's an application note, which shows an SPI bus with differential lines.

\$\endgroup\$
1
  • \$\begingroup\$ I will try to shield the lines. Concerning galvanic isolation, when I don't connect the grounds the slave device never registers any of the clocks sent by the master. \$\endgroup\$
    – Matt
    Commented Aug 5, 2013 at 13:38
1
\$\begingroup\$

There are a few ways to minimize the effects of noise on your signal lines. The easiest way is to route a copper plane or a copper trace adjacent to your signal traces. This minimizes the inductance of the traces and loop area.

At high frequency the return currents like to run a least impedance path adjacent to the signal lines themselves. I assume you have a common ground between your circuits but this may be causing problems for high frequency signaling if your common ground is simply a "power" ground connection between the circuits. It will cause a very large loop area for the signal currents which may enable a lot of noise injection due to stray magnetic coupling.

If you can, connect a extra ground connection between the grounds adjacent to the SPI signal lines in addition to keeping a copper ground plane or trace routed adjacent to the lines inside the boards as well. It may make a world of difference in how susceptible your circuit is to the motors.

\$\endgroup\$
1
  • \$\begingroup\$ I don't understand the phrase "between the grounds adjacent to the SPI signal lines". Specifically, the word adjacent is not clear to me. \$\endgroup\$
    – Matt
    Commented Aug 5, 2013 at 13:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.