Page 1 of 1
Configuring SPI on STM32F4
Posted: Wed Sep 03, 2014 12:55 am
by hkerner
Hi there,
I'm using an STM32F417 and trying to configure SPI2. From the demos I have deduced that by default CPHA=0, CPOL=0, and MSB first are configured (please correct me if I''m wrong) but I still don't understand how to configure the baud rate. Previously using libopencm3 I set the baud rate to SPI_CR1_BAUDRATE_DIV_64 with a prescaler of 0xff. Can someone please help me with what is needed in the SPIConfig struct for this?
Thank you in advance!
Re: Configuring SPI on STM32F4
Posted: Wed Sep 03, 2014 1:49 am
by hkerner
Would I just pass in SPI_CR1_BR_0 | SPI_CR1_BR_1 | SPI_I2SPR_I2SDIV ?
Re: Configuring SPI on STM32F4
Posted: Wed Sep 03, 2014 2:12 am
by hkerner
I also need 8-bit DFF, but it looks like this is also default? i.e. including SPI_CR1_DFF in the config would result in 16bit? Thanks so much!!!
Re: Configuring SPI on STM32F4
Posted: Wed Sep 03, 2014 8:54 am
by Giovanni
Hi,
The mapping in the configuration structure is exactly equal to the CR1 SPI register as documented in the Reference Manual. You must use the bits exactly as documented.
So default is 8 bits, DFF is 16 bits and so on.
I2S-related bits MUST not be used.
Giovanni
Re: Configuring SPI on STM32F4
Posted: Wed Sep 03, 2014 7:12 pm
by hkerner
Hi Giovanni,
Thanks for the response. I don't see where this is documented in the reference manual -- could you please point me there? I am looking here:
http://chibios.sourceforge.net/html/group___s_p_i.htmlThanks so much!
Re: Configuring SPI on STM32F4
Posted: Wed Sep 03, 2014 7:51 pm
by Giovanni
Ah sorry, I was not clear enough in my answer.
You have to look into the STM32F4 Reference Manual, SPI chapter, CR1 register

Many drivers have register images into their configuration structure and must be setup according to the ST documentation.
Giovanni
Re: Configuring SPI on STM32F4
Posted: Wed Sep 03, 2014 10:16 pm
by hkerner
Found it! Thanks a ton