Skip to main content
sdianoff
Associate II
April 6, 2021
Solved

SPI CPHA affects NSS

  • April 6, 2021
  • 3 replies
  • 1323 views

I use MCU STM32L462ET6TR. When I set CPHA=1, the NSS signal is always at low. When CPHA=0, NSS signal works normally. There is my initialization code:

void MX_SPI1_Init(void)
{
 hspi1.Instance = SPI1;
 hspi1.Init.Mode = SPI_MODE_MASTER;
 hspi1.Init.Direction = SPI_DIRECTION_2LINES;
 hspi1.Init.DataSize = SPI_DATASIZE_8BIT;
 hspi1.Init.CLKPolarity = SPI_POLARITY_LOW;
 hspi1.Init.CLKPhase = SPI_PHASE_1EDGE; // NSS SIGNAL WORKS NORMALLY
// hspi1.Init.CLKPhase = SPI_PHASE_2EDGE; // NSS SIGNAL DOESN'T WORK
 hspi1.Init.NSS = SPI_NSS_HARD_OUTPUT;
 hspi1.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_16;
 hspi1.Init.FirstBit = SPI_FIRSTBIT_MSB;
 hspi1.Init.TIMode = SPI_TIMODE_DISABLE;
 hspi1.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE;
 hspi1.Init.CRCPolynomial = 7;
 hspi1.Init.CRCLength = SPI_CRC_LENGTH_DATASIZE;
 hspi1.Init.NSSPMode = SPI_NSS_PULSE_ENABLE;
 if (HAL_SPI_Init(&hspi1) != HAL_OK)
 {
 Error_Handler();
 }
}

Why CPHA bit affects the NSS signal?

This topic has been closed for replies.
Best answer by waclawek.jan

This is how ST decided to implement the NSS Pulsed feature, see NSS pulse mode subchapter in RM:

This mode is activated by the NSSP bit in the SPIx_CR2 register and it takes effect only if 

the SPI interface is configured as Motorola SPI master (FRF=0) with capture on the first 

edge (SPIx_CR1 CPHA = 0, CPOL setting is ignored).

JW

3 replies

waclawek.jan
waclawek.janBest answer
Super User
April 6, 2021

This is how ST decided to implement the NSS Pulsed feature, see NSS pulse mode subchapter in RM:

This mode is activated by the NSSP bit in the SPIx_CR2 register and it takes effect only if 

the SPI interface is configured as Motorola SPI master (FRF=0) with capture on the first 

edge (SPIx_CR1 CPHA = 0, CPOL setting is ignored).

JW

sdianoff
sdianoffAuthor
Associate II
April 7, 2021

Yes, thank you.

Functions HAL_SPI_Transmit and HAL_SPI_Receive doesn't set SPI disable, so that NSS doesn't go up to high. This is my mistake.

waclawek.jan
Super User
April 7, 2021

Note, that SPI disable does not pull NSS high; rather, it stops controlling the pin from SPI module and NSS pin goes effectively threestate. If you want it to go high, you have to switch on a pullup, or re-enable SPI immediately after disabling it.

JW