2024-09-23 02:43 AM - last edited on 2024-09-23 02:58 AM by Andrew Neil
This is a question about SPI communication.
There is an NSS pin for SPI communication, but is it okay to use GPIO instead of the NSS pin when there is one master and one slave?
We don't quite understand the role of NSS. I think it will be useful when there is one master and many slaves.
2024-09-23 02:57 AM - edited 2024-09-23 03:02 AM
Rather than saying, "this is a question about X", please give more descriptive titles.
eg, here, rather than just "This is a question about SPI", which tells little, saying "Role of NSS in SPI" is more helpful in showing exactly what your question is about.
I've edited it for you.
Please see the posting tips:
@pass3master wrote:We don't quite understand the role of NSS. I think it will be useful when there is one master and many slaves.
Yes, that is the key role of NSS.
But, even if there is only one slave, NSS helps to provide synchronisation between slave and master.
Many (most?) slaves require to see a falling edge to mark the start of communication, and a rising edge to mark the end.
With the STM32, you can choose to have the SPI function manage NSS for you, or you can do it "manually" by toggling any GPIO pin.
EDIT:
Note that sometimes the built-in automatic operation of the NSS signal in the STM32's SPI function is not correct for use as a slave-select; eg, see:
So, in that case, you would have to do it "manually"
2024-09-23 03:05 AM
My apologies for the title.
Thank you for pointing that out.
We know it's possible to programmatically toggle GPIO pins and "manually" manage them, but are there any examples of how to do this using NSS?
2024-09-23 03:15 AM - edited 2024-09-23 03:18 AM
@pass3master wrote:We know it's possible to programmatically toggle GPIO pins and "manually" manage them, but are there any examples of how to do this using NSS?
Not sure I get what you're asking here?
When you're managing it "manually", it's just like setting any other GPIO high and low - so you just do that!
In your .ioc file (CubeMX project) disable the Hardware NSS:
EDIT:
Maybe this helps:
2024-09-23 05:25 AM
On the STM32F4 SPI, the NSS pin is always low. This is a common complaint but that's just how the hardware was made. If your slave requires something different, you will need to set it as GPIO output and toggle manually. It is okay to do this.
On newer families, the NSS pin can behave how you want, with it going low while the clock is active and high afterwards. This can be useful when there is only one slave, but doesn't help at all when multiple slaves are present.