Arduino Forum

Using Arduino => Networking, Protocols, and Devices => Topic started by: rekinchin on Dec 08, 2015, 02:45 pm

Title: ethernet locks up in Ethernet.begin
Post by: rekinchin on Dec 08, 2015, 02:45 pm
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 192.168.0.14 with 32 bytes of data:
Reply from 192.168.0.6: Destination host unreachable.
Reply from 192.168.0.6: Destination host unreachable.
Reply from 192.168.0.6: Destination host unreachable.
Reply from 192.168.0.14: bytes=32 time=1003ms TTL=128

Ping statistics for 192.168.0.14:
    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.

functions:
  W5100.init()
  SPI.beginTransaction(SPI_ETHERNET_SETTINGS)
  W5100.setMACAddress(mac)
  W5100.setIPAddress(ip)
  SPI.endTransaction()

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.

Robert
Title: Re: ethernet locks up in Ethernet.begin
Post by: SurferTim on Dec 08, 2015, 02:49 pm
Posting your code might help. Do you have a SD card or any other SPI device connected to your device?
Title: Re: ethernet locks up in Ethernet.begin
Post by: rekinchin on Dec 08, 2015, 05:07 pm
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 RX_BUF (TX_BUF + TX_RX_MAX_BUF_SIZE)

#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;

  
  Serial.begin(9600);
 
  while (!Serial) {
  }

  // start the Ethernet connection:
  Serial.println("1");
    W5100.init();
  Serial.println("2");
  SPI.beginTransaction(SPI_ETHERNET_SETTINGS);
  Serial.println("3");

  W5100.setMACAddress(mac);
  Serial.println("4");

  W5100.setIPAddress(ip);
  SPI.endTransaction();
  Serial.println("5");

  int ret = _dhcp->beginWithDHCP(mac, 10, 40);
  Serial.println("6");
}

void loop() {

}


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

No additional hardware on the SPI port

Robert
Title: Re: ethernet locks up in Ethernet.begin
Post by: PaulS on Dec 08, 2015, 05:31 pm
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?
Title: Re: ethernet locks up in Ethernet.begin
Post by: rekinchin on Dec 08, 2015, 05:51 pm
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
Title: Re: ethernet locks up in Ethernet.begin
Post by: rekinchin on Dec 08, 2015, 06:51 pm
Update:

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?)

Robert
Title: Re: ethernet locks up in Ethernet.begin
Post by: rekinchin on Dec 09, 2015, 12:53 pm
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

Robert