6
\$\begingroup\$

I've just started learning this material not too long ago and need some help. I'm trying to communicate with SPI from an AD7124-4 ADC IC to an ESP32.

The first problem I'm having is I'm getting a lot of ringing on the square waves which is shown in the photo on an oscilloscope. The ringing is about 1V and greater than 2V on the top signal and I believe it is interfering with the high and low signals, causing read errors. I've already compensated all four probes perfectly. See the schematic and also pic of the circuit on a breadboard (disregard parts not seen in the schematic) if anything stands out. Any ideas on what may be causing the ringing or how to fix? I'm using x10 probe and settings on the scope are for x10. I've set the SPI settings on the scope according to the manual (correctly I think). Everything looks great on all solder connections and the chip flashes just fine.

enter image description here

enter image description here

EDIT: I realized I didn't have the decoupling caps on the AVDD and IOVDD. Here is the schematic from the circuit note CN0381.

enter image description here

enter image description here

The second problem is the logic levels don't seem the correct voltage.

-------------------------

I have wired as follows:

ADC ---- ESP32


DIN --> MISO

DOUT --> MOSI

SCLK --> SPICLK

CS# --> SPICS

-------------------------

On the oscilloscope:

PROBE 1 -> MISO PROBE 2 -> MOSI PROBE 3 -> CLK PROBE 4 -> CS

-------------------------

On the ADC:

IOVDD = 3.3V

LOGIC INPUTS: LOW = 0.35 × IOVDD HIGH = 0.7 × IOVDD

LOGIC OUTPUTS: LOW (MAX) = 0.4V HIGH (MIN) = IOVDD − 0.35

-------------------------

On the ESP32: VDD = 3.3V

LOGIC LEVELS:

LOW = 0.25 * 3.3 = 0.825V

HIGH = 0.75 * 3.3 = 2.475V

-------------------------

I have 3.3V powering the ESP32 and the ADC so the logic levels should match I would assume according to specs, but why are MOSI and CS lower than the other 2? And MOSI and CS are also look like they are on 4 different levels which is not good at all I would guess. All probes are at 2V / division. I'm trying to decode the signal also on a Siglent SDS 1104X-E but the signals don't look readable yet. Thanks and I would really appreciate any help or suggestions.

======================================================================

EDIT: Well I got the levels right, I had the CS on the wrong (non SPI) pin and I swapped the MISO and MOSI, I mistakenly thought the docs said that ESP32 was a full time slave (I realize it doesn't make sense now). Here are some screen shots:

enter image description here

enter image description here

enter image description here

You can see that the length of the whole communication chain varies at different readings on the same time scale, that doesn't seem right but I'm new to SPI.

I used a dev kit ESP32 board instead of using the ESP32 mounted on a breakout board and the noise seems low enough to work correctly, I tried twisting grounds around the signal wires and it helped but not a whole lot. Here's the pic.

enter image description here

But still can't get it talking correctly, I'm using this code: https://github.com/epsilonrt/ad7124/tree/master/examples/ad7124-thermometer

In the debug output it just prints "FAIL". I've successfully used ESP32 for UART and I2C but not with SPI yet. Any more ideas or pointers? My main goal again is just to successfully read the signals and I'll clean them up after that.

==============================================

FINAL EDIT: I got it working finally, I could only get the SPI working with the AD7124 library when using this line of code in the setup() function:

SPI.setClockDivider(SPI_CLOCK_DIV4);

And it would only work using CLOCK_DIV4 or CLOCK_DIV2, no other speeds would work. Here's a scope shot of CLOCK_DIV64 which did not work:

enter image description here

The signals look pretty clean but could not communicate properly over SPI. Here's a scope shot of CLOCK_DIV2:

enter image description here

It was a bit noisier but worked. I believe If I'm counting right, the DIV64 signal is about 260KHz and the DIV2 signal is about 4MHz, it says in the ESP32 datasheet that default SPI speed is 80MHz so I don't know how dividing that by 2 gets 4MHz. The pic might have been from DIV4, don't remember. But 4MHz is the default speed on Arduino and I tried the AD7124 code on an Arduino Pro Mini and it worked great with no changes to the code.

I also got rid of the long SPI transmission lines and the noise went right away. Also in the first scope shots at the top, you can see the noise on the yellow trace is much worse and that wire is longer than the others and wraps to the other side of the board. Twisting with a ground wire did help and reduced noise by about 20% but it was still bad. Also switched to an ESP32 dev kit board instead of the breakout board which had longer wires connecting it to the breadboard (I just didn't have the right length with the connector ends needed). Here's the new setup:

enter image description here

But anyhow I was pretty happy to get it working and thanks to all for the help.

\$\endgroup\$
  • \$\begingroup\$ What speed are you running your SPI at? You could try adding series termination resistors as as close as possible to the TRANSMITTER on each line. The exact value depends on your impedances. Maybe try 50 ohms. Experiment. \$\endgroup\$ – DKNguyen Jun 19 at 23:07
  • \$\begingroup\$ This doesn't address the strange logic levels, but the overshoot might be an artifact of the o-scope probes' ground connections. Please see this question. Also, breadboards are, by their nature, fairly capacitive. This might limit your signalling rates, but it wouldn't explain the logic level issues... Finally, if the ringing is actually a problem, you may be able to slow down the slew rates (not the signalling rates) of the SPI master. I don't know if the ESP32 has this functionality; many microcontrollers have configurable slew rates. \$\endgroup\$ – bitsmack Jun 19 at 23:25
  • \$\begingroup\$ Channels 1 & 3 look reasonable given the setup and instrumentation. Try physically moving the scope wires around. If the ringing/spikes change that is a good indication that they aren't real. Channels 2 & 4 are horrible, they look similar, maybe they are shorted together. \$\endgroup\$ – Mattman944 Jun 19 at 23:26
  • \$\begingroup\$ Here's a video showing the screen on the scope, looks like something is off with the timing: youtu.be/5QDIPUyNdOA As far as SPI speed, it seems to me that the ESP32 is hard set at 80MHz and can't be adjusted unless programmed using custom external libraries. Bullet point from the data sheet... "is Up to 80 MHz (The actual speed it can reach depends on the selected pads, PCB tracing, peripheral characteristics, etc.)" but I found nothing on adjusting the speed. \$\endgroup\$ – wdbwbd1 Jun 20 at 1:23
  • \$\begingroup\$ As far the concern about channel 2 and 4 being shorted together, none of the pins on the ADC chip are shorted when tested with a mulimeter. I tried switching the probes between signals and it made no difference. I'll try some resistors on each line as suggested but can't try until later. \$\endgroup\$ – wdbwbd1 Jun 20 at 1:23
4
\$\begingroup\$
ADC ---- ESP32
DIN  --> MISO
DOUT --> MOSI
SCLK --> SPICLK
CS#  --> SPICS

This is part of your problem -- "DIN" on the ADC means data into the ADC. "MISO" means master in, slave out (or it's a kind of soup) -- if you've got the processor configured as master, then you've got input to input and output to output (DOUT --> MOSI).

Also, you need to provide a decent ground return for the SPI signals, and you're getting cross-talk between your clock and the other signals. I can't see from your scope shot what the time base is set to, but you're not providing much of any ground return for the SPI, much less a good one.

Get your innies and outies matched up correctly: make sure inputs go to inputs, and outputs to outputs (and double-check -- getting serial connections hooked up out to out and in to in always seems to happen).

Then make a ground return for each SPI line. You should be able to get away with twisting each SPI line with a ground wire. Do this for each wire carrying SPI between the controller and the ADC. You want an extra ground wire twisted with the original wire (and connected to GND on each side). This may seem excessive, but for high-speed signals it is not. Start there, and let us know how it works. (Next steps are twisted pair taking care to make the twist lengths different, and after that try to find some high-impedance coax -- that's probably unnecessary, though).

\$\endgroup\$
  • \$\begingroup\$ I'll have to look into how to configure master/slave but I switched the connections between MISO and MOSI and the yellow channel 1 was a all low signal after that and all signals were garbled some. And I don't understand how to perform the grounding mods you suggested, I have each alligator clip on an individual ground lead coming off the ground rail. This isn't a ground for each channel? I also posted a video link in the response above \$\endgroup\$ – wdbwbd1 Jun 20 at 1:24
  • 1
    \$\begingroup\$ What @TimWescott probably meant is to use for each SPI connection between the controller and the ADC an extra ground wire twisted with the original wire (and connected to GND on each side). You may say "but the ground is already connected somewhere else". This is actually important to improve the signal integrity problem you have. \$\endgroup\$ – joribama Jun 20 at 1:59
  • \$\begingroup\$ In your schematic I don't see decoupling capacitors on your logic supplies next to the controller (3V3 pin) and ADC (IOVDD, AVDD pins). I would add a 0.1uF capacitors between each of those pins and the GND pin of the part. Keep the leads short and solder them directly on the PCB instead of placing them on the breadboard. It's also not a good idea to connect IOVDD and AVDD together as you did, but this is the smallest of your problems at this point. \$\endgroup\$ – joribama Jun 20 at 2:04
  • \$\begingroup\$ And I'll try the decoupling caps, in the main post I updated with a photo of the original schematic I followed in the CN0381 circuit note which didn't mention to use any. Thanks for the clarification on the twisted wires, I'll give it a shot but I'll have to wait until tomorrow. \$\endgroup\$ – wdbwbd1 Jun 20 at 2:51
  • 2
    \$\begingroup\$ "And I'll try the decoupling caps" -- always use decoupling caps. Decoupling caps are left off of schematics the way that "put on your cloths" is left out of instructions that start with "go to the store". You just do it, always. \$\endgroup\$ – TimWescott Jun 20 at 15:21
0
\$\begingroup\$

Spikes could be due to Oscilloscopes ground clip wire length as well. Check that 1st. Also check your power supply to the CHip, if it getting bounced, you need to provide proper decoupling at the CHIP VCC.

\$\endgroup\$
0
\$\begingroup\$

New answer, because I think you have the signal integrity and connection problems fixed.

At this point in the process, I would be carefully comparing the bits going by on the scope with the ADC data sheet. You're running this through driver code, which complicates things -- but I suspect that you're just not "telling" the ADC the right thing.

You should also carefully review the SPI mode and polarity. Everyone does their SPI a bit different, basically involving the polarity of the clock and the relative timing of clock and data. You need to check the ADC data sheet, and make sure that the processor is set up to match.

\$\endgroup\$
  • \$\begingroup\$ Yes I believe you're right, I've gotten the SPI parameters I need from the ADC datasheet, now I'm trying to work the ESP32 Arduino core SPI code into the AD7124 code from the link I gave at the bottom of the main post so I can modify the parameters. Might take me a while but I'll report back, thanks. \$\endgroup\$ – wdbwbd1 Jun 22 at 2:20
  • \$\begingroup\$ So the library I'm using for the ADC is designed for an Arduino board which has a default SPI clock speed of 4MHz, the max limit for the ADC is 5MHz so it will work. But the ESP32 default speed is 80MHz and I tried to use the code to set the clock speed from the ESP32 library and it froze the ADC code. So that was definitely causing errors in the timing, I'll have to try to make the code work somehow. \$\endgroup\$ – wdbwbd1 Jun 22 at 5:03
0
\$\begingroup\$

watch out for the terminations, you don't seem to have termination resistors in place, also, you have a lot of crosstalk, not just ringing, if you are using long wires to connect an spi bus i would suggest you put 2 ground wires on the sides of the clock line

\$\endgroup\$

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.