cancel
Showing results for 
Search instead for 
Did you mean: 

NSS pin (chip select) driven by hardware.

LOliv
Associate II

Good morning.

I'm trying to use SPI communication on STM32L051 MCU but experiencing some problems. In my application, the MCU is working as a master and using all communications signals: SCK, MISO, MOSI and NSS.

I started with the example code "01_FullDuplexCommunication" on "STM32L0xx_Snippets_Package_V1.2.0" downloaded from STMicro website.

The Reference Manual for this MCUs saysthat if bit SSM of SPI_CR1 is configured to zero and bit SSOE on SPI_CR2 set to one, the NSS signal should goes low as soon as SPI is enabled (SPE = 1 on SPI_CR1). By that phrase, I conclud that when SPE = 0 the NSS signal should go high, disabling the slave communication.

However, what is happening is that NSS pin never goes high. It starts low after reset and remain in this state regardless SPI configuration. I also tried to put it on high (GPIOA->ODR |= 0x8000) before configuring NSS pin to its alternative function, but as soon as I configure SPI function on NSS pin (AF0), it goes low and never goes high again.

We are using SPI1 on this mcu, that is, PA15, PB3, PB4 and PB5 as NSS, SCK, MISO and MOSI respectively. As we are using LQFP64 encapsulation, the pins are 50, 55, 56 and 57. We are not using external pullup resistor at this pin.

I also tried to use it on TI_Mode, but it remains low and goes up just before clock starts. The other signals are working normally.

My question is: how the NSS signal should work when it is driven by hardware? I was expecting the it will remain high with SPE=0 and goes low just when SPE=1, regardless of previous configuration of pin to its alternate function.

​Thanks in advance,

​Leonardo.

1 REPLY 1

This is a recurring question here.

When SPE=0, NSS goes threestate, so it's not being actively pulled up. You may use a pullup or, if it's not fast enough, switch the NSS pin to GPIO set to push/pull output and set it to 1.

https://community.st.com/s/question/0D50X00009XkYEnSAN/spi-master-nss-always-low-in-stm32f4

JW