Hardware SPI instability issues (vspi, hspi) - SS oscillating

All ESP32 boards running MicroPython.
Target audience: MicroPython users with an ESP32 board.
Post Reply
blark
Posts: 7
Joined: Fri Jan 10, 2020 3:08 pm

Hardware SPI instability issues (vspi, hspi) - SS oscillating

Post by blark » Fri Jan 10, 2020 3:34 pm

I am having issues with the hardware SPI on several boards running MicroPython. I've tried nightlies, 1.12 and 1.11 to see if this might be an issue related to a single firmware. The behavior is the same across all hardware and firmware versions. I've tested ESP-WROOM-32 modules from both Adafruit (Huzzah32) and a Wemos OLED board.

When I run SPI at 1Mhz things seem to be better (the issue is less pronounced but still present), however any speed above this (2MHz) and up I start encountering data transmission errors. The issues worsen with speed, at 80Mhz the SS line oscillates so bad it looks like the clock line.

Here's a shot from my oscilloscope with 80MHz SPI (yellow = SCK, cyan = SS). The ESP32 board is not on a breadboard, it's only hooked up to my scope, nothing else is attached.
Image
Link to screenshot just in case the image embed doesn't work https://imgur.com/a/ZzvEAb6


This is the code I'm using to send data. On the other side I have an STM32 slave that echos back received data (for testing purposes):

Code: Select all

from machine import Pin, SPI, freq
vspi = SPI(2, baudrate=1000000, polarity=0, phase=0, bits=16, firstbit=0, sck=Pin(18), mosi=Pin(23), miso=Pin(19))
hspi = SPI(1, 10000000, sck=Pin(14), mosi=Pin(13), miso=Pin(12))
ss = Pin(25, Pin.OUT, value=1)

def spi_send(send_bytes, channel='vspi'):
    send_bytes = send_bytes + b'\x00\x00'
    rec_buf = bytearray(len(send_bytes))
    ss.value(0)
    eval(channel).write_readinto(send_bytes, rec_buf)
    ss.value(1)
    return rec_buf if rec_buf[2:] == bytearray(send_bytes[:-2]) else ("ERROR", bytearray(send_bytes), rec_buf)
then to send data I do something like:

Code: Select all

spi_send(b'test')
I was hoping for someone else that has configured hspi or vspi to do 80Mhz to give me some feedback. Or someone that has a scope that can check if they are seeing the same issues as I am. I initially discovered this issue because I had my logic analyzer attached and saw the SS line flapping all over the place. Sure enough when I hooked up the scope, it was oscillating for some unknown reason.

Your feedback or insights would be appreciated! Thanks for the help.

User avatar
Roberthh
Posts: 1890
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: Hardware SPI instability issues (vspi, hspi) - SS oscillating

Post by Roberthh » Fri Jan 10, 2020 4:35 pm

I did also some measuring an took oscilloscope pictures. You'll find them here: https://hidrive.ionos.com/share/fjiz1v.-g2
There are two pictures at 10Mhz and 80MHz. They differ by Frequency and the type of GND connection of the probe.
SCLK is Yellow, SS is green. 200 MHz test probes set to 10:1.
"Sping-tip" is just the small GND spring that comes with the probe places a close as possible to signal to GND. "Gnd_cable" uses the short cable with crocodile clamp hooked over the USB connector (Solid GND). With the spring tip you see a good signal. With the GND cable you see some ringing, which is cause by the cable. At 80MHz, you see also some signal on the SS, which is just crosstalk between GND cables of the test probes. Since I have only a 200Mhz oscilloscope, the 80MHz signal capture is already somewhat limited by that.
So you see, at higher frequencies measuring is not just attaching a cable. You must at least use good test probes in 10:1 setting, take of the hook from the test probe and use very short GND cables for the probe.

I do not know what kind of test probes you used, but what you get on your oscilloscope is just noise.

blark
Posts: 7
Joined: Fri Jan 10, 2020 3:08 pm

Re: Hardware SPI instability issues (vspi, hspi) - SS oscillating

Post by blark » Fri Jan 10, 2020 4:46 pm

Awesome. It sounds like this is just a bad GND connection. I'm using the stock Rigol DS1054 probes with the Alligator style clips. I will do some research into what I can do to improve the accuracy of my readings. Thanks for the quick and thorough feedback!

blark
Posts: 7
Joined: Fri Jan 10, 2020 3:08 pm

Re: Hardware SPI instability issues (vspi, hspi) - SS oscillating

Post by blark » Fri Jan 10, 2020 5:04 pm

Wow! What a massive difference that spring clip makes (again yellow = SCK, cyan = SS)

Image

Again, thanks very much for the help on this. And for your patience with my n00b scope skills ;) Hopefully someone else with a similar issue might stumble across this and save a bunch of time!

User avatar
Roberthh
Posts: 1890
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: Hardware SPI instability issues (vspi, hspi) - SS oscillating

Post by Roberthh » Fri Jan 10, 2020 5:22 pm

Looks better, but the SCLK signal is still mess. You have to use the 10:1 setting of the probe. There might be a little switch close to the tip. The 1:1 setting is only good for low frequencies, like audio signals.
Edit: I see that you try 80MHz. With a 50 MHz oscillscope that's more or less the best you can get.

blark
Posts: 7
Joined: Fri Jan 10, 2020 3:08 pm

Re: Hardware SPI instability issues (vspi, hspi) - SS oscillating

Post by blark » Fri Jan 10, 2020 5:36 pm

Ahh, yes I was using 1x and I only used the spring clip on the SS line because I don't have 6 hands :lol:

I'll play around with 10x next as well, thanks very much!

Edit: yes, the scope goes down to 50MHz max when I use two channels. I have the DS1054Z with the 100MHz hack

Edit 2: 100Mhz and 10x probe. Looks pretty decent to me. Thanks for the help!
Image

Post Reply