Hardware SPI instability issues (vspi, hspi) - SS oscillating
Posted: 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.
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):
then to send data I do something like:
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.
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.
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)
Code: Select all
spi_send(b'test')
Your feedback or insights would be appreciated! Thanks for the help.