cancel
Showing results for 
Search instead for 
Did you mean: 

Running SPI at 2MHz

iduffy
Associate II
Posted on May 15, 2013 at 23:21

I've got an STM32F407 with main clock set to 168MHz and am communicating with a slave device over SPI2. The SPI on the slave can work up to 2MHz and I would like to get as close to this as I can.

As far as I can tell, the SPI2 clock has to be a power-of-two divisor of the APB1 which in turn is a power-of-two divisor of the main clock. The closest I can get is therefore approx 1.3MHz.

Counter intuitively I'm coming to the conclusion that to communicate at 2MHz I need to slow the system clock down to 128MHz. Firstly, is this right, or am I missing something? Secondly, does changing the system clock speed open up a can of worms that I need to be aware of? (I'm also using USB FS so presumably that would be affected).

#stm32f4xx-spi-clock
4 REPLIES 4
Posted on May 16, 2013 at 00:58

Unfortunately ST has a history of making pretty sorry decisions when it comes to clocking schemes and prescaler/divider chains.

Yes, you're going to be in a bit of a bind. The USB needs a 48 MHz clock from the primary PLL's VCO Q divider tap. Which kind of means your processor is going to have to run at a multiple of 24 MHz. The I2S has it's own PLL, would have been helpful to be able to have gated that to USB, or whatever.

You'll have to play some games, and I don't think you'll find a particularly good fit. 120 MHz would give you USB, and SPI at 1.875 MHz
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
iduffy
Associate II
Posted on May 16, 2013 at 08:47

Thanks for your comments. Running at 120MHz is possibly an option, I'm still working on the rest of the code and don't yet know if I have the processor speed to spare.

I was hoping I was missing something but clearly not :(
Posted on May 16, 2013 at 09:15

I believe that some of the SPI-connected devices could actually run with the SPI module used in I2S mode, with the luxury of having an extra PLL.

Another option mentioned recently by Clive might be to generate clock from a timer and use SPI in slave mode.

Both would need a bit of thinking and experimenting.

JW

zzdz2
Associate II
Posted on May 16, 2013 at 11:32

Are you sure the slave can only handle 2 MHz, it seems somewhat slow, maybe they meant 250kB/s and the actual SPI clock can be faster.