Skip to main content
Dick Lin
Senior
Jul 13, 2018 4:36 PM UTC
Question

SPI NSS?

Posted on July 13, 2018 at 18:36

Hi,

I am working on Nucleo-144 SPI. The NSS GPIO ios PA4. The only way I can have the NSS high is use 

__HAL_SPI_DISABLE() function. The HAL_GPIO_WritePin() just never work.

I can see from the scope to verify it. Doesn't seems to be the right way to turn off the SPI for set NSS high.

Anyone has experience turn NSS high/low?

/**SPI1 GPIO Configuration

PA4 ------> SPI1_NSS

PA5 ------> SPI1_SCK

PA6 ------> SPI1_MISO

PA7 ------> SPI1_MOSI

*/

HAL_GPIO_WritePin( GPIOA, GPIO_PIN_4, GPIO_PIN_SET ); // NSS1 high

__HAL_SPI_DISABLE(m_spi);

Thx

    This topic has been closed for replies.

    10 replies

    Andreas Bolsch
    Lead III
    Jul 13, 2018 4:58 PM UTC
    Posted on July 13, 2018 at 18:58

    You can't easily use the same pin with 'alternate' pin setting (that happens if you use the hardware NSS signal) assigned to the SPI interface and with output setting (simple GPIO). Check the corresponding reference manual:

    'Alternate function configuration: ... The output buffer is driven by the signals coming from the peripheral (transmitter

    enable and data) ...'. Peripheral here means SPI interface.

    Either 'automatic' or 'manual', but not both at the same time ...

    Dick Lin
    Dick LinAuthor
    Senior
    Jul 13, 2018 7:06 PM UTC
    Posted on July 13, 2018 at 19:06

    I am assuming calling HAL_SPI_Transmit/Receive function doesn't automatically turn off NSS. The NSS always high after the function. 

    I am looking for a way to turn NSS on/off before/after the HAL function.

    Thx

    Tesla DeLorean
    Guru
    Jul 13, 2018 7:46 PM UTC
    Posted on July 13, 2018 at 19:46

    >>

    The HAL_GPIO_WritePin() just never work.

    Configure the pin as a GPIO. Sounds like you're not doing that properly. Show code, then people don't have to guess.

    Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
    turboscrew
    Senior III
    Jul 15, 2018 7:50 AM UTC
    Posted on July 15, 2018 at 09:50

    I think you described the way, SPI with HW NSS is supposed to work on STM32s. The SPI HW NSS is, how ever, known to have bugs in some STM32-chips.

    From F103 fererence:

    NSS output enabled (SSM = 0, SSOE = 1)

    This configuration is used only when the device operates in master mode. The

    NSS signal is driven low when the master starts the communication and is kept

    low until the SPI is disabled.
    AVI-crak
    Senior
    Jul 15, 2018 9:10 PM UTC
    Posted on July 15, 2018 at 21:10

    It's not a mistake.

    Contact NSS should work this way.