Delay between SPI messages

Hi,
I’m trying to understand how the SPI transfers work at low level, so I hooked up an oscilloscope to the SPI clock and grabbed the attached screenshot (SCK yellow line).
I send several commands to write registers of a TMC drivers and I can see they get executed approx 15-16ms apart even if they’ve been sent from the host code literally one after the other and with the same print_time.

Maybe I’m missing something on the way these SPI commands are handled on the MCU. My goal would be for them to be executed indeed one after the other (as fast as possible compatible with MCU clock and SPI speed)

SPI transfers in Klipper are not currently scheduled. They are processed in the micro-controller as each spi_transfer command arrives. There is currently no way to apply reliable transmission times to the messages.

The timestamp passed in the host software is used for message prioritization (and minimum message transmission time) in the host serial transmit queues. It’s only suitable for gross serialization (think 100+ milliseconds).

-Kevin

This begs the questions (based on the oscilloscope data):

  • what keeps the MCU busy for 15ms (when no other command is sent from the host)
  • how can that be avoided? (e.g. writing a new SPI command that would indeed be scheduled properly)

PS: to be clear on the interpretation of the screenshot, each spike on the CH1 (yellow) is actually a full SPI transmission when zoomed in

I repeated the test, but this time with the scope is on the host->MCU tx line.
The same pattern can be seen there, pointing to the host as the root cause.
The question though is still the same:

  • what is causing such delays?