cancel
Showing results for 
Search instead for 
Did you mean: 

SPI Mode switching

ARORAPD
Visitor

Hi!

Can we switch the SPI Mode from Mode 1 to Mode 0 or vice versa in the same project ??

For eg. If I have set the SPI Mode to Mode 1 using my IOC which is required by one of my ICs but one of my ICs works on SPI Mode 0 so can I change the mode from Mode 1 to Mode 0 using the code only to control one IC.

Please reply ASAP!

Thanks

1 REPLY 1
Ghofrane GSOURI
ST Employee

Hello @ARORAPD 

Yes, you can switch the SPI mode (such as from Mode 1 to Mode 0) at runtime in your STM32 project, even if you initially set one mode in your IOC file. This is done by de-initializing the SPI peripheral with HAL_SPI_DeInit(), updating the CPOL and CPHA settings in your SPI handle to match the required mode, and then re-initializing the peripheral with HAL_SPI_Init(). However, you must ensure that no SPI transfer is in progress and only one device is selected at a time when switching modes. 

THX

Ghofrane

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.