Arduino Leonardo and SPI Communications

I just found out that my favorite Arduino of choice (the Leonardo) has a problem with SPI  “Serial Peripheral Interface” communications (if you need to use the SS pin).  For SPI (which is bidirectional) , the following pins are normally used:

  • SS – Slave Select – digital 10. You can use other digital pins, but 10 is generally the default as it is next to the other SPI pins (except for on the Leonardo)
  • MOSI  – Master Out / Slave In – digital 11;
  • MISO – Master In / Slave Out  – digital 12;
  • SCK – Serial Clock – digital 13;

Unlike the Arduino Uno, the Leonardo has those pins on the ICSP (In-Circuit Serial Programming) header except for the SS pin which is not available. I found that out when I tried to get my Leonardo to communicate with an ENC28J60 ethernet module. (See my earlier article on connecting an Arduino to a LAN via an ENC28J60 module. The Arduino is the master and the module is the slave.) To make the Arduino Leonardo and SPI communications work,I had to modify the library code to use a pin other than the Leornardo SS default. Here is the wiring diagram:

Leonardo ENC28J60

Arduino Leonardo SPI -> ENC28J60 (click to enlarge)

If you prefer my Fritzing.org source code from which this graphic was created, you can get it HERE. I use the UIPEthernet library for the ENC28J60 module. To make it work for the Leonardo, I changed the Enc28J60Network.h file in the utility directory. Find this line:

#define ENC28J60_CONTROL_CS     SS

and change it to this:

#define ENC28J60_CONTROL_CS     10

The only problem with modifying the library is that you will need to remember to always use pin 10 for SS if that is not already the default (when setting up SPI for other Arduinos). Here is a good article on connecting arduinos using SPI for your further research.

2 comments

    • Vincenzo on October 27, 2015 at 11:47 am
    • Reply

    Hello,
    I’m trying to connect arduino Leonardo to MCP23S17 (spi 16bit I/O expander) using this library “http://playground.arduino.cc/Main/MCP23S17” i had already succesfully testing with arduino uno.
    i’m working with 1.6.3v IDE, what could it be the problem? thank you

      • earl on October 27, 2015 at 3:10 pm
        Author
      • Reply

      Hi, I think you will get a better response if you post your question on one of the forums here: http://forum.arduino.cc/ There will probably be someone there who is using that IC and library who can better help with your specific problem.

Leave a Reply

Your email address will not be published.