bl392-ak
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.

Thanks

User avatar
joan
Posts: 13225
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.

r3bpy
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:

http://www.advamation.com/knowhow/raspb ... 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.

rstuart
Posts: 1
Joined: Mon Jan 22, 2018 10:43 pm

Re: Pigpio I2C read has erratic speed

Mon Jan 22, 2018 11:39 pm

I have experience the same issue using Wiringpi C/C++, so I don't think is is a Pigpio issue. I am connected to two devices: an MPU-9250 and and Arduino Due as a slave. With either or both connected, the I2C speed will vary between two different speeds. It is unlikely that the slave is stretching the clock since I see the same behavior with either slave. If I put a scope on the SDA, the clock width (rise to rise) will jump between 2.4 uSec and 4.0 uSec. This change corresponds directly to the observed throughput. I changed to a different Pi 3 board and got the same results. The speed spontaneously changes every few seconds. The speed was set by adding the following line to /boot/config.txt: "dtparam=i2c1_baudrate=4000000".

Is this the same behavior others have observed? I will investigate further (and change to Pigpio to take advantage of burst I/O). I would be happy to file a bug report if I get the same consistent and reproducible behavior. Any other suggestions?

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

Who is online

Users browsing this forum: No registered users and 3 guests