Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 6970

Python • Python Threads Intorduces 10msec Delay in SPI

$
0
0
I am using python3 and pigpiod on an RPi 4b.

I have an application thar reads 48 bytes from a SPI device. The device will only do byte transfers so this is done in a loop. There are also two I2C buses.

In a NON-threaded implementation, this takes about 500 usec for the SPI read according to a logic analyzer. I wanted to speed this up and I/O functions should be easy to thread.

I converted the SPI, I2C0, and I2C1 functions to threads using condition variables to start the I/O in each thread.

This seemed to work Ok. I printed the data evary 1 second.

Then, I noticed the SPI thread was slow. Using the logic analyzer, the SPI thread was taking about 600 msec. Yes, milli-seconds!

There was about a 10 msec interval between the SPI transactions.

Any idea about why threads inserted the extra 10 msec between transactions? Context switch in the interpreter?
How can I get around this?

Tom Dean

Statistics: Posted by tomdean — Wed Dec 24, 2025 6:36 pm — Replies 0 — Views 2



Viewing all articles
Browse latest Browse all 6970

Trending Articles