Skip to main content
Visitor II
June 11, 2025
Question

STM32U5 Interrupt driven SPI transmit.

  • June 11, 2025
  • 2 replies
  • 357 views

HAL code for interrupt-driven SPI transmit attempts to fill a transmit queue, which uses up the 10 bytes I am transmitting.  But, a TX interrupt is also triggered which grabs an extra byte past the end of the buffer and decrements the count which wraps.  There is code to turn off TX interrupts in the handler, but it checks after transmitting a byte rather than before.  

Has anyone else noticed this?

    This topic has been closed for replies.

    2 replies

    Visitor II
    June 11, 2025

    Looks like "TXP" flag is never cleared.  The code that pre-fills the transmit FIFO ends up writing the entire buffer into the FIFO and only the first 8 bytes are actually entered.  I kludged the "Fill in the TxFIFO" code by breaking out of the loop after storing only 1 value and it started working.   

    Also the interrupt-driven code seems to write one value per interrupt.  If we have a FIFO, why not fill it at each ISR?  (Of course after figuring out why TXP is not being cleared)

    ST Employee
    June 13, 2025

    Hello jeffl.kelley9,

    The behavior of TXP flag seems to be the correct one. TXP flag is set if there is enough space to add data in TX FIFO. Depending on your instance the FIFO size can be up to 32 bytes. That is why TXP flag is always set. 

    What did you choose as frame size ? 8 bits per frame, 16 bits ? And what is the size you give in the input of the transmission function. It be helpul to help you.

    Br,