AnsweredAssumed Answered

Read adc through /dev/iio:deviceX

Question asked by Andrea Laini on Mar 16, 2017
Latest reply on Mar 16, 2017 by igorpadykov

Hi everybody,

 

I've an imx6sx board and I now need to use the adc, reading sampled value in my C program.

So, I've enabled adc2 in the dts, that's the code (exactly the same provided by Freescale):

 

.dtsi:

   adc2: adc@02284000 {
    compatible = "fsl,imx6sx-adc", "fsl,vf610-adc";
    reg = <0x02284000 0x4000>;
    interrupts = <GIC_SPI 101 IRQ_TYPE_LEVEL_HIGH>;
    clocks = <&clks IMX6SX_CLK_IPG>;
    num-channels = <4>;
    clock-names = "adc";
    status = "disabled";
    };

 

.dts:

&adc2 {
 vref-supply = <&reg_vref_3v3>;
 status = "okay";
};

 

Everything works in the right way if I cat the files in /sys/bus/iio/devices/iio:device0/ , getting the right voltage values.

Problems begin when trying to cat the node /dev/iio:device0, which returns "read error: Invalid argument". From my C program I'm able to open this device file, but when I'm going to read it, I still (obviously) get errorno -22, therfore "Invalid argument".

I've spent some hours googling and what I've found is that the device node represents a buffer where readings of all channels are "saved". Also, it seems that device driver vf610-adc has no buffer support, am I right? Is this the reason why I can't read the node?

In that case, how I can get adc readings in my C program (I'm just interested in only one of the 4 channels value)?

 

Many thanks

Andrea

Outcomes