Post Go back to editing

AD7193 Driver with Raspberry Pi

Hi,

So i have been trying to to establish SPI communication between AD7193 and Raspberry pi 3. I'm using the Yocto-rpi image for this purpose. This is procedure i followed but facing some issues:-

1. Enabled the ad7193 driver in menuconfig.

2. Added the patch file in the drivers/staging/iio/adc/ad7192.c for it to support device tree.

3.Created an overlay. dts file for this is /boot/dts/ as follows

/dts-v1/;
/plugin/;

/ {
        compatible = "brcm,bcm2835", "brcm,bcm2708", "brcm,bcm2709";

        fragment@0 {
                target = <&spi0>;
                __overlay__ {
                        status = "okay";
                };
        };

        fragment@1 {
                target = <&spidev0>;
                __overlay__ {
                        status = "disabled";
                };
        };

        fragment@2 {
                target = <&spidev1>;
                __overlay__ {
                        status = "disabled";
                };
        };

        fragment@3 {
                target = <&gpio>;
                __overlay__ {
                        ad7193_pins: ad7193_pins {
                                brcm,pins = <45>;
                                brcm,function = <0>;
                                brcm,pull = <0>;
                        };
                };
        };

        fragment@4 {
                target = <&spi0>;
                __overlay__ {
                        /* needed to avoid dtc warning */
                        #address-cells = <1>;
                        #size-cells = <0>;

                        adc: ad7192@0{
                                compatible = "adi,ad7192";
                                reg = <0>;
                                pinctrl-names = "default";
                                pinctrl-0 = <&ad7193_pins>;

                                spi-max-frequency = <1000000>;
                                spi-cpha;
                                spi-cpol;
                                irq-gpio = <&gpio 45 0x2>; /* IRQF_TRIGGER_FALLING */
                                interrupts = <45 0>; /* high-to-low edge triggered */
                                interrupt-parent = <&gpio>;
                                adi,reference-voltage-mv = <3300>;
                                adi,clock-source-select = <2>;
                                adi,refin2-enable;
                                adi,unipolar-enable;
                                status = "okay";
                        };
                };
        };
};

4. Added this overlay.dts file to bb.append file and rebuild the kernel and enable the overlay file in /boot/config.txt in the target.

5. The driver is loaded but i keep getting setup failed and spi0.0 supply vcc not found, using dummy regulator
ad7192 spi0.0: setup failed

ad7192: probe of spi0.0 failed with error -5

I'm attaching the image below please let me know what i'm doing wrong.

Note:- I have connected AGND,CS,SCLK,Din,Dout/Rdy to the respective pins in raspberry pi 3.

Thanks in advance.

-SK

  • Hi,

    Firstly, in order to get rid of the "spi0.0 supply vcc not found, using dummy regulator" warning, you need to setup a regulator in the device tree. 

    Secondly, why did you use GPIO 45? At a first look, it seems that it is not available. For example, you can use GPIO 25 instead: 

    irq-gpio = <&gpio 45 0x2>; /* IRQF_TRIGGER_FALLING */

    interrupts = <25 2>; /* 2 = high-to-low edge triggered */

    interrupt-parent = <&gpio>;

    https://www.kernel.org/doc/Documentation/devicetree/bindings/pinctrl/brcm,bcm2835-gpio.txt 

    Let me know how it goes.

    -Stefan

  • Hi,

    I added the details in the device tree as you mentioned and now the driver is working and I'm able to list the devices and other parameters but the regulator issue was still not solved.

    Firstly I saw an issue while communicating to the device, I didn't know if the SPI was working or not as i removed the communication cables no error was intimated to me by the driver. So should i comment out the Spidev0 in the device tree?? If so how will the SPI communication work as I'm writing using the CS0 of the SPI. In case it should be disabled is the ad7193 driver using the linux spi driver to communicate ? and if it is shouldn't it be enabled?

    Secondly is my connections right ? I connected

    SPI0 MOSI---->DIN

    SPI0 MISO---->Dout/RDY

    SPI0 CLCK----->CLK

    SPIO CS0 -> CS

    GND---->AGND

    Should i connect the Interrupt Pin (GPIO25) also to DOUT/RDY ?? but  don't think ad7193 is a interrupt device but an interrupt client ryt? Also /sys/devices/platform/bfin-spi.0/spi0.18 I'm not getting this for driver and device testing .

    Please let me know where am i making a mistake .

    Thanks in advance

    -SK

  • Hi,

    Your connections are correct. Also, you are right that DOUT/RDY pin should be connected to both SPI MISO and GPIO25.

    Can you please show me how your device tree looks like after the latest changes?

    Is your device listed in /sys/bus/iio/devices ?

    -Stefan

  • Hi,

    This is my device tree after the changes,

    /dts-v1/;
    /plugin/;

    / {
            compatible = "brcm,bcm2835", "brcm,bcm2708", "brcm,bcm2709";

        fragment@0 {
            target = "/";
            __overlay__ {
                adc_vref: fixedregulator@0 {
                    compatible = "regulator-fixed";
                    regulator-name = "fixed-supply";
                    regulator-min-microvolt = <3300000>;
                    regulator-max-microvolt = <3300000>;
                    regulator-boot-on;
                };
            };
        };

            fragment@1 {
                    target = <&spi0>;
                    __overlay__ {
                            status = "okay";
                    };
            };

            fragment@2 {
                    target = <&spidev0>;
                    __overlay__ {
                            status = "disabled";
                    };
            };

            fragment@3 {
                    target = <&spidev1>;
                    __overlay__ {
                            status = "disabled";
                    };
            };

            fragment@4 {
                    target = <&gpio>;
                    __overlay__ {
                            ad7193_pins: ad7193_pins {
                                    brcm,pins = <25>;
                                    brcm,function = <0>;
                                    brcm,pull = <2>;
                            };
                    };
            };

            fragment@5 {
                    target = <&spi0>;
                    __overlay__ {
                            /* needed to avoid dtc warning */
                            #address-cells = <1>;
                            #size-cells = <0>;

                            adc: ad7192@0{
                                    compatible = "adi,ad7193";
                                    reg = <0>;
                                    pinctrl-names = "default";
                                    pinctrl-0 = <&ad7193_pins>;

                                    spi-max-frequency = <1000000>;
                                    spi-cpha;
                                    spi-cpol;
                                    vref-supply = <&adc_vref>;
                                    interrupts = <25 2>; /* high-to-low edge triggered */
                                    interrupt-parent = <&gpio>;
                                    adi,reference-voltage-mv = <3300>;
                                    adi,clock-source-select = <2>;
                                    adi,refin2-enable;
                                    adi,rej60-enable;
                                    adi,chop-enable;
                                    adi,buf-enable;
                                    adi,burnout-curr-enable;
                                    Sadi,sinc3-enable;
                                    adi,unipolar-enable;
                                    status = "okay";
                            };
                    };
            };
    };

    What is the use of bcrm,pull=<0 or 1 or 2> what does these values mean ?

    Yes my its listed as iio:device 0 and trigger:0 in the mentioned path,but i cant find spi.o in /sys/devices/platform/bfin-spi.0 to check for the device . Let me know if i did anything wrong.

    Thanks in advance.

    -SK

  • Hi, 

    The ad7192 driver is looking for a regulator named "vcc" : linux/ad7192.c at xcomm_zynq · analogdevicesinc/linux · GitHub , but in your device tree, it is named "vref". For starters, try modifying this one line:

    vref-supply = <&adc_vref>;

    to

    vcc-supply = <&adc_vref>;

    Let's see if this gets rid of the regulator issue.

    -Stefan

  • Hi ,

    Will do that and let you know the results. The rest of the device tree looks good ? Should the Spidev0 be disabled as ad7193 will use the chip select ? can i go ahead and try this for now ?

    Thanks in advance.

    -SK

  • Hi,

    Your device should be under /sys/bus/iio/devices/iio:device0. Go to that location and type ls -l . You should see all the available options. If this works, then you are probably good to go. 

    Don't worry that you don't see the device under   /sys/devices/platform/bfin-spi.0/spi0.18, this is because for the wiki page example a Blackfin processor was used. 

     

    -Stefan

  • Hi,

    The Regulator issue is solved and also as you said in the path /sys/bus/iio/devices/iio:device0 lists all the available options and i'm able see the various scaling factor  but when i disconnect supply to the ad7193 hardware shouldn't the drive say that its not detected ? Its not showing that in my case and how do i test my device is working or not ? how do i confirm that device is present ?,and in my device tree for the interrupt pins i have written so


            fragment@4 {
                    target = <&gpio>;
                    __overlay__ {
                            ad7193_pins: ad7193_pins {
                                    brcm,pins = <25>;
                                    brcm,function = <0>;
                                    brcm,pull = <0>;
                            };
                    };
            };

    should the pull be 0 or should i change it to some other value accordingly ? Please look at it and let me know. Attaching an image below of how it works.

    Thanks in advance.

    -SK

  • Hi,

    I suggest that you follow the steps on the wiki under Driver Testing section: https://wiki.analog.com/resources/tools-software/linux-drivers/iio-adc/ad7192. Add a voltage source to your input channels and try commands like:

    cat in1_raw
    cat in_voltage1-in_voltage2_raw
    cat in_temp0_raw

    The driver tests for the device presence by reading the ID register only at startup when the device is probed: linux/ad7192.c at xcomm_zynq · analogdevicesinc/linux · GitHub . If this test fails, you will see the "device ID query failed" by typing dmesg .

    You probably don't need  ad7193_pins, so you can remove fragment@4.

    -Stefan

  • Hi ,

    I removed the fragment 4 as well as the pinctrl-0 = <&ad7193_pins> statement referring to those pins; and rebuilt the image

    and the ad7193 

    driver is loaded and also i tried to input an external voltage to the pins and tried to check it but it failed to show any other value than 0. I'm attaching the image below please look at it and let me know if what i'm doing is right.

    P.S:- Every time i connect the Dout pint to interrup i get the device ID query failed and when i remove it i get no error or so .