Skip to content
View in the app

A better way to browse. Learn more.

Armbian Community Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

NanoPi NEO Core-LTS how to use a 2 slave spi device ?

Featured Replies

I have board  which has 2 slaves on the SPI bus, requiring ce0 and ce1. 

My system: Armbian 23.8.1 Bookworm with Linux 6.1.47-current-sunxi

I applied overlays: spi-add-cs1 and spi-spidev, there's an spi in the system.

As soon as I apply spi-double-spidev-bus.dts, the spi disappears. 

Скрытый текст

/dts-v1/;
/plugin/;

/ {
    compatible = "allwinner,sun4i-a10", "allwinner,sun7i-a20", "allwinner,sun8i-h3", "allwinner,sun50i-a64", "allwinner,sun50i-h5";

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

            spidev@0 {
                reg = <0>; /* Chip Select 0 */
                compatible = "spidev";
                spi-max-frequency = <1000000>;
                status = "okay";
            };
        };
    };

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

            spidev@0 {
                reg = <0>; /* Chip Select 0 */
                compatible = "spidev";
                spi-max-frequency = <1000000>;
                status = "okay";
            };
        };
    };
};

How to make two cs?

As soon as I apply spi-double-spidev-bus.dts, the spi disappears. 
Also, as I assume there is a problem with CS1, I reassign it with my overlay:   

Скрытый текст

/dts-v1/;
/plugin/;

/ {
        compatible = "allwinner,sun8i-h3";

        fragment@0 {
                target = <&pio>;
                __overlay__ {
                        spi0_cs1: spi0_cs1 {
                                pins = "PC3";
                                function = "gpio_out";
                                output-high;
                        };
            
                };
        };

        fragment@1 {
                target = <&spi0>;
                __overlay__ {
                        pinctrl-names = "default", "default";
                        pinctrl-1 = <&spi0_cs1>;
                        cs-gpios = <&pio 2 3 0>; /* PC3 */
                };
        };

};
 


CS is reassigned in the system, but the spi device polls once. When polling again, errors occur. When I manually set the cs there are no re-polling errors.   

I use "spi-device" - accessing the SPI serial bus using Node.js on Linux boards https://github.com/fivdi/spi-device

On another board, the author's "spi-device" SPI polling works without problems https://github.com/fivdi/spi-device/issues/27 

Please help to make sense of these two issues.
   

  • Author

I installed my overlay: 

Скрытый текст

/dts-v1/;
/plugin/;

/ {
    compatible = "allwinner,sun8i-h3";

         fragment@2 {
                target = <&pio>;
                __overlay__ {
                        spi0_pi_pins: spi0-pi-pins {
                                pins = "PC0", "PC1", "PC2";
                                function = "spi0";
                        };

                        spi0_cs0_pi_pin: spi0-cs0-pi-pin {
                                pins = "PC3";
                                function = "spi0";
                        };

                        spi0_cs1_pi_pin: spi0-cs1-pi-pin {
                                pins = "PG8";
                                function = "spi0";
                        };
                };
        };


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

                        pinctrl-names = "default";
                        pinctrl-0 = <&spi0_pi_pins>;
                        spi-max-frequency = <1000000>;
                        num-chipselects = <2>;
                        spidev@0 {
                                reg = <0>; /* Chip Select 0 */
                                compatible = "armbian,spi-dev";
                                pinctrl-names = "default";
                                pinctrl-0 = <&spi0_cs0_pi_pin>;
                                status = "okay";
                        };

                        spidev@1 {
                                reg = <1>; /* Chip Select 1 */
                                compatible = "armbian,spi-dev";
                                pinctrl-names = "default";
                                pinctrl-0 = <&spi0_cs1_pi_pin>;
                                status = "okay";
                        };
                };
        };
};

two spi's appearing: 
den@nanopineo:~$ ls /dev/ | grep spi
spidev0.0
spidev0.1

den@nanopineo:~$ sudo cat /sys/kernel/debug/gpio
gpiochip0: GPIOs 0-223, parent: platform/1c20800.pinctrl, 1c20800.pinctrl:
 gpio-67  (                    |spi0 CS0            ) out hi ACTIVE LOW
 gpio-166 (                    |cd                  ) in  hi ACTIVE LOW
 gpio-200 (                    |sysfs               ) out hi
 gpio-203 (                    |sysfs               ) in  lo
 gpio-204 (                    |usb0_id_det         ) in  hi IRQ

gpiochip1: GPIOs 352-383, parent: platform/1f02c00.pinctrl, 1f02c00.pinctrl:
 gpio-355 (                    |k1                  ) in  hi IRQ ACTIVE LOW
 gpio-358 (                    |vdd-cpux            ) out lo
 

den@nanopineo:~$ dmesg | grep spi
[    2.600676] spidev@0 enforce active low on chipselect handle
[    4.022764] sun8i-h3-pinctrl 1c20800.pinctrl: unsupported function spi0 on pin PG8
[    4.022867] spidev spi0.1: there is not valid maps for state default
https://paste.armbian.com/yurepiyuve 

 spi 0.0 doesn't work!
How do I get it to work ? And set PG8 as cs1? 

Edited by DenisS

1 hour ago, DenisS said:

spi0_cs1_pi_pin: spi0-cs1-pi-pin {
                                pins = "PG8";
                                function = "spi0";
                        };

Based on the schematics of the board, PG8 only support uart1 or gpio function. So you can't set function = spi0 for the same.

 

Now this is a shot in the dark, but may by you can experiment with cs-gpios property.

2 часа назад, DenisS сказал:

spi0_cs0_pi_pin: spi0-cs0-pi-pin {
                                pins = "PC3";
                                function = "spi0";
                        };

                        spi0_cs1_pi_pin: spi0-cs1-pi-pin {
                                pins = "PG8";
                                function = "spi0";

function = "gpio_out";

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.