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