NSS pin mode
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2020-03-12 11:38 AM
Hello,
I'm using HAL_SPI_Transmit function to transfer two bytes over SPI, NSS pin controlled by SPI module. I noticed that NSS pin is changing state after each transmitted byte. I need that NSS goes low before transmission is started and goes back to high only when both bytes transmitted.
Is that possible?
- Labels:
-
SPI
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2020-03-12 2:11 PM
Which STM32?
What you describe sounds like NSS Pulse mode, see description of SPIx_CR2.NSSP and the NSS pulse mode subchapter in SPI chapter in RM. Check by reading back the SPI registers, if this bit is set.
I don't Cube, but Cube is open source so you can easily find yourself, how is this bit set.
JW
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2020-03-13 3:09 AM
waclawek.jan, thanks for prompt response.
I was searching over several forums, seems i'm not alone facing this problem.
Here is screenshot from my scope using NSS pin controlled by hardware:
Blue curve represents SPI clock, yellow is NSS pin. In my case i'm working with flash chip, to read/write data i need that NSS remains low until both bytes transmitted.
I also tried to use GPIO as output for chip select controlled by software, in this case everything works, but software controlled pin is very slow, even sys.clock is 48Mhz. Here is screenshot:
Is there any suggestions what else to try?
Thank you in advance.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2020-03-13 5:23 AM
Is there any suggestions what else to try?
- Telling the MCU part number
- Reading the reference manual
- Rewriting SPI handling code without HAL functions
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2020-03-13 6:02 AM
Thanks for response, berendi.
MCU is STM32F030C8T6
Do you mean that both delays shown in second screenshot (before and after transmission) caused by HAL function?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2020-03-13 7:03 AM
Try yourself - set GPIO pin low by writing into BSRR, then write byte into SPI_DR, wait until SPI_RXNE gets set, read SPI_DR, repeat once more, then set GPIO pin high again.
Observe on oscilloscope the result.
JW
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2020-03-13 7:11 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2020-03-14 4:06 AM
Thanks for suggestions.
I tried to use own SPI send/receive function and CS pin controlled by software. Result surprised me, sending 2 bytes took only 6us. Using HAL_SPI function it took 24us.
Thanks a lot, my problem solved.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2020-03-14 5:16 AM
No surprises here, just look how overcomplicated the HAL functions are compared to your straightforward one.
HAL tries to account for lots of possible uses of a peripheral in one function, your code does exactly what is necessary.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2020-03-14 11:03 AM
> HAL tries to account for lots of possible uses of a peripheral
Isn't it ironic that it tries to do everything, but in real life can do nothing. Not even the UART!
