Add a enc28j60 Ethernet interface

From www.chip-community.org
Jump to: navigation, search

enc28j60 is a quite cheap integrated 10Mbps Ethernet controller.

There are many modules available: on a small PCB there are commonly the enc28j60, a RJ45 connector (with the transformers inside), and some other components (including a quartz oscillator). In this test I have used this: [1]

Many others can be found looking for "enc28j60" on e-bay or amazon.

First of all, the standard kernel currently provided with chip (april 2016) does not support spi in its device tree and its spi driver must be patched to work with enc28j60.

A kernel compatible with enc28j60 can be downloaded following the instructions of the page: A new kernel and device tree: rd235b. (load the device tree named: sun5i-r8-chip.rd235b.enc28j60.dtb)

How to connect the module

Usually, Enc28j60 modules have the following pins (the first number on the left is the pin number for my module, the sequence changes on other modules but the set of signals should be the same, sorted in a different manner).

  • 1 SCL -> U14 pin 28 (tag CSICK) is SPI2-CLK
  • 2 MOSI -> U14 pin 29 (tag CSIHSYNC) is SPI2-MOSI
  • 3 MISO -> U14 pin 30 (tag CSIVSYNC) is SPI2-MISO
  • 4 Wake on Lan -> NC (it could be used to switch CHIP on)
  • 5 INT -> U14 pin 23 (tag PG1/EINT1)
  • 6 CLKOUT -> NC
  • 7 CS -> U14 pin 27 (tag CSIPCK) is SPI2-CS0
  • 8 RST -> NC
  • 9 GND -> some GND pin (e.g. U14 pin 1)
  • 10 +3.3V -> U14 pin 9 (non alpha chip, it seems it can can provide the required current).

Important: do not connect the module using a breadboard. The baudrate is quite high (12Mhz), there are interferences between rows due to parasite capacitance on breadboard contacts. I tried it myself and it did not work.

This is a picture of one of my chips wearing a DIY hat interface to the ethernet module:

Enchat.jpg

The network should be up and running

Reboot.

You should see eth0.

$ ip addr
...
5: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether b6:17:b3:d1:31:3f brd ff:ff:ff:ff:ff:ff
    inet 192.168.1.190/24 brd 192.168.1.255 scope global dynamic eth0
       valid_lft 507sec preferred_lft 507sec
    inet6 fe80::b417:b3ff:fed1:313f/64 scope link 
       valid_lft forever preferred_lft forever
...

(if you have not disabled dhcp, and the dhcp service is active on your net, eth0 will take its address from the nearest router).

Performance

It is a 10Mbps half duplex ethernet, the performance is not so high, but this interface can be effectively used in many IoT applications.

Using iperf I've got the following results:

Laptop server -> CHIP client

[  3]  0.0-10.3 sec  4.62 MBytes  3.76 Mbits/sec
[  3]  0.0-10.3 sec  4.62 MBytes  3.76 Mbits/sec
[  3]  0.0-10.4 sec  4.62 MBytes  3.73 Mbits/sec

CHIP server -> Laptop client

[  3]  0.0-10.5 sec  7.62 MBytes  6.11 Mbits/sec
[  3]  0.0-10.9 sec  9.38 MBytes  7.21 Mbits/sec
[  3]  0.0-10.1 sec  8.50 MBytes  7.07 Mbits/sec