I want to connect Ethernet board (W5100 HR911105A) to Arduino Leonardo with SPI and I also want to connect SD reader. When I test these boards separately everything working. But when I connect them on the same board the program fails at Ethernet.begin();

#include <SPI.h>
#include <Ethernet.h>
#include <SD.h>

#define SS_SD_CARD  4
#define SS_ETHERNET 10

const char CONFIG_FILE[] = "system.cfg";

byte C_MAC[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress S_IP(192,168,0,19);
IPAddress C_IP(192, 168, 0, 177);
const uint16_t  S_PORT = 8090;

EthernetClient client;

void setup() {
    while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
    pinMode(SS_SD_CARD, OUTPUT);

    digitalWrite(SS_SD_CARD, HIGH);
    digitalWrite(SS_ETHERNET, HIGH);

    digitalWrite(SS_SD_CARD, LOW);
    digitalWrite(SS_SD_CARD, HIGH);

    Serial.println("Setup ethernet");
    digitalWrite(SS_ETHERNET, LOW);
    if (Ethernet.begin(C_MAC) == 0) {
      Serial.println("Failed to configure Ethernet using DHCP");
      Ethernet.begin(C_MAC, C_IP);
    bool result = client.connect(S_IP, S_PORT);
    digitalWrite(SS_ETHERNET, HIGH);

void loop() {

I tried on Leonardo and Mega 2560.

  • So are you saying that if you have only the W5100 connected to the Leonardo it works fine but once you connect the SD reader it doesn't work? Also, it's SPI, not ISP. ISP stands for In-System Programmer, which is something completely different.
    – per1234
    Commented Aug 16, 2017 at 6:01
  • Yes this is what I am saying. When I connect both device to SPI only the card reader working and read data from the card, and the ethernet fail at the mentioned point. But if I only connect the ethernet it is working.
    – eszik.k
    Commented Aug 16, 2017 at 7:25
  • When you test individually as you describe, are the SS pin numbers the same (4 and 10)?
    – Nick Gammon
    Commented Aug 24, 2017 at 6:50
  • What SD reader are you using? Can you describe the exact wiring?
    – Nick Gammon
    Commented Aug 24, 2017 at 6:51

3 Answers 3


Some card reaaders (as well as display boards with built-in sd socket) use 10-kOhm resistors in series to the CS, DIN and CLK lines, to perform a cheap 5V to 3.3V level translation. This is really not the best solution, especially in terms of speed (we verified that typically this limits the maximum SPI speed to about 1 MHz).

Other cards readers (such as this one http://modtronix.com/mod-sdcard-l5.html), just use 10 k-Ohm resistors as pull-up to 3.3V. Therefore you're connecting all the SD card lines to the Leonardo board, which is 5V level. This will cause serious issues to the SD card or to the leonardo board. If your card reader falls in this second case, I suggest you to insert a resistor divider (1k + 1.5k) in series to each input lines of the SD card: DIN, CLK, CS. In the following schematics I just show for the CLK line, of course you have to repeat this three times. A much better idea would be a level translator IC.


simulate this circuit – Schematic created using CircuitLab


If you have a similar SD card reader like below (or same but with micro SD card), than I had exactly the same problem.

It works as single device on SPI, but not together with another SPI device.

You can either use a SD recorder proto board, or use a microcontroller that has multiple SPIs.

SD breakout

An example of the SD recorder I used and works with another SPI device on one SPI port.

Cons: bigger, more expensive Pro: has a RTC and proto space.

SD Recorder

  • Yes, I have similar card reader as you showed. I hope there is a solution for this problem. ebay.com/itm/…
    – eszik.k
    Commented Aug 16, 2017 at 11:31
  • I used until recently the SD recorder shield, but I'm moving to STM32 which has multiple SPI ports, so I can cannot probably (no tried) a simple SD card reader as you have to one port, and other peripherals (like a RF radio) to another SPI. Commented Aug 16, 2017 at 12:34
  • 2
    @MichelKeijzers - I've never used an SPI device (always been an I2C child) but I thought the idea was you used the CS lead to control what gets the message. From what you have said I assume there is more to it than that. Commented Aug 18, 2017 at 12:32
  • 4
    @CodeGorilla you are right, the CS (Chip Select, or SS: Slave Select) decides who gets the message. Normally one of the CS pins is low and the others are high. The SPI device with CS low pin can communicate with the master. All MISOs and MOSIs have to be coupled, and some devices (like the cheap SD card reader) does not support it ... I don't know the reason. Commented Aug 18, 2017 at 13:05

i suspect the reason is due to how the inputs/outputs are designed, the W5100 appears to be a 3v3 board with 5V compatible inputs, as does the link you posted to the SD reader, however depending on how these inputs/outputs are designed can mean they won't "play nice" with other boards on the same bus even though SPI is designed to do that.

depending on where the problem lies there are a few potential solutions, if (as i suspect) the problem is the output from the devices back to the arduino (ie you can write to them but not read from them) which you could confirm by connecting all lines in parallel, but only connecting one of the serial lines back to the arduino and check that it works, then swap the serial to the other device and check that. assuming that both devices work in this configuration you only need to fix the return signal. the simplest way of doing this would be to use two tri state buffers.

so the return signal is only connected to the arduino when that devices select line is active. and high impedance (disconnected) otherwise, programatically disconnecting one device from the bus.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.