Skip to main content
Associate II
Jan 22, 2025 7:30 PM UTC
Question

SPI NSS configuration in STM32H753 custom board

I have the main MCU serving as the master in the spi communication whose primary job is to transmit data over SPI lines to two slaves. If I choose hardware NSS signal configuration the IOC file assigns a default pin as the NSS signal for that SPIx peripheral. I have a basic doubt as to whether it is better for me to do Software or Hardware NSS signal? If I choose hardware NSS signal the default pin can serve as CS for just one slave, how can I have multiple CS working with SPI bus, should I just GPIOs as the NSS signal lines? Or do it with Software NSS signals if so how is it done? I have not yet worked with SPI on STM32, only with Arduino so have no idea what is happening? The manual is a bit intimidating rn.

This topic has been closed for replies.

3 replies

JBias
Associate III
Jan 22, 2025 11:00 PM UTC

You are correct with using two separate signals for each CS and not using the hardware NSS line option (built into the SPI hardware)  So, you will be using a software command to turn on the CS  -- do the SPI transfer -- then a software command to turn off the CS. It would be something like this:

JBias_0-1737586445712.png

 

hvs_learnAuthor
Associate II
Jan 23, 2025 10:35 AM UTC

So my code would look like this? if I want to send the same data to 2 slaves?
HAL_GPIO_WritePin(Module1_GPIO_PORT, MODULE1_Pin, GPIO_PIN_RESET);

rst = (HAL_SPI_Transmit(&hspi4, TxData, Size, Timeout);

HAL_GPIO_WritePin(Module1_GPIO_PORT, MODULE1_Pin, GPIO_PIN_SET);

HAL_GPIO_WritePin(Module2_GPIO_PORT, MODULE2_Pin, GPIO_PIN_RESET);

rst = (HAL_SPI_Transmit(&hspi4, TxData, Size, Timeout);

HAL_GPIO_WritePin(Module2_GPIO_PORT, MODULE2_Pin, GPIO_PIN_SET);

JBias
Associate III
Jan 25, 2025 12:43 AM UTC

Yes, you got it.