cancel
Showing results for 
Search instead for 
Did you mean: 

SPI Protocol Polarity Issue " hspi2.Init.CLKPolarity "

SEROL.1
Associate

I set up a basic Master-Slave SPI communication interface from the STM32H750VBT to the STM32F7ZET MCUs in only one direction. And in this workspace I set my hspi2.Init.CLKPolarity configuration as SPI_POLARITY_LOW on both sides. And, as far as I know it is enough if we make the polarity same on both side either HIGH or LOW. However the communication occasionally get lost. After this happens I tried to change polarity as HIGH. And I suddenly saw that the communication was ok again. I was just like "Wow!" what is that now? Do i miss anything guys? I mean how it can be possible since everything is same such as electronics board and the software.

void MX_SPI2_Init(void)
{
 
  hspi2.Instance = SPI2;
  hspi2.Init.Mode = SPI_MODE_MASTER;
  hspi2.Init.Direction = SPI_DIRECTION_2LINES;
  hspi2.Init.DataSize = SPI_DATASIZE_8BIT;
  hspi2.Init.CLKPolarity = SPI_POLARITY_LOW;
  hspi2.Init.CLKPhase = SPI_PHASE_1EDGE;
  hspi2.Init.NSS = SPI_NSS_SOFT;
  hspi2.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_32;
  hspi2.Init.FirstBit = SPI_FIRSTBIT_MSB;
  hspi2.Init.TIMode = SPI_TIMODE_DISABLE;
  hspi2.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE;
  hspi2.Init.CRCPolynomial = 7;
  hspi2.Init.NSSPMode = SPI_NSS_PULSE_ENABLE;
  hspi2.Init.NSSPolarity = SPI_NSS_POLARITY_LOW;
  hspi2.Init.FifoThreshold = SPI_FIFO_THRESHOLD_01DATA;
  hspi2.Init.TxCRCInitializationPattern = SPI_CRC_INITIALIZATION_ALL_ZERO_PATTERN;
  hspi2.Init.RxCRCInitializationPattern = SPI_CRC_INITIALIZATION_ALL_ZERO_PATTERN;
  hspi2.Init.MasterSSIdleness = SPI_MASTER_SS_IDLENESS_00CYCLE;
  hspi2.Init.MasterInterDataIdleness = SPI_MASTER_INTERDATA_IDLENESS_00CYCLE;
  hspi2.Init.MasterReceiverAutoSusp = SPI_MASTER_RX_AUTOSUSP_DISABLE;
  hspi2.Init.MasterKeepIOState = SPI_MASTER_KEEP_IO_STATE_DISABLE;
  hspi2.Init.IOSwap = SPI_IO_SWAP_DISABLE;
  if (HAL_SPI_Init(&hspi2) != HAL_OK)
  {
//    Error_Handler();
  }
}

I will be very appreciated if you could help me about this problem asap.

Thanks in Advance.

I used the following initial parameters for the SPI bus

2 REPLIES 2
TDK
Guru

If CPHA and CPOL are the same, it should work. If they are different, it may or may not work, depending on the clock skew. Attach a logic analyzer to see what’s happening.

If you feel a post has answered your question, please click "Accept as Solution".

Hello Sir/Madam.

First of all, thank you so much for your reply.

As I mentioned above, we set CPHA and CPOL the same as one another. Besides all these I gotta mention the following as well, we've run into an interesting problem when doing the simultaneous SPI transfer using the DMA. We get an SPI overrun error. We've managed to track down the error but there is no clue for us so far.

Any ideas would be very helpful.

Thank you in advance,

-Serkan