Mega 2560 Reset with output pin

I have tied the reset line of my Mega 2560 to a GPIO pin (A15) so that I can programatically reset the unit. This allows me to reset the device over the network, and it works a treat.

However when the reset line is tied to A15, this prevents me from being able to upload code. When I hit upload in the IDE, the TX light on the Mega doesn't flash as usual, and IDE returns the following error:

avrdude: stk500v2_getsync(): timeout communicating with programmer

When I remove the wire between reset and A15, the upload succeeds.

I hit a similar problem when I tried to tie the reset line of my W5100 breakout board to the Mega's reset line. Never really resolved it, other than using another GPIO pin to reset the W5100, which works ok.

Can anyone suggest a reason / solution for this?

This allows me to reset the device over the network, and it works a treat.

No it doesn't. The data sheet says it will not reset the processor correctly.

Can anyone suggest a reason

Yes, uploading uses the auto reset circuit and you have just clobbered it.

Thanks @Grumpy_Mike

Is the best advice to use this to "correctly" reset the processor:

void(* resetFunc) (void) = 0;



Use the watchdog to reset the board. Bear in mind the first shipping Mega 2560 boards had a bootloader bug that made using the watchdog impossible.

There is no software method of doing a hardware reset. The problem with what you are doing by connecting an output pin to the reset line is that as soon as the chip starts to reset the output pin is defaulted to being an input and thus removes the reset signal before the rest of the processor has been reset. So you have to make the reset pulse independent of the output pin. The best way of doing this is with a monostable but I have seen people use a large capacitor on the output pin.

As I said before this screws up the auto reset for uploading code so it is best to put a switch to disconnect the reset line from your circuitry when you want to upload code.

As an aside (since this is the wrong way to reset the chip), I'll wager the problem was that the pin was set as output/high, during normal operation, so this was preventing it from being pulsed low - were it set input, I think that would have "worked".