How can I get SPI NSS pin driven high, and why is SPI transactions sometimes garbled?
- October 2, 2019
- 6 replies
- 4213 views
I am having great difficulties getting an SPI interface to work on a STM32433 device. I’ve gone back to the ST Nucleo dev board and used STMCube to generate a project and I am able to reproduce all my problems with only the dev board.
I am using SPI1 on PA4 through PA7.
1. NSS not driven.
The NSS line is only driven low when hardware, master mode is enabled. On the dev board it is always low unless the pull-up is enabled on the GPIO, but in this case NSS slowly goes high (and in my case not high enough before next transaction) because it seems it is high-impedance when SPI is disabled.
The code generated by STMCube never disables the SPI, so after calling HAL_SPI_Transmit() it never goes high again.
I did not find any calls in the SPI_HAL ot manually control NSS.
According to RM0394 SPIx_CR1.SSI (Bit 8): “The value of this bit is forced onto the
NSS pin and the I/O value of the NSS pin is ignored.“ However, when I change SSM to 1 (to select software mode), and then change SSI, it has no effect.
What configuration/method/mode should I use so that NSS is driven high and low?
2. Garbage SPI Data.
The SPI bus transaction is sometimes invalid. When this happens, the debugger also loses the connection and I am unable to program after this. I first have to re-program with an application that does not do a SPI transaction. This fails with a flash verification error. I then have to cycle power, and then I am able to re-program and continue.
Attached is a scope trace showing the garbage SPI transaction. Clock can be seen going low, but it is low for a very long time (compared to actual clock speed) before some clocks that are too short follows. After this, I cannot debug the CPU any longer.
