SPI Maximum speed

yvesbazin
Posts: 2
Joined: Tue Feb 13, 2018 12:57 pm

SPI Maximum speed

Postby yvesbazin » Tue Feb 13, 2018 1:01 pm

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

ESP_Sprite
Posts: 9711
Joined: Thu Nov 26, 2015 4:08 am

Re: SPI Maximum speed

Postby ESP_Sprite » Wed Feb 14, 2018 5:30 am

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.

Xarlan
Posts: 12
Joined: Tue Jul 10, 2018 3:09 pm

Re: SPI Maximum speed

Postby Xarlan » Mon Jul 16, 2018 1:06 pm

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 52129 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

Xarlan
Posts: 12
Joined: Tue Jul 10, 2018 3:09 pm

Re: SPI Maximum speed

Postby Xarlan » Tue Jul 17, 2018 10:09 am

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 52108 times

User avatar
Vader_Mester
Posts: 300
Joined: Tue Dec 05, 2017 8:28 pm
Location: Hungary
Contact:

Re: SPI Maximum speed

Postby Vader_Mester » Tue Jul 17, 2018 12:29 pm

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.

Code: Select all

task_t coffeeTask()
{
	while(atWork){
		if(!xStreamBufferIsEmpty(mug)){
			coffeeDrink(mug);
		} else {
			xTaskCreate(sBrew, "brew", 9000, &mug, 1, NULL);
			xSemaphoreTake(sCoffeeRdy, portMAX_DELAY);
		}
	}
	vTaskDelete(NULL);
}

anakyr
Posts: 22
Joined: Fri Jun 15, 2018 12:09 pm

Re: SPI Maximum speed

Postby anakyr » Wed Oct 10, 2018 9:57 am

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?

User avatar
Vader_Mester
Posts: 300
Joined: Tue Dec 05, 2017 8:28 pm
Location: Hungary
Contact:

Re: SPI Maximum speed

Postby Vader_Mester » Wed Oct 10, 2018 10:00 am

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?

Code: Select all

task_t coffeeTask()
{
	while(atWork){
		if(!xStreamBufferIsEmpty(mug)){
			coffeeDrink(mug);
		} else {
			xTaskCreate(sBrew, "brew", 9000, &mug, 1, NULL);
			xSemaphoreTake(sCoffeeRdy, portMAX_DELAY);
		}
	}
	vTaskDelete(NULL);
}

anakyr
Posts: 22
Joined: Fri Jun 15, 2018 12:09 pm

Re: SPI Maximum speed

Postby anakyr » Wed Oct 10, 2018 10:45 am

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?

User avatar
Vader_Mester
Posts: 300
Joined: Tue Dec 05, 2017 8:28 pm
Location: Hungary
Contact:

Re: SPI Maximum speed

Postby Vader_Mester » Wed Oct 10, 2018 11:05 am

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.

Code: Select all

task_t coffeeTask()
{
	while(atWork){
		if(!xStreamBufferIsEmpty(mug)){
			coffeeDrink(mug);
		} else {
			xTaskCreate(sBrew, "brew", 9000, &mug, 1, NULL);
			xSemaphoreTake(sCoffeeRdy, portMAX_DELAY);
		}
	}
	vTaskDelete(NULL);
}

anakyr
Posts: 22
Joined: Fri Jun 15, 2018 12:09 pm

Re: SPI Maximum speed

Postby anakyr » Wed Oct 10, 2018 11:52 am

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 :)
Attachments
Capture.JPG
Capture.JPG (97.02 KiB) Viewed 51602 times

Who is online

Users browsing this forum: No registered users and 66 guests