Question
Resetting SCLK polarity after changing SPI mode through HAL (STM32F7xx)
We're developing for the STM32F767, primarily using the HAL. We have devices on the SPI bus which require different timing clock polarities. Re-configuring the SPI hardware through repeated calls to HAL_SPI_Init works, however, the actual hardware state of the SCLK line does not seem to change during HAL_SPI_Init .... we are only able to get it to reset by clocking out a byte. What's the "right" way to force the SCLK line to the correct polarity?
In pseudo-code, this works, but is obviously ugly:
SpiHandle.Init.CLKPolarity = SPI_POLARITY_HIGH;
HAL_SPI_Init(&SpiHandle);
// Expect SCLK to be high
// (successfully communicate with devices expecting SCLK to idle high)
SpiHandle.Init.CLKPolarity = SPI_POLARITY_LOW;
HAL_SPI_Init(&SpiHandle);
// !! Expect SCLK to be low, it is actually still high
// Sending a "null" transmission resets clock
char txBuffer[1] = '\0';
HAL_SPI_Transmit(&SpiHandle, txBuffer, 1, SPITimeout );
// !!! SCLK is now low
// (successful communication with devices expecting SCLK to idle low)