Arduino Leonardo and Ethernet with 1.0.1

Want to use Ethernet on a Leonardo board? Me too, and I started playing with it in Arduino 1.0. I was succeeding too. Then Arduino 1.0.1 was released and I noticed a few things.

Remember how the recent Ethernet Shield started using the ICSP header for access to the SPI interface? On the product page it seems like they did it for the MEGA board which uses pin 50, 51, 52 instead of 11, 12, and 13 for the SPI bus. Turns out it’s handy for the Leonardo board which doesn’t expose the hardware SPI pins through the regular pins on board. In fact, the hardware SS pin is used for the RX LED on a Leonardo.

I wired up a Wiznet module to the SPI bus on an ATMEGA32U4 breakout board and since I used the hardware SS pin just like a normal ATMEGA328 Arduino it worked great with 1.0 and then 1.0.1 released and nothing. I thought the library was broken and I started telling everyone I could. I tore into the library and saw the SS pin handling changed to use PORTB6. I thought that was dumb and was about to change it. I started looking at the schematic for the Ethernet Shield and the pin mapping of the Leonardo board instead. I realized the shield would connect SS to pin 10, and pin 10 on a Leonardo is PORTB6 which is not the hardware SS pin. (PORTB4 is used on MEGAs and PORTB2/SS on UNO and older ATMEGAx28 boards.)

I quickly rewired my module and found success.

If you’re lucky enough to have a new Arduino Leonardo already and want to add Ethernet be sure your shield or module grabs the SPI bus from ICSP header. This is also an issue for SD/MicroSD card access…but that’ll be another post.

Comments are closed.