Reset atmega328 by code

Hi all

I want to reset my arduino uno (or standalone atmega328) using code. using asm ("JMP 0"); seems not good because it is not a real reset. I saw this code and i wonder if it is the same or if does a real reset?

void(* resetFunc) (void) = 0;

void loop() {

//some code
resetFunc();

}

the only difference between jmp 0 (or jmp boot area) is registers are not zeroed. proper coding involves re-writing registers anyway so should not be a problem.

a better way is force watchdog timeout. then the main difference is just one bit in the status register.

So the real question is - why do you want to emulate a hardware reset?

geologic: I want to reset my arduino uno (or standalone atmega328) using code.

This was already recently cussed and discussed here: http://forum.arduino.cc/index.php?topic=381083.0

Paul__B: So the real question is - why do you want to emulate a hardware reset?

I'm using a arduino and a sim900 to send some data to the cloud. The sequence is wake -> send data -> sleep 1 hour. I should receive data every hour but i don't know why, my sim900 only works on the 1st time, after the 1st wake up, it never sends data again. If i reset everything it works ok, so after the 1st wake up i would like to reset arduino, so the sequence is start -> send data -> sleep 1 hour -> restart

dmjlambert: This was already recently cussed and discussed here: http://forum.arduino.cc/index.php?topic=381083.0

Since i'm using lowpower library to sleep arduino (https://github.com/rocketscream/Low-Power) i would like to avoid watchdog (have to change library code). The code i post in the 1st place works ok, my question is if that's a true RESET or just a soft reset?

Hook a pin to reset using resistor and digitalWrite(pin,LOW); may reset the micro.

-Malhar

You could try to isolate the sim900 reset from the reset of the Arduino and to connect it to a digital pin. That way you could reset the hanging sim900 only.

MalharD: Hook a pin to reset using resistor and digitalWrite(pin,LOW); may reset the micro.

-Malhar

I saw some posts saying that's not a good think to do. The reset sets all I/O pins to inputs, therefore can remove the reset signal too quickly for a complete reset.

Whandall: You could try to isolate the sim900 reset from the reset of the Arduino and to connect it to a digital pin. That way you could reset the hanging sim900 only.

I already did that, didn't work. Don't know why, but only powering arduino off/on can bring sim900 back in action, so i suppose it is something with the library. Doing a reset it works.

So it seems to me it is not the hardware that has the problem, but the library that manages it.

Back to your original question, did you try the jump to zero code? Does it bring the sim900 back to life?

You could try to make the sim900 object dynamic and delete and recreate it if needed. That should reinitialize the hardware like a restart without powercycle or reset.

Jumping to location 0 is not a true soft reset. It is merely jumping to location zero and re-running the all the initialization code. It will not actually reset any h/w.
You can do a true soft reset of the AVR by using the watch dog timer and letting it expire.
However, while that will reset the AVR, reset all the AVR internal h/w, and restart all the s/w on the AVR again,
it will not reset any external h/w.
Because of this, a software reset of the AVR is not the same as bashing the physical reset button which resets everything.

So what to reset and how to do it depends on what you are wanting to do and what really needs to be reset.

— bill

watchdog is not exactly the same as hardware reset.

using an output pin to reset IS exactly the same and works for all external devices too. adding a simple cap solves all timing issues mentioned in the atmel app note.

john1993: watchdog is not exactly the same as hardware rest.

In what way?

mcucsr has different bit settings depending on whether reset was por, wdt, bod, reset pin, etc.

otherwise bootloaders like opti would not work.

bperrybap: Because of this, a software reset of the AVR is not the same as bashing the physical reset button which resets everything.

Or more precisely, everything actually connected to the reset button. :grinning:

john1993: using an output pin to reset IS exactly the same and works for all external devices too. adding a simple cap solves all timing issues mentioned in the atmel app note.

Can you elaborate on this? A capacitor inline between an output pin and reset pin? What value capacitor is required?

I want to remotely reset a mega2560 which has an ethernet shield attached and so far have been looking at an external reset circuit such as this: http://www.openhardwarehub.com/projects/36-Arduino-Hardware-Reset-Circuit-Breadboard

warwound: Can you elaborate on this? A capacitor inline between an output pin and reset pin?

no. between both pins and ground. the point is cap holds low longer so the incomplete reset mentioned in app notes does not occur. i used .1mfd but dont think value matters much, probably anything from 100pf to 100mfd.

in fact the cap is probably not needed at all but willing to give atmel benefit of the doubt. both projects were mission critical so thought it better not to take a chance. the few times i did it for hobby use no cap was used and it still worked ok.

warwound: I want to remotely reset a mega2560

http://www.openhardwarehub.com/projects/36-Arduino-Hardware-Reset-Circuit-Breadboard

imo the 555 is overkill. a simple cap will do the same thing. you dont have to hold reset for milliseconds, only a few microseconds.

ive used remote reset to remotely program an esp8266 and avr combo but no cap required since esp and not avr was doing the reset. remote reset via rfm22b (si4432 prone to hang) did need a cap because the avr was resetting itself and the transceiver.

john1993:
no. between both pins and ground. the point is cap holds low longer so the incomplete reset mentioned in app notes does not occur. i used .1mfd but dont think value matters much, probably anything from 100pf to 100mfd.

Thanks for the info, i’ll try it out later this week.

its worth mentioning again that there is no point using a pin to reset unless another attached device must be reset too. jmp 0 or wdt more than adequate for 99.9% applications.