Read adc through /dev/iio:deviceX

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Read adc through /dev/iio:deviceX

3,736 Views
andrealaini
Contributor I

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

Labels (3)
0 Kudos
2 Replies

2,007 Views
igorpadykov
NXP Employee
NXP Employee

Hi Andrea

also one can follow similar example for gpio

Access GPIO from Linux user space | FalsinSoft 

Best regards
igor

0 Kudos

2,007 Views
gary_bisson
Senior Contributor III

Hi Andrea,

You should use libiio in order to communicate with the device:

GitHub - analogdevicesinc/libiio: Library for interfacing with IIO devices 

So far it proved to work very well.

Regards,

Gary

0 Kudos