ADC on 3.14.x kernel (or newer)

Hi,

I made another attempt to read some analog values with the 3.14 RCN kernel.

How am I supposed to read analog values?

The only thing which gives something (strange) seems to be a hacked version of the generic_buffer test of the iio framwork. Does anyone know what I am doing wrong and/or how else to read A/D values? I am thinking about wiring via i2c an a/d converter and use this instead of those on board.

root@beaglebone:~# cat /proc/version
Linux version 3.14.0-custom-student4+ (student4@bh4) (gcc version 4.8.2 (GCC) ) #1 SMP Tue Sep 30 20:09:53 EEST 2014

  • lsmod
    Module Size Used by
    nfc 56331 0
    bluetooth 232921 2
    6lowpan_iphc 6182 1 bluetooth
    omap_aes 11951 0
    omap_sham 17071 0
    ti_am335x_adc 4743 0
    kfifo_buf 2517 1 ti_am335x_adc
    industrialio 46758 2 ti_am335x_adc,kfifo_buf
    ti_am335x_tsc 4715 0
    rtc_omap 5240 0
    uio_pdrv_genirq 3258 0
    uio 8858 1 uio_pdrv_genirq
    gpio_keys 8038 0

  • modprobe iio-trig-sysfs

  • echo 1 > /sys/bus/iio/devices/iio_sysfs_trigger/add_trigger
    we should have a trigger0 folder now

  • ls /sys/bus/iio/devices/
    iio:device0 iio_sysfs_trigger trigger0

  • cat /sys/bus/iio/devices/trigger0/name
    sysfstrig1

  • cat /sys/bus/iio/devices/iio:device0/scan_elements/in_voltage4_en
    0

  • cat /sys/bus/iio/devices/iio:device0/scan_elements/in_voltage5_en
    0

  • cat /sys/bus/iio/devices/iio:device0/scan_elements/in_voltage6_en
    0

  • echo 1 > /sys/bus/iio/devices/iio:device0/scan_elements/in_voltage5_en

  • cat /sys/bus/iio/devices/iio:device0/scan_elements/in_voltage4_en
    0

  • cat /sys/bus/iio/devices/iio:device0/scan_elements/in_voltage5_en
    1

  • cat /sys/bus/iio/devices/iio:device0/scan_elements/in_voltage6_en
    0

ADC Value: 246484699
ADC Value: 237047412
ADC Value: 228527626
ADC Value: 218828111
ADC Value: 209587410

I would expect 12 bits out of 16 bits.

Regards,

Robert

How did you enable them in the dts?

I have one example here:

https://github.com/RobertCNelson/dtb-rebuilder/blob/3.14-ti/src/arm/am335x-bone-basic-proto-cape.dtsi

Regards,

Hi Rob,

Thanks.

My problem was that I did not interpret the data properly.

I don’t know why people print data in decimal and not directly in hex :wink:

ADC Value: 14157877 0xd8(216) 0.094922 0x835(2101) 0.923291
ADC Value: 13043810 0xc7(199) 0.087451 0x862(2146) 0.943066
ADC Value: 15992896 0xf4(244) 0.107227 0x840(2112) 0.928125

each line consists of 2 samples (in this case form channel A5 and A6).
It’s still quite noisy, but at least the values make more sense now.

Regards,

Robert