2013-05-09 01:50 PM
We can initialize the SPI port clock polarity by :-
SPI_InitStruct.SPI_CPOL = SPI_CPOL_Low; SPI_InitStruct.SPI_CPHA = SPI_CPHA_1Edge; If we have several slaves connected to the SPI port, different slave operated using different clock polarity, is there any way to change those 2 parameters easily without using the above method again? Thanks. #stm32f4-spi-cpol-cpha2013-05-09 11:55 PM
You can write to the SPI_CR1 register to directly change the CPOL/CPHA bits but note that prior to changing the CPOL/CPHA bits the SPI must be disabled by resetting the SPE bit.
I use multiple SPI devices with different configurations and simply call the functions to re-initialise the SPI before selecting a device. You probably will need to be handling the slave select (device CS_N) lines in software anyway. It's all quite fast! Alternatively, use multiple SPIs with each set for a particular configuration.2013-05-10 09:13 AM
''is there any way to change those 2 SPI parameters easily?''
Forgive - but coming from past, dark days - when we changed parameters w/xacto-blade, wire-cutter, soldering iron - just how much easier can life get? As responding poster notes - conserving MCU pins forces you to alter some aspects of SPI config. Multiple SPI employment may enable ''just once'' set-up/config - at the cost of additional pin usage... Did think of one old, HW method - to achieve your desire. Simple inverter would be added - fed by SPI clock. Then both ''normal clock'' and new, ''inverted clock'' feed a data selector IC - which is controlled by single GPIO. Now - via toggle of that GPIO - normal or inverted clock - at your SW command... (with a little help from HW add-on)