I am using two SPI devices to talk to a MCP23S17 (SPI0) to multiplex the chip selects (CS) for four SPI slaves (SPI1). The loop is running at 500 Hz, the transfer takes roughly 900 us. Most of the time everything works as intended. But ever so often the loop time gets a lot bigger >2.5 ms.
I know it's not a real time system, but 3.5ms or more seem excessive compared to the rest of the loops where everything works perfectly. Is there any way to prevent these hiccups?
System is a raspberry4, program is multithreaded, written in c++, no CPU is ever >30% usage.
white MOSI1, brown MISO1, red SCLK1, orange SCLK0, yellow MOSI0, purple CS0
edit1: I now isolated two processor cores to run the program on those cores to get closer to real time behavior and am now using the fifo-scheduler. This decreases the delays but they are still there.
I also looked more into when the delays occur and it's always the same point in the transfer. When the SPI0 is supposed to transfer data as shown in the picture below the CS line goes low but then delays the MOSI data transfer. This happens only when I write to more than one SPI slave on the SPI1 bus, but does not happen when I only test the SPI0 bus without writing to the SPI1 bus.
edit2: a little more info: the program consists of 4 threads. 1: reading the spi slaves 2: logging the received data to csv 3: reading i2c data 4: zmq communication with computer
from what I found is that the interrupts seem to come from the zmq thread. as soon as it's disabled, the delays are gone.