Arduino Mega 2560 and W5100 (non-shield)

Hi

I'll try to explain my problem properly, but I've been struggling so hard with it over the last week and I know I haven't actually fully understood the problem, let alone managed to work out how to start solving it. With a view to the above, please be kind and help me to explain it better if I didn't manage!

I'm using the W5100 "red" breakout board purchased on eBay with a Mega 2560. (See attached image.) Previously I used this board with my MQTT project using the standard ethernet library and the knolleary Arduino Client for MQTT on a Nano V3. The red ethernet board and Nano V3 still work a treat. It seems safe to say there are no electrical issues with the red ethernet board for this reason.

When I ported over to the Mega 2560, it worked when I used the correct pins: Mega 50-52 for SPI and Mega 10 for chip select. (i.e. NSS (CS) > Mega 10, MI > 50, MO > 51, SOK > 52.)

I started having problems uploading the sketch. After some googling I removed the reset line from ethernet board to Arduino during upload, replaced it after upload finished, then hit the physical reset button on the Arduino. Using this procedure my sketch worked beautifully for a week. No overheating, no random crashing, and apparently full reliability.

In short, randomly after some change I made it stopped - and I've thrown literally HOURS of testing at the problem but haven't gotten to the bottom of it. The problem seems to be related to the reset process, but it's intermittent and therefore hard to pin down. I've gone to the following lengths: replaced ethernet cable, pulled apart my prototype and started from scratch, stripped the sketch back to its minimum code just for Ethernet and MQTT, tested with Arduino sketch for web server (can't get even this to work), and experimented with delays in the setup routine and even manually resetting the ethernet board by wiring it up to a tie-high resistor and switch and setting up the sketch to wait for me to reset then initialise ethernet library.

I literally can't get the thing to ping from a remote machine, let alone get MQTT working. However sometimes randomly it does ping. I have tried to figure out exactly what caused it to work when it did, but it's seemingly random.

When I plug the red board back into my old prototype stripboard on the Nano, it works like a dream.

I've read this forum a tonne and reviewed every old post relating to W5100 and issues with reset routine on the Mega, and tested lots of theories.

So I'm coming hat in hand to ask if someone can help me through by explaining exactly why the Mega was known to have reset issues with the first revisions of the ethernet shield, so I can at least have an understanding of how the resets work.

The ethernet board also works fine with my Uno - web server sketch runs fine. Plug it into the Mega and... same intermittent problems.

I haven't listed most of the things I've tried, or included the code of my sketch, so it's a very vague request at this stage, but if there is anything else someone can write here to shed some light on exactly what happens when a Mega is plugged into a W5100 as compared with an Uno, I would really be grateful.

Thanks

Mat

red.jpg

Just to make your problem clear, your problem is the USB IC doesn't reset the Mega processor to start the bootloader, correct?

The reset by the USB port is connected to the Mega reset line through a capacitor. In the schematic, the cap is c7 (far right center).

If the cap on the ethernet board reset circuit is larger than c7, then reset line from the USB IC may not be able to pull the reset line low.

Mat, it really seems you have tried hard to figure out the problem and explained it well.

Some thoughts to check with you:
Do you have in your setup() code something like the following;

pinMode(10, OUTPUT);        // set ethernet CS as output:
pinMode(53, OUTPUT);        // set ATMega-2560, pin 53 hardware cs pin output, even if un-used:

Also, have you tried with a small delay, say like delay(250) in the setup() to allow time for the ethernet CPU to reset before using it?


Paul

@rockwallaby Thanks. I hadn't explicitly set pins 10 and 53 as outputs. This wasn't required when I was working with the Nano. Either way, I've done that now but the ethernet board still apparently won't reset properly. I also set the outputs low to enable W5100. Also yes, I have been experimenting throughout with delays at the beginning of setup() to ensure the ethernet resets before attempting to use it. I've tried delays starting at 50 up to 2000.

@SurferTim I probably wasn't clear enough! The Arduino resets fine after an upload or when hitting the reset button. The issue is that the ethernet board is not responding. I'm guessing this means it's not resetting properly, or there could be another fault. Either way

a) the fault is not manifesting itself when plugged into a Nano V3 or the Uno R3
b) likewise if I use a different model ethernet shield (I have another one, Sainsmart) stacked onto the same Mega, using the same sketch, it works fine
c) furthermore it did work with my Mega for a couple of weeks throughout which I made a lot of changes in the sketch. Needless to say I've rolled back changes (using file versioning) and pulled-apart and re-built the prototype on breadboard. In summary I don't believe it's about the USB IC not resetting the Mega or the ethernet board. (If I understand your understanding of my understanding correctly... :wink: )

I feel like the solution must be staring me in the face but for a week of head scratching I just can't get close to understanding the problem!

The reason I want to use these red boards is that they are smaller (lower height) than using a shield and space is an issue for my project.

@SurferTim, to be honest I don't quite understand the Mega2560 schematic. I see cap C7 on the right, but what is the "RESET-EN" pad? On my Mega board it looks like just a pad with no component on it. Is that how it should be? Maybe it's unrelated?

I just really want to understand the process of what happens when you reset an Arduino, and what is expected from attached shields in terms of reset electronics.

I've attached a pic of what I see on the Mega board.

reset-en.jpg

The two "reset en" pads should be connected by a very small trace. If you break that small trace, the Mega will not reset when a device connects to the usb port. That should not be your problem.

So it is the ethernet shield that is not resetting then? The Arduino resets and uploads code ok? Can you post a link to the board you are using? Something that shows a pinout. It appears there is a pinout silkscreen on the bottom of the board, but I can't read all the pins in the pic above.

This is the test code I use to insure the SPI bus and the SPI side of the w5100 is working. If the serial monitor shows 192.168.2.2, then all is ok there. If it shows anything else, the SPI side of the w5100 is not working.

#include <SPI.h>
#include <Ethernet.h>

byte mac[] = {  0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(192,168,2,2);

void setup() {
  Serial.begin(9600);

  // disable SD SPI
  pinMode(4,OUTPUT);
  digitalWrite(4,HIGH);

  // Start ethernet
  Serial.print(F("Starting ethernet..."));
  Ethernet.begin(mac, ip);
  Serial.println(Ethernet.localIP());
}

void loop() {
}

@SurferTim I ran your test code which didn't work first time with my Mega and the red ethernet board, but then did the second time.

Anyone would think the problem might be dodgy hookup wire connections but I've tried with a number of different wires and the problem persists. It does seem intermittent. I can solve it sometimes more effectively by pulling the power to the arduino and Ethernet board simultaneously, re-powering up over USB then subsequently hitting the reset button on the arduino. But often this doesn't fix it as well.

Yes I believe the issue is that ethernet chip is not being properly reset.

Here's a link to (what I think is the correct) schematic: http://www.robotshop.com/media/files/pdf/schematic-shd031.pdf

hazymat, could you can try SurferTim's code, but put that small delay, say like, delay(250) in the setup(), anywhere before your 'start ethernet' section, to give a bit of time for the W5100 to finish its reset and become ready for communications with the Arduino over SPI.

Also, then try with those pin settings I mentioned as well, as you are on a Mega 2560 board, it is advised to set pin 53.


Paul

Hi @rockwallaby, @surfertim

I think I've now (roughly) figured out what is causing this problem, could you chime-in to suggest a solution?

When the hook-up wire connecting reset (from Mega to W5100) is a bit longer, it doesn't reset. For instance if I connect the W5100 reset line to a wire, which is connected to another wire through breadboard then into Mega reset line, it doesn't reset the W5100 chip.

Not exactly sure why that's happening, I note @surfertim mentioned in another thread that this might be due to a capacitor on the reset line on the W5100.

It could be a combination of the resistance and capacitance of the long wire and the breadboard. That forms a rc circuit which increases the amount of time required to change the line level.

Google rc circuit.

I'm not sure that adding such a small length of wire would increase the RC enough to get that sort of problem, not unless you added many many metres. But it is a good thought.

It might be that there is no pull up or pull down on the line and the line is not being driven hard in both directions, for example, only being driven high, but not pulled back to 0 volts that is then seeing a floating line that is susceptible to EMI.

In any case, it's an odd situation for sure.

I like how you try to diagnose and also explain it well.


Paul

rockwallaby:
It might be that there is no pull up or pull down on the line and the line is not being driven hard in both directions, for example, only being driven high, but not pulled back to 0 volts that is then seeing a floating line that is susceptible to EMI.

Thanks Paul,

Do you reckon it's worth piping the output to an op amp to ensure it's less susceptible to interference / floating?

Is there another way I can do it with tie resistors?

Here is the schematic of the Mega 2560.

Note the ICSP pinout top center of the schematic, and the reset circuit to the left of the ICSP connector. There is a 10K pullup there with a reverse polarity diode and a 22pf capacitor.

The reset circuit from the USB port is far right center. There is a 100nf capacitor that ac couples the DTR line to the reset circuit top center of the schematic. The reset pulse through the capacitor must be of sufficient strength to counter both the 10K resistor and the 22pf cap.

If you modify that circuit, you must take into account the capacitance and resistance of that entire circuit to insure the reset pulse is adequate to reset the w5100. An op-amp or a LM555 timer in monostable mode to increase the length of the reset pulse might do the trick.

edit: I couldn't find a schematic for that ethernet module. Is there a resistor or capacitor on the reset circuit on the module?

SurferTim:
edit: I couldn't find a schematic for that ethernet module. Is there a resistor or capacitor on the reset circuit on the module?

Hi SurferTim

Here's a link to that ethernet module schematic: http://www.robotshop.com/media/files/pdf/schematic-shd031.pdf

That module has a 10K pullup resistor on the reset line also. That may be too much for the reset line on the Mega to pull low. Maybe your inline op-amp on the reset line is the best plan.

Do you think there might be an issue with the fact that the Arduino Mega has its reset line pulled up to +5volts, while your Ethernet board has its reset pulled up to +3v3?

Also, there is no time constant on the reset line for the W5100, just a pullup, which suggests to me that you need to externally pull it down to ensure it has been reset correctly.

I haven't checked the UNO or Nano circuits to see if it is the same as the Mega, with regard to the reset pull-up volts.

Do I recall you saying that is it did work for some period of time before you started having troubles?
If so, I am wondering if something has happened to the input stage on the reset line on the Ethernet board with driving it to +5 volts via 10kΩ pullup?

It is certainly a strange problem, and I'm really just guessing here.

EDIT: in fact you have an Arduino that has 5 volts I/O and you are connecting this the Ethernet board which is only 3v3. Might this be something to be concerned about?


Paul

The ethernet shield w5100 reset line is also 5 volts, but driven by a CAT811TTBI. That IC acts like a non-inverting buffer and a pulse extender. The reset line from the Arduino (Mega) connects to the MR (Manual Reset) pin on that IC.

Manual Reset Input. A logic LOW on MR asserts RESET. RESET remains
active as long as MR is LOW and for 140ms after MR returns HIGH. The
active low input has an internal 20kΩ pull-up resistor. The input should be
left open if not used.

Thanks again @Rockwallaby and @SurferTim

A bit of progress:

1/ I've pumped the Mega 2560 reset line through a 3.3v hex level convertor. This solves the upload problem (where it would hang during uploading a sketch) - but not the W5100 reset problem.

2/ Then I removed the thing powering my project - an ultra mini 5V buck converter - and replaced it with USB power - and that solves the W5100 reset issue as well.

I'm not sure if the latter is causing EMI on the reset line, or whether it's something to do with the fact the Mega's regulator is kicking in... more tests to follow.

Either way it's a combination of those two things. Thanks for the pointers.

Next I'm going to try whacking a capacitor on the output (or the input) of my buck converter. I'm sure the mini buck converter has capacitors inside, maybe they aren't sufficient?

Okay so putting a 1000uF capacitor on the rails does nothing to reduce the electrical noise or solve the problem. (I can still hear the high pitched noise and W5100 doesn't reset)

Connecting W5100 reset through the level converter doesn't solve the problem of it not resetting.

I'm stuck with the problem: if I connect W5100 reset to Mega, it does reset... for now... but if I lengthen that wire or connect it via a breadboard it simply doesn't work... argh!

This is so weird. What else can I try?

Hi everyone!
Sorry to resurrect an old thread, but I have been experiencing a similar problem and actually found a solution. Maybe someone can benefit on my solution.

Using the same Ethernet module as Hazymat described and an Arduino pro mini clone, I first got the module to work without any problems and started developing my own code based on the webserver example. I soon discovered that the Ethernet module wouldn’t always boot as it should. It did however sometimes work after a seemingly random number of reboots. Even after reverting back to the original example code the problem persisted.

At first I figured it was caused by an improper reset of the Ethernet module or startup timing issue, and wasted many hours trying different startup delays and externally resetting the Ethernet module. I then tried changing to a more powerful power supply, adding a smoothing capacitor and even changing the dupont cables used between the arduino and the module, but still no progress.

Finally I noticed by mistake that the module worked better if a ground wire was close to the dupont cable. So I added a foil shield around the dupont cable and connected it to ground. To my big surprise the module worked perfectly after every reboot! I guess the signals get distorted when using too long wires, but I have no idea of what the maximum recommended cable length for SPI line is.

In my setup I’m using a 20 cm dupont cable between the arduino and the Ethernet module. Also the reset pin on my Ethernet module is not connected to anything, and I’m currently using a delay of 750 ms in the setup to make sure the Ethernet module boots up in time.

Hazymat, if you still have the problem, I hope a foil screen or a shorter wire will help you as well!

Hi There

I'm having similar problems with a batch of 3 boards I received. I've found the boards marked 14/10 or 09/44 on the Ethernet connectors work fine. The ones marked 15/10 just wont work.

Back to buying new boards :slight_smile: