ESP32: Cannot make HSPI work faster than 8MHz clock - Page 1
Forum section: electronics / general

author: rglory
author_rank: Contributor
timestamp: May 02, 2021, 06:42:27 pm
content: Hi there,I am trying to make ESP32-CAM to stream video over ethernet, using ENC28J60 over SPI. I tried to use couple libraries, managed to make UIPEthernet work, but very very slow. So I decided to write my own simple implementation of IP/UDP stack. So far it works but I realized that if I try to use SPI freq higher than 8MHz I am getting data corruption. I am using HSPI with default pins. Is there limit for HSPI or I am missing something?ThanksPS I found this topichttps://www.esp32.com/viewtopic.php?t=4688#:~:text=It%20is%20in%20fact%20capable,clock%20a%20lot%2C%20and%20impedance.which says:QuoteSo is it hardware limitation on HSPI interface?PS sorry if offtopic, is this espressif company always that unfriendly? I tried to download their app to select ST23 chip - STM32Cube - it is convoluted process made so just so you cannot download it without registration. I can register fine but it does not work, so program which is in their interest to share is difficult to get. I tried to ask this question on their forum - it stays more than 24 hour for premoderation. I asked if it always so and they do not care about new people - they simply deleted my topic. Price for their devices is quite nice, but such attitude can easily compensate that.

author: pigrew
author_rank: Frequent Contributor
timestamp: May 02, 2021, 08:56:34 pm
content: Your title shows STM32, so I started to think about them, but I think you're actually using an ESP32?With the default pins (and good PCB layout), you should be able to get up to 80 MHz, or 40 MHz with the pin mux involved (according to the ESP-IDF documentation). I have not done it, but it should work.It'd also be helpful for you to post a photo of your test setup.Since I don't know many details of your setup, these are the things I'd first investigate. It's likely you are running into signal integrity issues.Do you have good signal signal transmission lines/GND? You should have a GND net in parallel to your signal lines.Maybe you need series termination resistors. Add a 22 or 33 ohm resistor in series to your signal line, close to the OUTPUT pin.Is your clock polarity set properly? Confirm with an oscilloscope that the polarity of your clock is consistent with the Ethernet IC's datasheet.Do you have a passive oscilloscope probe connected to your data or clock nets? If so, their extra 15 pF load can cause issues.Do you have sufficient decoupling capacitors close to your ESP32 and SPI device power pins?Use an active oscilloscope probe if you need to debug SI issues. Your oscilloscope preferably would have bandwidth >10 your clock rate. A logic analyzer (with low capacitance probes) could also be helpful.

author: rglory
author_rank: Contributor
timestamp: May 02, 2021, 09:26:22 pm
content: Quote from: pigrew on May 02, 2021, 08:56:34 pmUps, sorry, I've been playing with AVR and arduino before, so these names are new for me, so I get confused, fixed.QuoteI use already made PCBs:ESP32-CAM I guess it is AI-Thinker variant:https://randomnerdtutorials.com/esp32-cam-ai-thinker-pinout/HiLetgo ENC28J60 ENC28J60-I/SO HR911105A Ethernet LAN Network Module -https://www.amazon.com/gp/product/B00WX1NRO0/ref=ppx_yo_dt_b_search_asin_title?ie=UTF8&psc=1So I guess I do not have much choice on how good would be PCB Layout.QuoteI have quite a mess on my table, but here it isQuoteGround connected through breadboard, where both PCBs gets power from.I will try resistors.Main thing disturbs me - I had them connected through breadboard, so I first thought about cables too. I connect them directly and no difference at all. If cables would be issue I could expect work 8MHz first case and maybe 10MHz on another, but no, it just works pretty well on 8 and works very bad - either hangs or a lot of errors on faster. And on topic I that person mentioned he also clains that HSPI cannot work faster than 9MHz.

author: pigrew
author_rank: Frequent Contributor
timestamp: May 02, 2021, 10:42:26 pm
content: The layout of that Ethernet module looks marginal. I would definitely try connecting the GND directly (without the breadboard), or route everything through the breadboard. How it is in the photo creates a large loop in the signal return path.You are also operating somewhat close to the limits of those chips as you get closer to 20 MHz.You want SPI mode 0. If you do 20 MHz, that's 50 ns per clock cycle. The controller outputs MOSI <10ns after the clocks falling edge. You're using the "IO mux pins" (the "default ones").The ESP-IDF documentation states aFreq limit  = 80 / (floor(MISO delay/12.5) + 1). In your case the MISO delay would be (positive duration of the clock)+(10ns)+(a bit more, perhaps 10 ns?). With a symmetrical clock, this would be 20 MHz. So, it should work. You might be able to make the timing converge better if you use an asymmetric clock (with HIGH perhaps 25% of the clock period).The ESP-IDF suggests that you also set the input_delay_ns parameter for your SPI config if you try to use >8MHz. I'd set it to (15ns + CLK_HIGH_TIME).

author: rglory
author_rank: Contributor
timestamp: May 03, 2021, 03:49:13 pm
content: Quote from: pigrew on May 02, 2021, 10:42:26 pmThat's where I started, connection was through breadboard, I thought maybe wires are too long plus breadboard has some parasitic capacity, so connected directly.QuoteYea, but it is less than a half, not even closeQuoteWill try thanks, though it is not too easy as I am using rduino framework and SPIClass interface, and those things not exposed directly.The thing is - even on 8MHz on oscilloscope signal looks like analog, not digital. Similar way it was shown on the link I posted before.Another thing on schematic you can see that those pins for HSPI also connected to SD Card module. That should not affecte them if there is no card inserted, should it?https://www.reddit.com/r/esp32/comments/b6wyjt/aithinker_esp32cam_schematic/

author: pigrew
author_rank: Frequent Contributor
timestamp: May 04, 2021, 12:50:53 am
content: Quote from: rglory on May 03, 2021, 03:49:13 pmI'll assume that you have a <15pF probe and >100 MHz oscilloscope. It should look a bit better than that other post.Another trick you could try (if your framework supports it) is to increase the pin drive strength (the ESP-IDF function isgpio_set_drive_capability(...)). With higher drive strength, it'll decrease the fall and rise times, but would be more likely to "ring".I tend to suggest giving priority to making sure that your GND runs roughly parallel to your signal wires, leaving shortening wires as a secondary goal.I probably should grab a ESP32 and see how it looks over here, and measure rise-fall times....

author: rglory
author_rank: Contributor
timestamp: May 04, 2021, 09:18:21 pm
content: Quote from: pigrew on May 04, 2021, 12:50:53 amNo, I do notLittle bit expensive toy for a hobby project.Quote from: pigrewWill try, thanks, but it looks like more and more that it would be easier to use raspberry PI instead, it has camera and ethernet interface already, and I can use gpio to control LEDs. I thought it would be not bad idea to use this one as it is quite cheap and functional but underestimated luck of support...