2022-09-19 03:18 PM
Hello,
I am following a course on Udemy ("Mastering Microcontroller and Embedded Driver Development" if that matters) and I try to set my Nucleo as SPI master.
I set up the SPI but the NSS pin does not want to go high when I enable the peripheral.
A workaround is to set a pullup on that pin but I don't like the manual idea because as I understood that should happened automatically.
I don't want to bloat you with my code but if needed I can share it.
In general what I do is:
-Setup the USER button as input so when it is pressed to trigger the data send.
-Initialize the MOSI, CLK,NSS pins at GPIO alt fun, No pull ups, push pull, speed low(tried all 4 speeds).
-Initialize SPI2. BUS=Full duplex, Mode=Master, Speed (tried all), DFF=8, CHA=0,CPOL=0,SSM=0,SSOE=1.
This is the lesson's code actually
Also other students had the same problem as I saw in comments.
I hope some more experience could help!
Thank you in advance
Solved! Go to Solution.
2022-09-19 04:14 PM
When SPI is disabled, NSS is not controlled by SPI and goes threestate. You can set pullup at the initialization, it will then pull the pin NSS up when SPI is disabled, but how fast it will go up depends on the external parasitics.
http://efton.sk/STM32/gotcha/g21.html
JW
2022-09-19 04:13 PM
The NSS in hardware is an open collector output so that you can wire together multiple processors as multiple masters. I've never seen this topology used in real life, but NSS is set up to support it, so there.
A part of the open collector topology is that can only pull to ground, it cannot pull high. Therefore you must use an external pull-up.
The other option is to redefine the pin as a GPIO output and bit bang the chip select line.
I usually go for plan B as I haven't found very many peripheral chips that lend themselves to what hardware NSS offers.
But the pull-up resistor is the answer to your query.
2022-09-19 04:14 PM
When SPI is disabled, NSS is not controlled by SPI and goes threestate. You can set pullup at the initialization, it will then pull the pin NSS up when SPI is disabled, but how fast it will go up depends on the external parasitics.
http://efton.sk/STM32/gotcha/g21.html
JW
2022-09-19 11:48 PM
Thank you guys. It was driving me crazy so long time.