ENC28J60 with microSD not working

hello,

spent quite some time with my uno now trying to get my network module to serve a website with the directory contents of the root folder of an sd card.

the microSD module alone works fine with the SD/listfiles example.

the network module alone works fine with the EthernetENC library with the webserver example, #include “Ethernet.h” replaced by “EthernetENC.h”.

but when the microSD gets powered the network module doesn’t work anymore, saying it couldn’t find the ethernet hardware, if i ignore this message the sd card still works fine.

the wiring:
arduino SCK/MISO/MOSI are hooked to a rail each from which they connect to the modules.

microSD:
vcc → 5v
gnd → gnd (common)
cs → 4

network:
vcc → 3.3v
gnd → gnd (common)
cs → 10

i checked the wires several times.
here is the code of the sketch trying to get both running:

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

byte mac[] = {
  0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED
};
IPAddress ip(192, 168, 0, 101);
EthernetServer server(80);
File root;

void setup() {
  Serial.begin(9600);
  Serial.println("Ethernet WebServer Example");

  if (!SD.begin(4)) {
    delay(1000);
  }
  Serial.println("SD initialization done.");

  Ethernet.init(10);
  Ethernet.begin(mac, ip);
  //Ethernet.begin(mac);
  server.begin();

  Serial.println(Ethernet.localIP());
}

EthernetClient client;

char header[] = "HTTP/1.1 200 OK\r\n"
                "Content-Type: text/html\r\n"
                "Connection: close\r\n"
                "\r\n"
                "<!DOCTYPE HTML>"
                "<html><body>";

void loop() {
  client = server.available();
  if (client) {
    Serial.println("New client");
    boolean currentLineIsBlank = true;

    while (client.connected()) {
      Serial.println("Client connected");

      if (client.available()) {
        char c = client.read();
        if (c == '\n' && currentLineIsBlank) {
          client.println(header);
          printDirectory();
          client.println("</body></html>");
          break;
        }
        if (c == '\n') {
          currentLineIsBlank = true;
        } else if (c != '\r') {
          currentLineIsBlank = false;
        }
      }
    }

    delay(1);
    client.stop();
  }
}

void printDirectory() {
  root = SD.open("/");

  while (true) {
    File entry =  root.openNextFile();
    if (!entry) {
      break;
    }

    client.print(entry.name());
    if (entry.isDirectory()) {
      client.print("/");
    } else {
      client.println(entry.size(), DEC);
    }
    entry.close();
    client.print("
");
  }
}

Some SD Card modules don’t play nicely on the SPI bus. They have a chip, used for level shifting, that drives the MISO pin even when the CS pin is HIGH (not selected). That interferes with any other device on the SPI bus. The only way I know of to be sure is to trace the circuits of the SD Card module. :frowning:

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.