cancel
Showing results for 
Search instead for 
Did you mean: 

(solved) CPOL and CPHA inverse when using as slave only?

caco3
Associate II
Posted on September 29, 2015 at 15:32

I am using the STM32F4 as an SPI slave.

The signal is comming with LSB first, CPOL=0, CPHA=0. See image below, which shows the reception of 0x44: 0690X00000604mTQAQ.png Neverthe less, I seem to have to set CPOL=1, CPHA=1 to receive it correctly! With any other configuration, it gets parsed wrong. What is wrong? Below my configuration (as generated by STM32CubeMX:

hspi1.Instance = SPI1;
hspi1.Init.Mode = SPI_MODE_SLAVE;
hspi1.Init.Direction = SPI_DIRECTION_2LINES_RXONLY;
hspi1.Init.DataSize = SPI_DATASIZE_8BIT;
hspi1.Init.CLKPolarity = SPI_POLARITY_HIGH;
hspi1.Init.CLKPhase = SPI_PHASE_2EDGE;
hspi1.Init.NSS = SPI_NSS_SOFT;
hspi1.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_2;
hspi1.Init.FirstBit = SPI_FIRSTBIT_LSB;
hspi1.Init.TIMode = SPI_TIMODE_DISABLED;
hspi1.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLED;
hspi1.Init.CRCPolynomial = 10;
HAL_SPI_Init(&hspi1);

2 REPLIES 2
Posted on October 01, 2015 at 15:33

Hi CaCO3,

No all configurations give you correct data display, you have to respect this condition

''The idle state of SCK must correspond to the polarity selected in the SPI_CR1 register (by pulling up SCK if CPOL=1 or pulling down SCK if CPOL=0).''

 

as indicated in the page 869 ( Clock phase and clock polarity) of RM0090.

-Shahrzad-

caco3
Associate II
Posted on October 05, 2015 at 09:24

I did some further tests. It seems that the inputs are very sensitive to noise. If I shield the wires better and add a filter, it works much better.

Additionally, If I use a CS input (SPI_NSS_HARD_INPUT), it works without a problem.