简体   繁体   中英

Arduino Mega + ENC28J60 ethernet module is hanging on ether.begin

I bought an Ethernet module for my Arduino Mega and I'm unable to start it. After some checking I found that the library for this chip hangs on calling ether.begin and I'm not sure why.

Here is the code. I'm using a modified "backSoon" from the library's example folder, so I'm posting only the setup() function (the rest is irrelevant anyway, because of the titular bug):

void setup(){
  pinMode(LED_BUILTIN, OUTPUT);
  Serial.begin(57600);
  Serial.println("\n[backSoon]");
  Serial.print("Slave=");
  Serial.println(SS);
  Serial.print("MOSI=");
  Serial.println(MOSI);
  Serial.print("SCK=");
  Serial.println(SCK);
  Serial.print("MISO=");
  Serial.println(MISO);
  Serial.print("LED=");
  Serial.println(LED_BUILTIN);

  // Change 'SS' to your Slave Select pin, if you arn't using the default pin
  uint8_t status = ether.begin(sizeof Ethernet::buffer, mymac, SS);
  Serial.print("Status: "); Serial.println(status);
  Serial.flush();
  if (status == 0) {
    Serial.println( "Failed to access Ethernet controller");
    digitalWrite(LED_BUILTIN, LOW);
    while(true);
  } else {
    digitalWrite(LED_BUILTIN, HIGH);
  }
#if STATIC
  Serial.println("Setup static");
  ether.staticSetup(myip, gwip);
#else
  Serial.println("Trying DHCP");
  if (!ether.dhcpSetup())
    Serial.println("DHCP failed");
#endif

  ether.printIp("IP:  ", ether.myip);
  ether.printIp("GW:  ", ether.gwip);
  ether.printIp("DNS: ", ether.dnsip);
}

The code with a lot of Serial calls is there because I wasn't sure if I connected the Ethernet module right, so I printed all pins the library uses (I lurked into the library's source).

The output on serial is:

[backSoon]
Slave=53
MOSI=51
SCK=52
MISO=50
LED=13

[backSoon]
Slave=53
MOSI=51
SCK=52
MISO=50
LED=13

(yes it is doubled, which is also strange)

As the title says I'm pretty sure the problem lies in the ether.begin(...) invocation as none of the serial prints after it are printed.

I'm afraid I might burned the module, but first I want to hear if there could be any other possible explanation for my problem.

PS: If someone ask I connected the pins in this way:

  • 5V -> 5V
  • GND -> GND
  • S0 -> 50
  • SCK -> 52
  • ST -> 51
  • CS -> 53

Ok, I solved it. I made a dummy mistake: I haven't connected ALL the GND's to Arduino. I didn't noticed there are two GND pins on the module. My module simply didn't got enough juice.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM