Go Down

Topic: ethernet locks up in Ethernet.begin (Read 1 time) previous topic - next topic


Hi Folks,

I have never used arduino before, but it seems everything is locked away so if a function like this fails I have no idea where to start debugging.

I am a hardware designer (and experienced firmware engineer) and have taken the Ethernet design from the schematics and incorporated it into my clients design.

I have 1 PCB functioning correctly but my second locks up in the Ethernet.begin function. I assumed the compiler used the library sources, but it seems that it doesn't.

My signals all look correct and I can get ping responses from the W5100. See below: (unreachable when not plugged in, packet received when it is)

Pinging with 32 bytes of data:
Reply from Destination host unreachable.
Reply from Destination host unreachable.
Reply from Destination host unreachable.
Reply from bytes=32 time=1003ms TTL=128

Ping statistics for
    Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
    Minimum = 1003ms, Maximum = 1003ms, Average = 1003ms

I have managed to get a bit further.


all return, but _dhcp->beginWithDHCP() locks up, however I am not sure if I had declared _dhcp correctly when copy pasting code.

Any ideas how I debug this please.



Posting your code might help. Do you have a SD card or any other SPI device connected to your device?


Dec 08, 2015, 05:07 pm Last Edit: Dec 08, 2015, 05:16 pm by rekinchin
The code is just the DHCPAddressPrinter example. I did try and breakdown some of the .begin function using this

Code: [Select]

#include <SPI.h>
#include <IPAddress.h>
#include <Dhcp.h>
#include "C:/Program Files (x86)/Arduino/libraries/Ethernet/src/utility/w5100.h"
 * Copyright (c) 2010 by Arduino LLC. All rights reserved.
 * This file is free software; you can redistribute it and/or modify
 * it under the terms of either the GNU General Public License version 2
 * or the GNU Lesser General Public License version 2.1, both as
 * published by the Free Software Foundation.

#include <stdio.h>
#include <string.h>

// W5100 controller instance
//W5100Class W5100;

#define TX_RX_MAX_BUF_SIZE 2048
#define TX_BUF 0x1100

#define TXBUF_BASE 0x4000
#define RXBUF_BASE 0x6000

byte mac[] = {
  0x00, 0xAA, 0xBB, 0xCC, 0xDE, 0x02

byte ip[] = {
  0, 0, 0, 0, 0, 0
DhcpClass *_dhcp;

void setup() {

  static DhcpClass s_dhcp;
  _dhcp = &s_dhcp;

  while (!Serial) {

  // start the Ethernet connection:



  int ret = _dhcp->beginWithDHCP(mac, 10, 40);

void loop() {


That hangs on int ret = _dhcp->beginWithDHCP(mac, 10, 40); after printing "5"

No additional hardware on the SPI port



Code: [Select]
DhcpClass *_dhcp;

void setup() {

  static DhcpClass s_dhcp;
  _dhcp = &s_dhcp;

I don't understand the purpose of this. Why define a pointer to a static instance?
The art of getting good answers lies in asking good questions.


Ask arduino!!! that's the Ethernet.cpp library Ethernet.begin function

Code: [Select]

int EthernetClass::begin(uint8_t *mac_address, unsigned long timeout, unsigned long responseTimeout)
  stat  ic DhcpClass s_dhcp;
  _dhcp = &s_dhcp;

  // Initialise the basic info


That I copied to see what is happening



I have a further PCB functioning now, so the problem is certainly hardware (2 boards OK 1 fails). Also a working PCB will go through my test code and display all 6 messages. SO, my question becomes what can cause it to hang in _dhcp->beginWithDHCP()  (even with timeout?)



I'm closing this post.. I have found that working copies of the libraries sit in a documents/arduino folder from that I have identified the problem. I shall post that as another posting.

Thanks for help


Go Up