cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F207 not working as SPI slave when NSS is configured in software mode.

DGupt
Associate III

Hello Guys

I am building a very simple application using CubeMX. 

I am using two STM32F207ZG boards to communicate with each other over SPI bus without DMA or interrupts.

One is acting as a master another as as slave.

The slave settings are as follows.

  hspi1.Instance = SPI1;
  hspi1.Init.Mode = SPI_MODE_SLAVE;
  hspi1.Init.Direction = SPI_DIRECTION_2LINES;
  hspi1.Init.DataSize = SPI_DATASIZE_8BIT;
  hspi1.Init.CLKPolarity = SPI_POLARITY_LOW;
  hspi1.Init.CLKPhase = SPI_PHASE_1EDGE;
  hspi1.Init.NSS = SPI_NSS_SOFT;
  hspi1.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_4;
  hspi1.Init.FirstBit = SPI_FIRSTBIT_MSB;
  hspi1.Init.TIMode = SPI_TIMODE_DISABLE;
  hspi1.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE;
  hspi1.Init.CRCPolynomial = 10;

The problem is i don't want to use NSS pin in hardware mode as it is being used for other purpose. If i configure NSS to be as software, i am missing one clock edge coming from the master and the slave is always stuck checking the TXE bit at the end of transmission inside HAL_SPI_TransmitReceive(....) function (because it is waiting for one more clock edge). i have verified it by sending 0xAA series from the master and the slave always receive 0x55.

/* Wait until TXE flag */
  if(SPI_WaitFlagStateUntilTimeout(hspi, SPI_FLAG_TXE, SET, Timeout, tickstart) != HAL_OK)
  {
    errorcode = HAL_TIMEOUT;
    goto error;
  }

But here if i reset the spi communication (i am resetting the controller), then surprisingly there after no problem in SPI communication.

Also if i put a CRO probe on the clock signal everything works fine.

I thought of capacitance issue but i have reduced the clock frequency to lowest possible but it didn't help, moreover i wonder if it would have been a problem with the capacitance why it would work after resetting the slave controller at the first place.

I would really appreciate if someone could please help me out of this issue.

Many thanks in advance. let me know if any other details are required

0 REPLIES 0