SPI ethernet (enc28j60) not quite working

I’ve got an Arduberry and in my box of bits I have a cheap chinese enc28j60 card.

I’ve also got a regular ethernet shield for an Arduino (but that won’t work with the Arduberry without adding the ICSP pins).

So I’ve downloaded http://github.com/jcw/ethercard and built one of the sample sketches (…/ethercard/examples/rbbb_server/rbbb_server.ino).

Everything works OK with compiling and uploading the sketch (I tweaked it to use pin 10 as the CS/SS pin. By default it uses pin 13 for SCK, pin 12 for MISO & pin 11 for MOSI) but it doesn’t connect to my network.

Curiously, when I shutdown the Raspberry Pi host with sudo shutdown -h now, then hit the Arduberry reset button then things work as expected.

If I then reboot the Raspberry Pi it continues to run.

The puzzle (and the reason for the post) what’s preventing the SPI interface on the Arduberry from running? What can I tweak on the Raspberry Pi to fix it? Or would I need to update the Arduino IDE with a new …/hardware/arduino/variants/*/pins_arduino.h to completely change the SPI pins used for the arduberry?

It looks like the SPI pins on the Raspberry Pi are interfering with the SPI on the Arduberry. The SPI pins are used by the Raspberry Pi to upload the code to the Arduberry.

Disabling the SPI on the Raspberry Pi might help but you won’t be able to upload the code to the Arduberry. Another thing that might help would be to make the Raspberry Pi CS pin’s as logic HIGH.
To do this, first change the mode to output for both CE0 and CE1:

gpio mode 10 OUTPUT
gpio mode 11 OUTPUT

and then set both the lines to logic HIGH:

gpio write 10 1
gpio write 11 1

This might work but the moment you upload the code this wil be set back to the default mode. Do try this and let me know if it works.

I tried a few options then looked at the pins status with WebIOPi. Setting GPIO 9, 10, 11 & 8 as input then resetting the Arduberry works.

With WiringPi the pin numbers are different (because of the multitude of names).

So I took a look with gpio readall

root@pi /etc # gpio readall
 +-----+-----+---------+------+---+-Model B2-+---+------+---------+-----+-----+
 | BCM | wPi |   Name  | Mode | V | Physical | V | Mode | Name    | wPi | BCM |
 +-----+-----+---------+------+---+----++----+---+------+---------+-----+-----+
 |     |     |    3.3v |      |   |  1 || 2  |   |      | 5v      |     |     |
 |   2 |   8 |   SDA.1 |   IN | 1 |  3 || 4  |   |      | 5V      |     |     |
 |   3 |   9 |   SCL.1 | ALT0 | 1 |  5 || 6  |   |      | 0v      |     |     |
 |   4 |   7 | GPIO. 7 |  OUT | 0 |  7 || 8  | 1 | ALT0 | TxD     | 15  | 14  |
 |     |     |      0v |      |   |  9 || 10 | 1 | ALT0 | RxD     | 16  | 15  |
 |  17 |   0 | GPIO. 0 |  OUT | 0 | 11 || 12 | 0 | OUT  | GPIO. 1 | 1   | 18  |
 |  27 |   2 | GPIO. 2 |  OUT | 0 | 13 || 14 |   |      | 0v      |     |     |
 |  22 |   3 | GPIO. 3 |  OUT | 0 | 15 || 16 | 0 | OUT  | GPIO. 4 | 4   | 23  |
 |     |     |    3.3v |      |   | 17 || 18 | 0 | OUT  | GPIO. 5 | 5   | 24  |
 |  10 |  12 |    MOSI |  OUT | 0 | 19 || 20 |   |      | 0v      |     |     |
 |   9 |  13 |    MISO |   IN | 0 | 21 || 22 | 0 | IN   | GPIO. 6 | 6   | 25  |
 |  11 |  14 |    SCLK |  OUT | 0 | 23 || 24 | 1 | OUT  | CE0     | 10  | 8   |
 |     |     |      0v |      |   | 25 || 26 | 0 | IN   | CE1     | 11  | 7   |
 +-----+-----+---------+------+---+----++----+---+------+---------+-----+-----+
 |  28 |  17 | GPIO.17 |   IN | 0 | 51 || 52 | 0 | IN   | GPIO.18 | 18  | 29  |
 |  30 |  19 | GPIO.19 |   IN | 0 | 53 || 54 | 0 | IN   | GPIO.20 | 20  | 31  |
 +-----+-----+---------+------+---+----++----+---+------+---------+-----+-----+
 | BCM | wPi |   Name  | Mode | V | Physical | V | Mode | Name    | wPi | BCM |
 +-----+-----+---------+------+---+-Model B2-+---+------+---------+-----+-----+
root@pi /etc #

Pins 12 MOSI, 14 SCLK and 10 CE0 are set as output so I toggled those to INPUT with

gpio mode 10 input
gpio mode 12 input
gpio mode 14 input

Note I had to use the WiringPi numbers not the GPIO numbers for that stuff.

If I then hit the reset button on the Arduberry, it starts working.

Thanks a lot for testing it out and letting us know about the configurations that worked for you.