cancel
Showing results for 
Search instead for 
Did you mean: 

STM32H7 SPI MOSI Signal changing before the CLK and observed the pulse

Suryaprakash
Associate II

STM32H7 SPI configured as Master with the Clock Phase and Clock Polarity 0 (mode 0).  During the HAL_SPI_TransmitReceive() call, before the CLK the pulse is observed on the MOSI signal. Due to this the slave device is behaving differently. Agree the slave device should consider the data w.r.t clock, but for some use cases, our slave doesn't expect any change in the MOSI signal.

We would like to know the workaround for this (i.e MOSI should toggle/change the state only w.r.t the clock).

Please find the picture shown for reference.

0693W00000QN5gRQAT.pngFollowing is the initialization part.

/**
  * @brief SPI6 Initialization Function
  * @param None
  * @retval None
  */
static void MX_SPI6_Init(void)
{
 
  /* USER CODE BEGIN SPI6_Init 0 */
 
  /* USER CODE END SPI6_Init 0 */
 
  /* USER CODE BEGIN SPI6_Init 1 */
 
  /* USER CODE END SPI6_Init 1 */
  /* SPI6 parameter configuration*/
  hspi6.Instance = SPI6;
  hspi6.Init.Mode = SPI_MODE_MASTER;
  hspi6.Init.Direction = SPI_DIRECTION_2LINES;
  hspi6.Init.DataSize = SPI_DATASIZE_8BIT;
  hspi6.Init.CLKPolarity = SPI_POLARITY_LOW;
  hspi6.Init.CLKPhase = SPI_PHASE_1EDGE;
  hspi6.Init.NSS = SPI_NSS_SOFT;
  hspi6.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_8;
  hspi6.Init.FirstBit = SPI_FIRSTBIT_MSB;
  hspi6.Init.TIMode = SPI_TIMODE_DISABLE;
  hspi6.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE;
  hspi6.Init.CRCPolynomial = 0x0;
  hspi6.Init.NSSPMode = SPI_NSS_PULSE_ENABLE;
  hspi6.Init.NSSPolarity = SPI_NSS_POLARITY_LOW;
  hspi6.Init.FifoThreshold = SPI_FIFO_THRESHOLD_01DATA;
  hspi6.Init.TxCRCInitializationPattern = SPI_CRC_INITIALIZATION_ALL_ZERO_PATTERN;
  hspi6.Init.RxCRCInitializationPattern = SPI_CRC_INITIALIZATION_ALL_ZERO_PATTERN;
  hspi6.Init.MasterSSIdleness = SPI_MASTER_SS_IDLENESS_00CYCLE;
  hspi6.Init.MasterInterDataIdleness = SPI_MASTER_INTERDATA_IDLENESS_00CYCLE;
  hspi6.Init.MasterReceiverAutoSusp = SPI_MASTER_RX_AUTOSUSP_DISABLE;
  hspi6.Init.MasterKeepIOState = SPI_MASTER_KEEP_IO_STATE_DISABLE;
  hspi6.Init.IOSwap = SPI_IO_SWAP_DISABLE;
  if (HAL_SPI_Init(&hspi6) != HAL_OK)
  {
    Error_Handler();
  }
  /* USER CODE BEGIN SPI6_Init 2 */
 
  /* USER CODE END SPI6_Init 2 */
 
}

2 REPLIES 2

As you said, SPI slave should sample MOSI at the SCK edge, and ignore any changes on MOSI elsewhere. The idle state of MOSI may be given by previously transmitted frame (first or last bit of it), but it's not documented, and also the initial state is not documented.

I may be wrong as you use 'H7 which has a different SPI module than other STM32, so even if I doubt it, maybe there is some documented way to do this in 'H7, read the SPI chapter in RM.

If not, the only workaround then is not to use the SPI module at all, and generate the waveform in other some way (bit-bang, generate "pwm pattern" using timer(s)/DMA, etc.).

JW

Thanks, Waclawek.jan for your suggestions.

I couldn't find any information related to this in RM.

Regarding the workaround, our system is not only generating the waveform, in parallel we also need to capture the data using the MISO line.

For more information, I am attaching the scope-captured pictures.

0693W00000QNaEYQA1.pngData transmitting on MISO line is 0x01, SPI Mode-3

0693W00000QNaEEQA1.pngData Transmitting on MOSI is 0x81, SPI Mode-3