-
Notifications
You must be signed in to change notification settings - Fork 7.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ESP32C3: SPI errors due to late MISO sampling #10917
Comments
Have you tried with SPI MODE 1 or 2? Looks like it should sample on the falling edge |
I haven't tried because the device is configured for MODE 0. The sampling should happen on the rising edge but it is obviously happening 27ns after. |
The point of sampling is done inside the hardware and can only be controlled by switching the mode. We do not have other way to influence it. I suggest you try another mode and see if that will make the device work |
Maybe, but if only in espidf. Arduino code does no low level code to control hardware. |
I suspect this might be a HW bug. Did/could someone from espressif validate the SPI hardware? |
I spent some more hours on this. It seems it all boils down to
My question now is, how this value should calculated? There is no mention in C3 TRM. Ideally, I would like to read 0x0 with 1 delay also on C3 and I feel this should be doable. |
There is no explanation for |
Ok, I think I understand the clock config now: clk_hclk -> [ clock divider by value SPI_CLKDIV_PRE ] - > [ timer ] -> CLK_OUT timer config:
Now these are the measured values with C3:
Now the ultimate question: Why does the sample delay changes with moving falling edge? It should be only related to rising edges in MODE0. |
Board
ESP32C3 super mini
Device Description
Qorvo DW1000 UWB module via SPI
Hardware Configuration
SPI running at 16Mhz
Version
v2.0.17
IDE Name
platformio
Operating System
Ubuntu
Flash frequency
no idea
PSRAM enabled
no
Upload speed
460800
Description
I noticed (often) random errors when reading from SPI when communicating with DW1000.
See attached screenshot:
Logic analyzer (PulseView) reads the value correctly (0xDC) but C3 does not (0x9C - highlighted in terminal).
Here you can see the MISO went down about 26ns after clock rise:
When I migrated the project from C3 to good old ESP32 all errors were gone.
So I prepared a test bed to find out the sampling delay (data latch-in after CLK rise).
It is a breadboard with a series of logical inverter pairs in 74AC04 package. Each inverter introduces about 4ns delay so 1 pair gives 8ns delay (detailed numbers on scope pictures). Then the signal is fed back to MISO and read by the module.
Now the results comparison for ESP32 and ESP32C3
Oscilloscope pictures follow. CH1 - CLKOUT, CH2 - MISO
Scope 1.:
Scope 2.:
Scope 3.:
From this data it is obvious that ESP32 samples data less than 9ns after clock rise. 👍
ESP32C3 samples data somewhere around 27ns after clock rise which explains why the bit from the module was read as 0.
The api reference explains some settings for sampling but how can this be configured from Arduino?
Sketch
Debug Message
Other Steps to Reproduce
No response
I have checked existing issues, online documentation and the Troubleshooting Guide
The text was updated successfully, but these errors were encountered: