Skip to main content
MSipo
Senior II
September 1, 2023
Solved

How to handle if SPI slave receives less words when chip select goes high?

  • September 1, 2023
  • 3 replies
  • 2147 views

I have setup the MCU as an SPI slave that will receive 15 words.

How can I handle if the master sends less than 15 words?

If the master sends less than 15 words I don't get any call to HAL_SPI_TxRxCpltCallback().

The NSS pin is selected as "Hardware NSS Input Signal".

I have not been able to activate an external interrupt on the NSS pin so I can't detect NSS rising edge.

This topic has been closed for replies.
Best answer by TDK

In CubeMX, right click the pin -> Pin Stacking. Then select the EXTI function.

TDK_0-1693575482403.png

It looks like CubeMX generates the initialization in the correct order to allow this to work, but I didn't test. Try it. If it doesn't, you will need to do the EXTI configuration in user code.

3 replies

TDK
September 1, 2023

One option is to make the CS pin an EXTI interrupt source, and when it goes high, reset the SPI interface and/or interpret the amount of data it already sent.

The pin can act as NSS and EXTI at the same time.

"If you feel a post has answered your question, please click ""Accept as Solution""."
MSipo
MSipoAuthor
Senior II
September 1, 2023

I tried to use the pin as NSS and EXTI at the same time but it didn't work. But I did route it to a separate pin and there it works.

What do I need to do to make it work on the same pin?

 

TDK
TDKBest answer
September 1, 2023

In CubeMX, right click the pin -> Pin Stacking. Then select the EXTI function.

TDK_0-1693575482403.png

It looks like CubeMX generates the initialization in the correct order to allow this to work, but I didn't test. Try it. If it doesn't, you will need to do the EXTI configuration in user code.

"If you feel a post has answered your question, please click ""Accept as Solution""."
MSipo
MSipoAuthor
Senior II
September 1, 2023

Thank you. I didn't know about the pin stacking in CubeMx :thumbs_up:

MSipo
MSipoAuthor
Senior II
September 4, 2023

Got it to work now. Found more info at https://community.st.com/t5/stm32-mcu-products/is-it-possible-to-use-multiple-functions-on-a-single-pin-on/m-p/134013 

CubeMX doesn't support this (both EXTI and NSS at the same time). So I had to manually add a rising edge EXTI on that pin. Now it works.