MOD-ENC28J60 and Linux (Debian/GNU)

Started by leo, December 03, 2012, 05:43:03 PM

Previous topic - Next topic


Wow, sorry, the correct would be:

while(--poll_time > 0) {/* txFIFO counter */
  if(aw_spi_query_txfifo(base_addr)) {      
          poll_time++; // a little more time
  } else {


This looks to be a potentally dangerous code: if there is 1 byte stuck in the fifo and you can't send that byte, you are inside an endless loop, because poll_time never decreases...

Today I'm going to take a deeper look to the code... Let's see if I can find a solution...

If you have any other ideas you're welcome!
Thank you.


We really have to find a solution. This probably is not the best, I could not think of other. But the variable always decreases, independent if() be true or false.

About patch, could you submit it?

My enc28j60 arrived yesterday, I can now do the tests.  ;D

As you know that rx packets are wrong?


Fine, so you can also do some tests...
RX is fine now, we have only some issue for tx timout wich forces the network to reset, but RX works like a charm...

If the if() statement is always true you have: --poll_time and then poll_time++... So you actually don't change the value of the variable...

I was waiting to submit the patch to see if we find a solution for this issue... This afternoon I try anyway... Meanwhile you can use the link to the patched module...




I've submitted the patch, now let's wait for the replay...




after a lot of test, it seems that the problem with TX timeout is related to SPI speed: with 10MHz the enc28j60 works far better. Some tx errors are still present but with a very low frequency...

Please use it with 10MHz clock configuration!

Use this script.bin and module: (I did some small changes).

2013-02-05 17:10:28 (195 KB/s) - `VirtualBox-4.2.6-82870-Win.exe' saved [97461672/97461672]



Nice! ;D Finally a functional enc28j60!

I have not had time to test it.  :-[

I'm trying to run the a13-olinuxino-micro...

I have a question, how you configured the external interruption?


Hi lorenzo,

I talked to amery, he said: "the sunxi driver should be fixed to coexist with mainlined code, not the other way around."

So we need to change spi_sunxi.c, not enc28j60.c, taking into account that enc28j60.c is in the mainline.

In that case I'll submit a patch for spi_sunxi.c


Where truly is the problem?  If it's in the mainline code then THAT is what should be fixed.  But only if it's there.



Hi all,

mmhhhh... well I don't think we can fix only spi_sunxi.c file, because IRQ management should be fixed in the enc28j60 driver, we can't fix it in the spi_sunxi module (maybe we can do IRQ registration, but I'm not sure about that)...
Well actually the enc28j60 patch should work only with A13, so maybe it cannot be merged with mainline version...

Anybody knows if it is possible to create a enc28j60 sunxi version of the driver?




Which pins must be connected? I connected the wires: SCK, MOSI, MISO, INT, 3V3, GND and CS

I'm always getting this error: "link down"



maybe RST is missing. Did you buy the MOD-ENC28J60 (
You can check the connection on the schematic, but if you connect all the pins correctly it shouldn't be any problem.

Did you check script.bin file?

Talking to Alejandro about enc28j60 patch he told me that the only way is to produce a sunxi driver version, because I must change the module code to make it work correctly.
Next days I'll try to submit a modified version of the driver, with comments and informations about code changes, but I'm not sure it will be accepted to be part of the kernel...

Lorenzo Nava


hi lorenzo,

yes, I bought MOD-ENC28J60, but I'm not using the cable that came with it, i use wires. i hate wires >:(
RST i leave not connected.

I reviewed the original code(enc28j60.c), it seems that he really needs to be changed. because spi_read_op() and spi_write_op do not set up .cs_change. However using an oscilloscope I see the CS pin down and then up, but I do not understand how that happens.  :o

spi_sunxi.c: line 979 and 994

/* update the new cs value */
cs_change = t->cs_change;
/* if zero ,keep active,otherwise deactived. */
   if (cs_change) {
aw_spi->cs_control(spi, 0);


Hi vinifr,

the other problem is that if you don't set tx_buf and rx_buf to NULL alternatively the DMA works with full duplex mode, and not with half duplex. The only way to make enc28j60 work is o use half duplex DMA transfers, so changes to enc28j60 are mandatory...

About enc28j60, it's very strange. What does dmesg report?