2023-09-01 03:02 AM
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.
Solved! Go to Solution.
2023-09-01 06:41 AM
In CubeMX, right click the pin -> Pin Stacking. Then select the EXTI function.
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.
2023-09-01 06:06 AM - edited 2023-09-01 06:06 AM
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.
2023-09-01 06:08 AM
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?
2023-09-01 06:41 AM
In CubeMX, right click the pin -> Pin Stacking. Then select the EXTI function.
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.
2023-09-01 07:06 AM
Thank you. I didn't know about the pin stacking in CubeMx :thumbs_up:
2023-09-01 07:50 AM
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. :thinking_face:
2023-09-04 01:02 AM
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.