5
\$\begingroup\$

A couple of days ago I had an issue where I was unable to read data from an SPI slave. I finally fixed and I'm now able to read data quite well.

However, I found another interesting issue today. If I connect the slave's output directly to the MCU, the data is corrupted. The following picture shows this:

enter image description here

However, if I put in a series 220 Ohm resistor the data comes in just fine, like so:

enter image description here

The byte transferred was 11001101. You can see the start and end of the transfer from the two small dips in the waveform. The starting dip is seen near the trigger indicator. These are nowhere to be seen in the corrupted waveform.

The rate of data transfer is not very fast. The clock rate is just 62500 Hz.

What could cause this? And how can I make sure that it does not occur when I finally layout the PCB?

The top waveform is the clock (SCK) and the bottom is MISO.

These waveforms show the ringing in more detail. Again, top waveform is the clock and the bottom is MISO. This picture has the CPLD and MCU connected via 220 Ohm resistor:

enter image description here

This shows the ringing when the MCU and CPLD are connected directly (no resistor between them). Note that I cannot get to the source pin (in this case, the CPLD's pin) because the CPLD is on a development board and the chip is on a BGA package. I will try and see if the pin can be probed. Also, I forgot to add, I also have a 100 Ohm resistance in series on the SCK like. I needed this to reduce ringing from the MCU on the clock and because its required for the AVR ISP programmer. Otherwise, AVR Studio simply puts out an error. So, on the final PCB layout they are going to be needed.

enter image description here

\$\endgroup\$
  • \$\begingroup\$ Are you sure you're probing the right signals? The first image looks like you're following a clock signal. Neither appear corrupted. \$\endgroup\$ – Kevin Vermeer Sep 20 '11 at 10:32
  • \$\begingroup\$ Yep. I leave the probe connected and as soon as I connect the MCU directly to the slave, the waveform changes. \$\endgroup\$ – Saad Sep 20 '11 at 10:45
  • \$\begingroup\$ Display the clock, as well. \$\endgroup\$ – Leon Heller Sep 20 '11 at 11:12
  • 2
    \$\begingroup\$ When probing high speed signals you can use a temporary short ground attached near the tip of the probe to reduce loop area. Here is a good link that gives tips on this. \$\endgroup\$ – Oli Glaser Sep 20 '11 at 19:12
  • 1
    \$\begingroup\$ Just so we're clear, the plastic breadboards where you push wires into holes are the problematic ones. I don't think the etched-board ones have nearly these problems. \$\endgroup\$ – Mike DeSimone Sep 21 '11 at 3:41
5
\$\begingroup\$

When probing, you need to probe the signal where it hits the input pin, and make sure the probe ground is connected to a ground near that pin, so it doesn't hide any ground bounce. It looks to me like you're probing at the output pin, which will hide any ringing.

In the first plot, I see spikes at the signal edges. This tells me that you have some overshoot and possibly potential ringing. The fact that a 220 ohm resistor fixed it is indicative of this as well.

There are three usual solutions to this problem.

The first solution is to use a ferrite bead in series to damp the spike. The ferrite bead will look like a large resistance at high frequencies and a short at low frequencies. It's not the same as an inductor (and a spike usually means you have more than enough inductance in your line).

The second solution is to use a series resistor like you did, but typical values for this resistor are around 22 to 50 ohms, depending on the transmission line impedance, and the resistor must be placed at the source (driver output) end of the line (usually within 0.2 inch, though that may not make any difference at 62.5 kHz). The function of this resistor is to slow down the rising and falling edges of the waveform, damping their high-frequency components. 220 ohms seems like too much resistance to me. You can also use a ferrite bead (or similar EMI filter) with the resistor, usually if your line is part of a cable.

Finally, you might be able to program your driver for a slower edge rate (several nanoseconds instead of one or two), though this is still an unusual feature. This is actually the best solution, and greatly reduces EMI to boot.

\$\endgroup\$
  • \$\begingroup\$ +1 - Good point about the slew rate limiting - IIRC from the last question this was on an FPGA, so it's quite likely there will be an option to program it for slower rise time. \$\endgroup\$ – Oli Glaser Sep 20 '11 at 14:06
  • \$\begingroup\$ Hoping that MCU/DSP vendors start putting slew rate control in their chips... \$\endgroup\$ – Mike DeSimone Sep 20 '11 at 15:03
  • \$\begingroup\$ Thanks Mike. This is on an CPLD and I'll look into reducing the rise/fall time. I hope its possible. However, I need to include the resistance anyway. This is because I program the AVR via ISP and that utilizes the SPI lines as well. The AVR ISP application note suggests to put a small resistance on each SPI line (except SS) otherwise the AVR mkII can't program the MCU. I intend to include a small header on the board for the programmer, so these resistance will be required in anycase. \$\endgroup\$ – Saad Sep 20 '11 at 15:11
  • \$\begingroup\$ Okay, forthat you'll need a resistance of at least 1k or so. The resistances I gave will be too strong for the AVRisp to drive. However, you still want the resistor on the driver end of the wire, or you'll want a buffer on the receive end (so it would be MISO out -> 27 ohm -> long wire -> buffer input, then buffer output -> 1k to 10k resistor -> ISP header -> MISO pin on AVR). And you only need that 1k to 10k resistance on lines that will be driven by devices other than the AVR or the ISP, which is just MISO unless you have other SPI masters on the bus. \$\endgroup\$ – Mike DeSimone Sep 20 '11 at 16:21
  • \$\begingroup\$ Mike, will a 1K resistance not delay the signal by a large amount? And could you please elaborate on the buffers? If I remember correctly, a buffer will have a very large input impedence and a small output impedence. But what is the function of a buffer in this particular application? \$\endgroup\$ – Saad Sep 20 '11 at 18:31
4
\$\begingroup\$

I'm not quite sure how it manages to change so drastically from the first signal to the second (I think this is probably what Kevin was thinking) but the most likely problem sounds like a longish line and ringing. You can see some ringing on the first trace (almost 2V on a 3.3V line), which maybe will tell more of a story if you reduce the timebase. This might be causing some strange things to happen like the Rx pin picking up multiple transitions - may be even coupling to other traces and causing issues there.
The resistor will damp the ringing and fix things. The clock rate is not the issue, more the rise time of the signal.
You could shorten the lines (if that's an option), but it's good practice to have a small series resistor anyway.

\$\endgroup\$
  • \$\begingroup\$ Yes, the line is quite long. It's all on a breadboard for now but I'm going to shift onto a PCB in about two weeks. What resistor values would you recommend? Is this the only to fix ringing? Is there no way to prevent it from happening? \$\endgroup\$ – Saad Sep 20 '11 at 11:43
  • \$\begingroup\$ How long is the line? The breadboard might be contributing to issues, but it's hard to say exactly what's going on from the info. I think it will probably go away when you put it on the PCB, but leaving a series resistor in there (say 20-200 ohms) is a good idea anyway. Have a Google for termination and signal integrity. \$\endgroup\$ – Oli Glaser Sep 20 '11 at 12:03
  • \$\begingroup\$ I see you added the clock line in the pics - can you reduce the timebase and post that too? (i.e. "magnify" the intial rise of the signal, e.g. <1us/div) It should show any ringing in much more detail. \$\endgroup\$ – Oli Glaser Sep 20 '11 at 12:13
  • \$\begingroup\$ @OliGlasar I have attached the reduced timebase pictures. You were right - lots of ringing! \$\endgroup\$ – Saad Sep 20 '11 at 15:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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