Posts: 2
Joined: Wed Dec 21, 2016 12:01 am

Pigpio I2C read has erratic speed

Mon Mar 20, 2017 1:34 pm

I am using an MPU 6000 chip and I am aiming to read it at ~1kHz. Most of the time this is absolutely fine. However sometimes the read time jumps to 1-10ms instead of the normal 0.4ms. I am using the pigpio library for the I2C communication.

Code: Select all

t1 = gpioTick();
result = i2cReadI2CBlockData(m_currentI2C, regAddr, reinterpret_cast<char*>(data) + position, getLength);
t2 = gpioTick();
Most of the results of this are in the range 200-400, but I get occasional (1 in 1000) spikes in the 1000-10000 range. Any suggestions on ways to avoid this would be appreciated. Is it just the MPU chip being unreliable? The above code is in a loop that is triggered by an interrupt from the MPU.


User avatar
Posts: 12705
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: Pigpio I2C read has erratic speed

Mon Mar 20, 2017 1:39 pm

The pigpio i2c* calls are just wrappers around the underlying Linux SMBus/I2C implementation. It may just be normal Linux scheduling delays.

Posts: 3
Joined: Thu Apr 06, 2017 9:52 am

Re: Pigpio I2C read has erratic speed

Mon Jun 19, 2017 6:53 pm

This might be clock stretching issue, the slave does not respond in time and Pi reads incorrect data - I have observed it multiple times (Pi 3B), exactly as described bellow: ... c-bug.html

Since pigpio i2c* calls rely on Pi's implementation of I2C you sill can be affected by this bug. I switched to pigpio bit-banging I2C implementation (set of bb_i2c* calls) and can confirm that it works more reliably than the native SMBus/I2C implementation.

Return to “Interfacing (DSI, CSI, I2C, etc.)”

Who is online

Users browsing this forum: No registered users and 7 guests