1

I'm trying to monitor some 4-20mA current loops and 0-10V generators with a RPi 3. I found these modules which would do the job:

https://widgetlords.com/products/pi-spi-2a0-raspberry-pi-analog-output-ma-vdc-interface for the 0-10V and 4-20mA generator

https://widgetlords.com/collections/pi-spi-din-series/products/raspberry-pi-din-rail-analog-input-interface for the inputs.

The problem is that both devices use different libraries, and these libraries use different 'dtoverlays'. They say on the web site to activate in the '/boot/config.txt'

dtoverlay = pi-spi for the output device

dtoverlay = vpe-2701c for the input device

I put the code of the overlays down

I don't know if I can uncomment both lines at the same time so I can run a script that takes input and generates outputs ...

I took a look on the net but the device trees are quiet difficult to understand for me.

Would it be a problem to have 2 device tree overlays used by the same script ?

pi-spi overlay:

/dts-v1/;
/plugin/;

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

    fragment@0 {
        target = <&spi0>;
        frag0: __overlay__ {
            #address-cells = <1>;
            #size-cells = <0>;
            pinctrl-0 = <&spi0_pins &spi0_cs_pins>;
            status = "okay";
            cs-gpios = <&gpio 8 1>,     /* 8KO */ 
                   <&gpio 7 1>,     /* 8AI */
                   <&gpio 4 1>,     /* 2AO */
                   <&gpio 17 1>,    /* 8DI */
                   <&gpio 22 1>;    /* SPARE */

            spidev@2{
                compatible = "spidev";
                reg = <2>;  /* CE2 */
                #address-cells = <1>;
                #size-cells = <0>;
                spi-max-frequency = <1000000>;
            };

            spidev@3{
                compatible = "spidev";
                reg = <3>;  /* CE3 */
                #address-cells = <1>;
                #size-cells = <0>;
                spi-max-frequency = <1000000>;
            };

            spidev@4{
                compatible = "spidev";
                reg = <4>;  /* CE4 */
                #address-cells = <1>;
                #size-cells = <0>;
                spi-max-frequency = <1000000>;
            };

        };
    };

    fragment@1 {
        target = <&spi0_cs_pins>;
        frag1: __overlay__ {
            brcm,pins = <8 7 4 17 22>;
            brcm,function = <1>; /* out */
        };
    };
};

vpe-2701c overlay:

/dts-v1/;
/plugin/;

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

    fragment@0 {
        target = <&spi0>;
        frag0: __overlay__ {
            #address-cells = <1>;
            #size-cells = <0>;
            pinctrl-0 = <&spi0_pins &spi0_cs_pins>;
            status = "okay";
            cs-gpios = <&gpio 8 1>,     /* CE0 */ 
                   <&gpio 7 1>,     /* CE1 */
                   <&gpio 24 1>,    /* CE2 */
                   <&gpio 23 1>,    /* CE3 */
                   <&gpio 18 1>;    /* CE4 */

            spidev@2{
                compatible = "spidev";
                reg = <2>;  /* CE2 */
                #address-cells = <1>;
                #size-cells = <0>;
                spi-max-frequency = <1000000>;
            };

            spidev@3{
                compatible = "spidev";
                reg = <3>;  /* CE3 */
                #address-cells = <1>;
                #size-cells = <0>;
                spi-max-frequency = <1000000>;
            };

            spidev@4{
                compatible = "spidev";
                reg = <4>;  /* CE4 */
                #address-cells = <1>;
                #size-cells = <0>;
                spi-max-frequency = <1000000>;
            };

        };
    };

    fragment@1 {
        target = <&spi0_cs_pins>;
        frag1: __overlay__ {
            brcm,pins = <8 7 18 23 24>;
            brcm,function = <1>; /* out */
        };
    };

    fragment@2 {
        target = <&i2c_arm>;
        __overlay__ {
            #address-cells = <1>;
            #size-cells = <0>;
            status = "okay";

            mcp7941x: mcp7941x@6f {
                compatible = "microchip,mcp7941x";
                reg = <0x6f>;
                status = "okay";
            };
        };
    };
};

1 Answer 1

2

You are NOT using "different 'dtoverlays'".

Libraries do NOT "use … 'dtoverlays'" they may use resources initialised by overlays.

Device Tree is a mechanism for configuring the hardware and modules which are loaded - more specifically for modifying the default settings by the default dtb.

I typically include ~6 in my configuration.

Provided the dtoverlays do not use the same resource there is no issue, although it appears these are both attempting to use the SPI interface.

The Pi has 2 SPI interfaces, so it may be possible to use both - with software changes.

The "documentation" linked is inconsistent, but a superficial reading indicates both use MOSI, MISO, SCLK (but different CE pins). SPI can be shared - this is normally mediated by CE pins and the kernel module supports 2 CE pins, but it is possible to use as many CE pins as desired, if the software is written to support this.

1
  • If I understand what you say, since both overlays here configure the GPIO associated with the SPI bus, but in differents ways, then the SPI bus won't know which GPIO to use. So I will have some problems of compatibility when runnning a script that use the SPI bus ? Apr 4, 2019 at 9:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.