I have here an STM32F303K8T6 and would like to use the SPI to read out a sensor, but without setting the NSS manually by reseting and setting a GPIO pin. I have heard, that the NSS Hardware does not support the automatically reseting and setting for the Master, but only for the slaves?

Does the function HAL_SPI_TransmitReceive(...); automatically set the NSS pin in software? But if so, how do I configure my NSS pin to achieve this.

What I have done so far is the following:


Where GPIO_PIN_15 is my NSS pin.m But I would like to transfer data automatically by using the DMA, but then also the NSS should be reset and set automatically, such that I don't receive always an interrupt between a transfer, because the overhead is killing me.

  • \$\begingroup\$ what you mean "for the masters". Only master sets the NSS. Slave only reads the NSS. What overhead which kills you? It is very difficult to understand the last paragraph. I could not understand the word. Asking technical question use technical terms. If you write about interrupts explain which ones. \$\endgroup\$ – P__J__ Oct 14 '17 at 15:14
  • \$\begingroup\$ I meant only for the master, singular. The DMA Interrupt routine could be used, such that after each byte received, the NSS pin is set in the manner above, but this leads to so many interrupts, that the whole program slows down tremendous. What I'm asking is, if there is already somewhere the NSS handling implemented inside the HAL Libraries (for example inside HAL_SPI_TransmitReceive_DMA(...)), such that I can receive mutliple bytes automatically without interrupts. \$\endgroup\$ – HansPeterLoft Oct 14 '17 at 16:03
  • \$\begingroup\$ Study the RM, see the diagrams there. If it is your understanding of the DMA it is completely wrong. DMA interrupt can be invoked on: end of transmission and half of transmission and sending one byte using the DMA (unless the transmission is triggered by the hardware (pin, timer, something else) is absolutelly pointless. Try to use registers - at least you will start ot understand how the hardware works. HAL libraries are not yet for you. They only do more mess in something you anyway do not understand. \$\endgroup\$ – P__J__ Oct 14 '17 at 17:02
  • 1
    \$\begingroup\$ SPI could drive NSS automatically but to release it you must stop SPI. Soo workflow is (configure SPI), start SPI (NSS is high), transfer data (NSS goes low now), wait for transfer completion (NSS is low) then stop SPI (NSS goes back to high there). See section 30.5.5 in Reference Manual (variant SSM=0, SSOE=1)(st.com/content/ccc/resource/technical/document/reference_manual/…) \$\endgroup\$ – Misaz Sep 17 '18 at 10:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.