Custom Leonardo with W5500 Eth. controller. No activity

Hi,
I made a custom arduino with W550 ethernet controller and are troubleshooting why I'm not getting any conenction or activity at all.

The boards have arduino Leonardo bootloader, and I'm simply trying the DhcpAddressPrinter example using Ethernet2 library. The code stops somewhere inside Ethernet.begin(mac), but never prints "Failed to configure Ethernet using DHCP".

I have scoped the SPI lines and they are never active. No activity at all. It looks like the avr never reaches out to the W5500. Anyone has an idea of what could be wrong here? I attached the ethernet part of my schematic. I think I did a blooper on the activity/link-LEDs.

For reference, here is the slightly modified version of DhcpAddressPrinter example with some debugging statements.

/*
  DHCP-based IP printer

 This sketch uses the DHCP extensions to the Ethernet library
 to get an IP address via DHCP and print the address obtained.
 using an Arduino Wiznet Ethernet shield.

 Circuit:
 * Ethernet shield attached to pins 10, 11, 12, 13

 created 12 April 2011
 modified 9 Apr 2012
 by Tom Igoe

 */

#include <SPI.h>
#include <Ethernet2.h>

// Enter a MAC address for your controller below.
// Newer Ethernet shields have a MAC address printed on a sticker on the shield
byte mac[] = {
  0x00, 0xAA, 0xBB, 0xCC, 0xDE, 0x02
};

// Initialize the Ethernet client library
// with the IP address and port of the server
// that you want to connect to (port 80 is default for HTTP):
EthernetClient client;

void setup() {
  // Open serial communications and wait for port to open:
  Serial.begin(9600);
  Serial.println("Trying to open serial port");
  // this check is only needed on the Leonardo:
  while (!Serial) {
    ; // wait for serial port to connect. Needed for Leonardo only
    Serial.println("waiting...");
    delay(100); 
  }
  Serial.println("Did I get here, though?");
  
  // start the Ethernet connection:
  if (Ethernet.begin(mac) == 0) {
    Serial.println("Failed to configure Ethernet using DHCP");
    // no point in carrying on, so do nothing forevermore:
    for (;;)
      ;
  }

  Serial.println("What about here inside1?");
  
  // print your local IP address:
  Serial.print("My IP address: ");
  for (byte thisByte = 0; thisByte < 4; thisByte++) {
    // print the value of each byte of the IP address:
    Serial.print(Ethernet.localIP()[thisByte], DEC);
    Serial.print(".");
  }
  Serial.println();
}

void loop() {

  Serial.println("...and here?");
  delay(100); 

}

Uhm, the sketch description says "Ethernet shield attached to pins 10, 11, 12, 13", is it referring to MCU pins or Arduino IO pins? Because I have wired the same MISO/MOSI/SCK as on the ISP header.

Pretty sure they are indicating the SS and SPI pins. #s are from the Uno.

CrossRoads:
Pretty sure they are indicating the SS and SPI pins. #s are from the Uno.

Okay... That certainly explains the table for which pins are SPI on this page: SPI - Arduino Reference

But why is there a reference to UNO pins in a common library for all Arduinos? That's not good I would say

HSPalm:
But why is there a reference to UNO pins in a common library for all Arduinos? That's not good I would say

It may be in the docs, but the SPI pins are defined for each model Arduino in
./hardware/arduino/avr/variants//pins_arduino.h

SurferTim:
It may be in the docs, but the SPI pins are defined for each model Arduino in
./hardware/arduino/avr/variants//pins_arduino.h

That would be a much better explanation. Cause right now I have Leonardo chosen as board, opens Ethernet-example and it says SPI pins are D10-D13 when they are not. I just checked for fun the BarometricPressureSensor example and it's the same :frowning:

Anyways, just checked the header file you pointed to and it says

// Map SPI port to 'new' pins D14..D17
#define PIN_SPI_SS    (17)
#define PIN_SPI_MOSI  (16)
#define PIN_SPI_MISO  (14)
#define PIN_SPI_SCK   (15)

I suppose these are my SPI pins. They are not marked D14, D15, D16 and D17 anywhere on the leonardo from what I can see in pictures, they are just labeled MISO, MOSI, SCK, SS. They are not labeled by their numbers in the Leonardo schematic either. I know I have used the right pins by the way because I burn the bootloader using ISP on the SPI pins with success. And it's the same pins I use for the ethernet connection.

Is there a way I can debug the library somehow? Can I insert println-statements or something? I feel completely lost when the software just stop in there in the library somewhere....

Just tried loading the BarometricPressureSensor sketch and the SPI pins woke up and tried to communicate on the SPI lines as expected.

So where does the ethernet example crash? What can I have done wrong?

The SPI data pins are on the ICSP pins only on the Leonardo.
https://store.arduino.cc/usa/arduino-leonardo-with-headers

SurferTim:
The SPI data pins are on the ICSP pins only on the Leonardo.
https://store.arduino.cc/usa/arduino-leonardo-with-headers

Yup that's what I figured :slight_smile: Do you know how I can edit a library file to do some debugging? Like toggle outputs or print to serial port.

I did a little debugging with the w5100 and the SPI bus. What did you have in mind?

I'm a Linux (Ubuntu) person. I don't use Windows, so bear that in mind.

SurferTim:
I did a little debugging with the w5100 and the SPI bus. What did you have in mind?

I'm a Linux (Ubuntu) person. I don't use Windows, so bear that in mind.

Really I just want to put "signs of life" (serial print, led blink) inside the library code from the beginning of Ethernet.begin until I find out where it stops! I have edited the Ethernet2.cpp to include these lines:

pinMode(13, OUTPUT);
	digitalWrite(13, LOW);
	delay(1000);
   	digitalWrite(13, HIGH);

..but the LED never lights. I'm not sure if I'm allowed to use Arduino-code inside the libraries. I am also not sure where inside the Ethernet2.cpp code we jump when:

Ethernet.begin(mac);

...in the Arduino code

I appreciate your help! I'm running Debian here on an old computer....

It should work inside the library code. I am familiar with Debian (Raspbian) also.

Insure you are editing the correct library code. Do you have an Arduino folder in your home folder?

SurferTim:
It should work inside the library code. I am familiar with Debian (Raspbian) also.

Insure you are editing the correct library code. Do you have an Arduino folder in your home folder?

I have an Arduino folder in both my home folder and in root user home folder. I have edited both, without success. But that may be because I have not found the entry point in the library file. Do you have an idea where we "jump in" in the Ethernet2 library when I call Ethernet.begin(mac); ? C++ in confusing me, I'm no programming genius but straight C I would have handled I think :slight_smile:

I'm onto something! Got some serial prints from inside the library, on my way to track down the culprit 8)

Edit: Deleting this post because my discoveries not true :slight_smile:

Now, finally some real discoveries. I am stuck and the loop indicated by the serial print in the below code. This is in the socket.cpp source file. It looks like it has sent something to the W5500 and is waiting for an OK. But as I've said, nothing happens on SPI lines so I'm not surprised this happens. I will dig deeper tomorrow, but I appreciate any insight.

int sendUDP(SOCKET s)
{

  w5500.execCmdSn(s, Sock_SEND);
		
  /* +2008.01 bj */
  while ( (w5500.readSnIR(s) & SnIR::SEND_OK) != SnIR::SEND_OK ) 
  {
	Serial.println("This is where I'm stuck");
    if (w5500.readSnIR(s) & SnIR::TIMEOUT)
    {
      /* +2008.01 [bj]: clear interrupt */
      w5500.writeSnIR(s, (SnIR::SEND_OK|SnIR::TIMEOUT));
      return 0;
    }
  }



  /* +2008.01 bj */	
  w5500.writeSnIR(s, SnIR::SEND_OK);

  /* Sent ok */
  return 1;
}

What W5500 ethernet controller hardware are you using?

I'm not sure what you're asking. If you're referring to a module I can inform you I don't use a module or shield, I made a PCB. The Ethernet part of the PCB schematic is posted in my first post.

That is going to be difficult to troubleshoot without an o-scope. Got one?

Yes... I have scoped the SPI lines and there is absolutely no activity. I have also scoped with BarometricPressureSensor example, then there is SPI activity.