This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

ADS1115: Unable to read multiple channels w IIO buffers

Part Number: ADS1115

I am working with Raspberry Pi 4 with connected ADS1115 ADC in a form of https://www.mikroe.com/adc-8-click mikroBUS extension board.
I am trying to configure Linux IIO buffers to read from this ADC.

My problem is that I cannot configure IIO buffer to read more than one channel at the same time. I can read every channel separately, but not more.
The error I get is related to invalid arguments when creating the IIO buffer. The same error I get from both IIO API functions and from command line tools.

Here is the output of 4 channels read separately with iio_readdev tool. I am using software trigger (trigger0) which I trigger from another terminal.

kuba@raspberrypi-kuba:~ $ sudo iio_readdev -t trigger0 -T 0 -b 1 -s 1 iio:device1 voltage0 | hexdump
WARNING: High-speed mode not enabled
0000000 6692                                   
0000002
kuba@raspberrypi-kuba:~ $ sudo iio_readdev -t trigger0 -T 0 -b 1 -s 1 iio:device1 voltage1 | hexdump
WARNING: High-speed mode not enabled
0000000 0011                                   
0000002
kuba@raspberrypi-kuba:~ $ sudo iio_readdev -t trigger0 -T 0 -b 1 -s 1 iio:device1 voltage2 | hexdump
WARNING: High-speed mode not enabled
0000000 000a                                   
0000002
kuba@raspberrypi-kuba:~ $ sudo iio_readdev -t trigger0 -T 0 -b 1 -s 1 iio:device1 voltage3 | hexdump
WARNING: High-speed mode not enabled
0000000 001f                                   
0000002

As you can see, all channels voltage0-3 are returning some values and they are correct (voltage0 is 6692 which results in 3.3V and the rest is almost 0).

If I try to read two channels at the same time, then I get the buffer error:

kuba@raspberrypi-kuba:~ $ sudo iio_readdev -t trigger0 -T 0 -b 1 -s 1 iio:device1 voltage0 voltage1 | hexdump
Unable to allocate buffer: Invalid argument

The same error is returned no matter what values are put into -b and -s options. According to the iio_readdev manual and other internet sources, it should be possible to read more than one channel.

Here is the snipper from device tree which I'm using for ADS1115:

&i2c1 {
	pinctrl-names = "default";
	pinctrl-0 = <&i2c1_pins>;
	clock-frequency = <100000>;

 	ads1115: adc@48 {
    	compatible = "ti,ads1115";
    	reg = <0x48>;
		#address-cells = <1>;
	    #size-cells = <0>;

		channel@4 {
	    	reg = <4>;
	    	ti,gain = <1>;
	    	ti,datarate = <4>;
    	};

		channel@5 {
	    	reg = <5>;
	    	ti,gain = <1>;
	    	ti,datarate = <4>;
    	};

		channel@6 {
	    	reg = <6>;
	    	ti,gain = <1>;
	    	ti,datarate = <4>;
    	};

		channel@7 {
	    	reg = <7>;
	    	ti,gain = <1>;
	    	ti,datarate = <4>;
    	};
  	};
};

The same errors I get from IIO API 

iio_device_create_buffer()
  • I have verified that on AD7923 from Analog Devices this command works fine, so it must be something with the driver for ADS1115.

  • Hi Kuba,

    Sorry for the delay - we've had some weather issues here in Dallas that knocked a lot of the team offline.  Anyway...the driver looks like it came from the MIKROE folks, have you talked with them about the code?  We are not familiar with the iio_readdev tool.

    Also, the device you are not having issues with is a 200000 SPS converter with a fast SPI interface, while the ADS1115 is an 860 SPS device with an I2C interface.  Without seeing the timing of the control signals (i.e. and O-Scope or logic analyzer capture) its hard to say if you are simply trying to access the ADS1115 to fast.  Can you post screen shots of the timing for us?

  • No problem.

    As for the iio_readdev and iio_info, these are the standard Linux cmd line tools to read values from IIO devices (and clearly ADS1115 has an IIO support in Linux kernel).

    As for the timings: the problem is that when I use iio_readdev (which uses IIO buffers API) it works fine if I ask only for one channel. Here you can see an output from Saleae Logic Analyzer:

    kuba@raspberrypi-kuba:~/devices/iio:device0 $ sudo iio_readdev -t trigger0 -T 0 -b 1 -s 1 iio:device1 voltage0 | hexdump
    WARNING: High-speed mode not enabled
    0000000 66ae
    0000002

    If I ask for two channels, then there is no transmission at all. The Linux driver simply returns an error and refuses to create an IIO buffer.

    On the other hand, when I use iio_info (which uses different sysfs IIO API), then there is no problem to get data from all channels:

  • Hi Kuba,

    I'm having a hard time seeing the images you posted. When I click the link the image is broken. You can load your images directly onto E2E using the Insert/Edit Media button in the post control panel. It may be more reliable than an external host.

    Regards,

  • I edited my previous post. Should be visible now.