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
The code is just the DHCPAddressPrinter example. I did try and breakdown some of the .begin function using this
#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"
Ask arduino!!! that's the Ethernet.cpp library Ethernet.begin function
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
.....
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.