0

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

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.

3
  • Just guessing but that appears like an interrupt is taking over for a short period of time.
    – Gil
    Jul 28 at 22:39
  • is there a way to find out what is causing the interrupt?
    – FR_MPI
    Jul 29 at 6:30
  • This is just a SWAG: It is probably the OS, I have no idea what is connected or what the code looks like. I am assuming it is one of the many process that is running the task scheduler that starts the SPI and after a given amount of time it is interrupted to do another task.
    – Gil
    Jul 29 at 18:50

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.