Page 1 of 2

SPI Maximum speed

Posted: Tue Feb 13, 2018 1:01 pm
by yvesbazin
Dear all
I want to drive shift registers using SPI as fast as possible.
Using the native SPI pin I should be able to push data at 80Mhz
But it seems like I can't go faster than 5Mhz ?
Also changing duty_cycles doesn't have any effect.
Can someone help me
thank you

Regards
Yves

Re: SPI Maximum speed

Posted: Wed Feb 14, 2018 5:30 am
by ESP_Sprite
SPI is indeed perfectly capable of getting to 80MHz. It's pretty hard to find out why your implementation doesn't without knowing how exactly you set things up and measure speeds.

Re: SPI Maximum speed

Posted: Mon Jul 16, 2018 1:06 pm
by Xarlan
My result:
in case use HSPI & VSPI mapped like this:
HSPI_CLK = 14 or 25 GPIO
HSPI_MOSI = 13 or 26 GPIO
HSPI_MISO = 12 or 32 GPIO
HSPI_CS = 15 or 33 GPIO

VSPI_CLK = 18 or 21 GPIO
VSPI_MOSI = 23 or 22 GPIO
VSPI_MISO = 19 or 19 GPIO
VSPI_CS = 05 or 23 GPIO

the maximum speed of CLK is 9 MHz.
photo_2018-07-16_16-01-01.jpg
HSPI
CLK = 9MHz
photo_2018-07-16_16-01-01.jpg (81.06 KiB) Viewed 52845 times
However, when I use VSPI at CLK = 26MHz - it work correctly.
I connected ESP32 + 2xMAX3421E and try blik led, whic connected to MAX3421E's GPIO

Re: SPI Maximum speed

Posted: Tue Jul 17, 2018 10:09 am
by Xarlan
Well
CPU Frequency - 240MHz
Flash SPI speed - 80 MHz
At this moment - maximum stable frequensy of SPI = 18MHz.
(Send command and data to MAX3421E to blink led)
Perhups, the long wire don't allow setup SPI CLK more up
photo_2018-07-17_13-04-38.jpg
photo_2018-07-17_13-04-38.jpg (62.25 KiB) Viewed 52824 times

Re: SPI Maximum speed

Posted: Tue Jul 17, 2018 12:29 pm
by Vader_Mester
You should thoroughly check how you set up your SPI.
It is in fact capable of 80MHz.

Although several notes: Do not use long wires in this case. Make them as short as possible.
At 80MHz long wires will distort the SPI clock a lot, and impedance.

So when you measure the SPI clock, measure it as close to the GPIO pin as possible.

Re: SPI Maximum speed

Posted: Wed Oct 10, 2018 9:57 am
by anakyr
I am having the same issue, but probably has to do with the CPU frequency. I can measure SPI at maximum 26 MHz. When I set it at 40, my scope doesn't show any signals. How can I change the CPU frequency higher? Is the function included in one of the examples?

Re: SPI Maximum speed

Posted: Wed Oct 10, 2018 10:00 am
by Vader_Mester
anakyr wrote:I am having the same issue, but probably has to do with the CPU frequency. I can measure SPI at maximum 26 MHz. When I set it at 40, my scope doesn't show any signals. How can I change the CPU frequency higher? Is the function included in one of the examples?
SPI clock is independent of CPU clock. It is derived from APB_CLK which is the internal bus clock, and usually is 80MHz, and can not be adjusted.
What board do you use? Does your board has a 26MHz crystal, or a 40MHz crystal?

Re: SPI Maximum speed

Posted: Wed Oct 10, 2018 10:45 am
by anakyr
I am using ESP-WROOM-32D module on the devkitc. I see that the module has a 40 MHz crystal.
Then how can I verify what you say about the internal bus clock? Where is that located? Isn't that derived from the CPU's clock as well?

Re: SPI Maximum speed

Posted: Wed Oct 10, 2018 11:05 am
by Vader_Mester
anakyr wrote:I am using ESP-WROOM-32D module on the devkitc. I see that the module has a 40 MHz crystal.
Then how can I verify what you say about the internal bus clock? Where is that located? Isn't that derived from the CPU's clock as well?
Actually, I said a bit of bullsh*t above. The APB_CLK the SPI periferial is using is actually derived from the CPU clock.
(Technical reference manual, top of page 40).
APB_CLK is 80MHz, and SPI max clock is APBfreq/2, so 40MHz, with all other deviders set to default state.

Are you 100% sure that you in fact have a 26MHz clock on the module?
By default in Menuconfig you select 40MHz clock, which tells the rest of IDF that you run a 40MHz CPU, which will use it in it's calculations as reference, even though you may be having a different clock!
By setting 40MHz, it means - i guess - that almost all the clock deivders are set to their default state - eg. no clock devision - so it should be 40MHz coming out. Having no devision and 26MHz coming out suggest to me that in fact you have a 26MHz crystal on your module.

Maybe I'm wrong, but it's woth trying to work with clock register settings. (TRM Page 132 SPI_CLOCK_REG)
You can also try to use the formula on Page 121, to calculate the register values needed for 26MHz clock, and then read out the registers, to see if register settings are the same as you calculated.

Re: SPI Maximum speed

Posted: Wed Oct 10, 2018 11:52 am
by anakyr
I'm 100% sure that I have a 40MHz crystal. Check attachment too. I will try first to include SPI_DEVICE_NO_DUMMY in order to ignore this checking, as the error message in red is saying. If it doesn't work, I will go to the registers :)