Adding Ethernet Port to Raspberry Pi


There are a lot of ways to add ethernet port to Raspberry Pi.(I know only two ways) For instance, you may use usb to ethernet adapter. I want to tell an other way to do this. We can do this using Enc28j60.


You can buy Enc28j60 from Dx, Aliexpress, Ebay easily.

Before adding ethernet to Raspberry Pi, you must know that it will run slow. Because we use SPI interface. When you added port, you have about 3 mbit/s speed. Furthermore, I don’t know whether robust or not but I’m sure it runs.


Compiling Kernel

Firstly, We will compile Raspberry Pi kernel. We prefer to compile kernel using cross-compile because of speed. I use debian based OS for cross-compile. You can use your favorite Linux distro.

We download the compile tools from following git address:


git clone


You haven’t git, use following command:


sudo apt-get install git


Download the Raspberry Pi source code using following address:


git clone



Raspberry Pi Tools present several types of compilers:

  • tools/arm-bcm2708/arm-bcm2708hardfp-linux-gnueabi
  • tools/arm-bcm2708/arm-bcm2708-linux-gnueabi
  • tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian

The last one is the toolchain containing the linaro patches, so we will use it for cross-compilation. Set the CCPREFIX environment variable to the prefix of the third toolchain and test it by invoking GCC using the prefix, e.g:


export CCPREFIX=/home/testuser/raspberry/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/bin/arm-linux-gnueabihf-”


Before we can build the kernel we need to configure it. A very good starting point would be the configuration file from your existing Raspberry PI that can be obtained by reading and unpacking the /proc/config.gz file on Raspberry PI. Go to the ‘linux’ subdirectory with the downloaded kernel sources and run the following command there:


gunzip -c config.gz .config


After that, Find bcm2728.c file in your kernel folder and open it.


Find bcm2708_spi_devices[] word. If you find it, edit as following lines:


static struct spi_board_info bcm2708_spi_devices[] = {
.modalias = “enc28j60”,
.max_speed_hz = 12000000,
.bus_num = 0,
.chip_select = 0,
.mode = SPI_MODE_0,
.irq = ((25) + GPIO_IRQ_START),
}, {
.modalias = “spidev”,
.max_speed_hz = 500000,
.bus_num = 0,
.chip_select = 1,
.mode = SPI_MODE_0,



After editing is finished, save your file.

Open “your_kernel_folder/linux/drivers/net/ethernet/microchip/enc28j60.c” file and find “request_irq”. Replace it with following line;

ret = request_irq(spi->irq, enc28j60_irq, IRQF_TRIGGER_FALLING, DRV_NAME, priv);

Open .config file with your favorite text editor and remove “#” from beginning of “CONFIG_ENC28J60”. After that, We change as follows:



Run the following command in the Linux kernel source directory to bootstrap the new kernel configuration from the .config file obtained from Raspberry Pi.


ARCH=arm CROSS_COMPILE=${CCPREFIX} make oldconfig


Do not forget to specify ARCH. Otherwise the kernel will be configured using x86 configuration options and will be missing ARM ones leading to a build failure. Use -j parameter for using multicore processing.

“ARCH=arm CROSS_COMPILE=${CCPREFIX} make -k -j 9”

Now that We will need to generate a directory containing kernel modules that Raspberry PI can load when needed. Run the following command to copy the modules to the ‘modules’ directory.


ARCH=arm CROSS_COMPILE=${CCPREFIX} INSTALL_MOD_PATH=your_kernel_folder/modules make modules_install


We will create an uncompressed kernel image and upload it to the temporary directory on Raspberry PI. Run the following commands on your build machine:

cd ../tools/mkimage/
./ ${KERNEL_SRC}/arch/arm/boot/zImage


Now, move the created file to Raspberry Pi:
Derleme Platformu -> Raspberry Pi
kernel_klasörünüz/tools/mkimage/kernel.img -> /boot/kernel.img
kernel_klasörünüz/modules/lib/firmware -> /lib/firmware
kernel_klasörünüz/modules/lib/modules -> /lib/modules

Restart your Raspberry and kernel is ready to your use.

Connecting Pins

Pin map is as following:

ENC28J60 – Rasberry Pi
VCC   –   3v3  (pin 1)
GND   –   GND ( pin 9)
CS    –   CE0 (gpio 8 / pin 24)
SI    –   MOSI (gpio 10 / pin 19)
SCK   –   SCKL (gpio 11 / pin 23)
SO    –   MISO (gpio 9 / pin 21)
INT   –   GPIO25 (pin 22)

You can check whether run or not using “ifconfig” command.

I shared compiled kernel file (Raspberry Pi 3.18.7+) following lines. You can use those files for your Raspberry.


Kernel Image


Bir cevap yazın

E-posta hesabınız yayımlanmayacak. Gerekli alanlar * ile işaretlenmişlerdir

This site uses Akismet to reduce spam. Learn how your comment data is processed.