cancel
Showing results for 
Search instead for 
Did you mean: 

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

MSipo
Senior II

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.

1 ACCEPTED SOLUTION

Accepted Solutions
TDK
Guru

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".

View solution in original post

6 REPLIES 6
TDK
Guru

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".

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
Guru

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".

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

I have tested the solution now. There is only one problem with stacking. It is that CubeMX will set the "Hardware NSS Signal" to "Disable". And that will make the SPI slave not care about the NSS. It will always clock in data when there is a SPI clock even if CS is high. I can't have that behavior as there are more slaves on the same bus with their own chip selects. 🤔

MSipo
Senior II

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.