1

I'm forced to use port /dev/spidev0.0 with a camera that I'm not able to configure at this time. Hence I need to change my current configuration where I'm using ENC28J60 on /dev/spidev0.0 and move it on a different port: /dev/spidev1.0 or /dev/spidev1.2 (spidev1.1/CE pin is used as an interrupt source from the camera itself). I googled for info but the only useful reference is this thread on RPi forum:

https://www.raspberrypi.org/forums/viewtopic.php?t=191180

that talks only about changing CE pin in terms of redefining (?) the overlay that's something I'm not proficient in. Someone managed to use a different port for ENC28J60 and can guide me in this process?

BTW I'm using Raspbian 9 (stretch) on a RPi3A+ (I would like to make it work on RPi0W also if possible)

2 Answers 2

3

As far as I can tell from /boot/overlays/README you need to add the following entry in /boot/config.txt (and remove or comment out any existing enc28j60 entry).

dtoverlay=enc28j60-spi2

From your forum link that should use chip enable 0.

The relevant part of the README is:

Name:   enc28j60-spi2
Info:   Overlay for the Microchip ENC28J60 Ethernet Controller on SPI2
Load:   dtoverlay=enc28j60-spi2,<param>=<val>
Params: int_pin                 GPIO used for INT (default 39)

        speed                   SPI bus speed (default 12000000)
6
  • Wow! Thnx. Hope it works.. I'll let you know.
    – weirdgyn
    Oct 23, 2019 at 11:54
  • What GPIO pins is 39? It's not a big problem since it can be changed but RPI has not 39 GPIO pins and pin 39 is a GND pin ...
    – weirdgyn
    Oct 24, 2019 at 9:45
  • another question... which spi is spi2? in all the docs I've looked into I found only reference of spi0 and spi1.
    – weirdgyn
    Oct 24, 2019 at 9:54
  • uhm looks like spi2 is only available on compute module not in standard RPi.
    – weirdgyn
    Oct 24, 2019 at 10:03
  • Pi actually has GPIO 0-53. Most Pis only have GPIO 0-27 connected to the outside of the board.
    – joan
    Oct 24, 2019 at 10:10
1

Following joan hint I found a possibile solution into making a new .dts (enc28j60-spi1-overlay):

// Overlay for the Microchip ENC28J60 Ethernet Controller - SPI1
// Interrupt pin: 25
/dts-v1/;
/plugin/;

/ {
    compatible = "brcm,bcm2708";

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

            status = "okay";

            eth1: enc28j60@0{
                compatible = "microchip,enc28j60";
                reg = <0>; /* CE0 */
                pinctrl-names = "default";
                pinctrl-0 = <&eth1_pins>;
                interrupt-parent = <&gpio>;
                interrupts = <25 0x2>; /* falling edge */
                spi-max-frequency = <12000000>;
                status = "okay";
            };
        };
    };

    fragment@1 {
        target = <&gpio>;
        __overlay__ {
            eth1_pins: eth1_pins {
                brcm,pins = <25>;
                brcm,function = <0>; /* in */
                brcm,pull = <0>; /* none */
            };
        };
    };

    __overrides__ {
        int_pin = <&eth1>, "interrupts:0",
                  <&eth1_pins>, "brcm,pins:0";
        speed   = <&eth1>, "spi-max-frequency:0";
    };
};

And compiling it with:

sudo dtc -I dts -O dtb -o /boot/overlays/enc28j60-sp1.dtbo enc28j60-spi1-overlay.dts

And finally enabling it in /boot/config.txt:

dtparam=spi=on          #enable spi
dtoverlay=spi1-1cs      #enable spi1 (and CE0, CE1)
dtoverlay=enc28j60-spi1 #enable enc28j60 module on spi1 port

I tested it on my LAN and it seems to works fine (not worse than using default spi0 port).

I found a pretty similar solution here:

https://www.raspberrypi.org/forums/viewtopic.php?t=224915

You can use it also but beware it assign by default enc28j60 interrupt to pin 39 and this will not work on standard RPi boards (such pin is user availabe only on Compute Module).

6
  • 1
    Works great. Thank you. If I could give 10 upvotes I would.
    – Noel
    Mar 29, 2021 at 20:00
  • one upvote is more than enogh.
    – weirdgyn
    Mar 30, 2021 at 10:16
  • Great work @weirdgyn , I have a followup question <raspberrypi.stackexchange.com/q/139936/114130> I wanted to both spi0 and spi1 to be enabled parallely as 2 ethernet port is required. I have tried but not seeing success. Kudos. Nov 17, 2022 at 7:55
  • 1
    @HarishPatil I don't know if I can be of any help .. in my solution I needed to switch from the standard configuration to an alternative using different port/pin mappings ... in your case you wish to run multiple copies of the enc28j60 driver. IMHO this may work or not work but it depends on the driver structure itself not the configuration
    – weirdgyn
    Nov 17, 2022 at 8:25
  • @weirdgyn after some research I am thinking why cant I use spi1 on enc2860 module and spi0 for wiznet w5500 module, thats a separate kernel driver. So i started making enc2860 on spi, but not with good success. I Just wanted to understand which pin you have used in as interrupt pin 39 mentioned above. If you write some answer with pin diagram It would be worth lot upvotes. Nov 18, 2022 at 10:36

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.