SPI1 and SPI2 speed

Generic boards that are not Maple or Maple mini clones, and don't contain the additional USB reset hardware
Post Reply
michael_l
Posts: 367
Joined: Mon Aug 24, 2015 6:11 pm

SPI1 and SPI2 speed

Post by michael_l » Thu Oct 27, 2016 12:30 pm

What's the default speed for SPI1 and SPI2 ?

How can I change the speed of SPI2 to, say, 8MHZ ? Thanks.

User avatar
Vassilis
Posts: 336
Joined: Thu May 21, 2015 6:42 am
Location: Thessaloniki, Greece
Contact:

Re: SPI1 and SPI2 speed

Post by Vassilis » Thu Oct 27, 2016 5:58 pm

The SPI1 works on APB2 (72 MHz). The maximum frequency that works the SPI1 is 72/2 =36 MHZ.
The SPI2 works on APB1 (36 MHz). The maximum frequency that works the SPI2 is 36/2 =18 MHZ.

You can use the setClockDivider(select_divider) function to reduce the SPI clock

The available dividers are:

Code: Select all

SPI_CLOCK_DIV2
SPI_CLOCK_DIV4
SPI_CLOCK_DIV8
SPI_CLOCK_DIV16
SPI_CLOCK_DIV32
SPI_CLOCK_DIV64
SPI_CLOCK_DIV128
SPI_CLOCK_DIV256
Using the SPI1 at 4.5MHz:

Code: Select all

SPI.setClockDivider(SPI_CLOCK_DIV16); // (72 MHz / 16 = 4.5MHz)
Using the SPI2 at 4.5MHz:

Code: Select all

SPIClass SPI_2(2); //Create an instance of the SPI Class called SPI_2 that uses the 2nd SPI Port
...
...
SPI_2.setClockDivider(SPI_CLOCK_DIV8);  // (36 MHz / 8 = 4.5MHz)
I hope it helps!

Ollie
Posts: 205
Joined: Thu Feb 25, 2016 7:27 pm

Re: SPI1 and SPI2 speed

Post by Ollie » Thu Oct 27, 2016 11:17 pm

With those higher speeds, you should design the software structure properly for time critical applications. My recommendation is to use interrupts for the SPI address and command data and after that DMA for the bulk data transfer.

Cheers, Ollie

michael_l
Posts: 367
Joined: Mon Aug 24, 2015 6:11 pm

Re: SPI1 and SPI2 speed

Post by michael_l » Fri Oct 28, 2016 6:37 am

Thanks for help!

I'm also looking for examples on how to use SPISettings "correctly" for sharing the same bus between several devices.

EDIT: found something here http://www.dorkbotpdx.org/blog/paul/bet ... in_3_steps

So the idea here seems to be that transaction support is done into the library and library contains SPISettings.

ted
Posts: 62
Joined: Sun Jul 16, 2017 9:57 pm

Re: SPI1 and SPI2 speed

Post by ted » Mon Jan 01, 2018 1:34 am

It is possible to divide by 100 ?

victor_pv
Posts: 1864
Joined: Mon Apr 27, 2015 12:12 pm

Re: SPI1 and SPI2 speed

Post by victor_pv » Mon Jan 01, 2018 8:03 pm

ted wrote:
Mon Jan 01, 2018 1:34 am
It is possible to divide by 100 ?
No. the dividers are the ones listed in Vasilis post. That's a hardware setting.

Post Reply