Pages: [1]   Go Down
Author Topic: Software reset?  (Read 880 times)
0 Members and 1 Guest are viewing this topic.
Indiana
Offline Offline
Full Member
***
Karma: 1
Posts: 234
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Is there a way to invoke a reset via program instructions (purely via software)?

And no, I don't want to connect one of the digital pins to the reset pin and bring it low.  This is a hardware solution and from what I can remember it's advised against in the ATmega168 datasheet.
Logged

London
Offline Offline
Tesla Member
***
Karma: 10
Posts: 6255
Have fun!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

This post has a link to example code to do a software reset using the watchdog timer: http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1222941939/4#4
Logged

Indiana
Offline Offline
Full Member
***
Karma: 1
Posts: 234
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Perfect!  That's exactly what I needed.

Thanks for the help.

Logged

Sweden, Malmö
Offline Offline
Full Member
***
Karma: 2
Posts: 200
Rooky
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Mem,

Did try the reset code but it actually just ended my code maked it frezze. Any pointers to what i could have done wrong?

Etracer,

Did you get it working?
Logged

Indiana
Offline Offline
Full Member
***
Karma: 1
Posts: 234
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Here's a simple little sketch that looks for digital pin 2 to go high and then executes the reset.  Make sure you have a pull-down resistor on pin 2 so you don't leave it floating.

Code:
#include <avr/io.h>
#include <avr/wdt.h>

#define Reset_AVR() wdt_enable(WDTO_30MS); while(1) {}

void setup()
{
  Serial.begin(9600);
  Serial.println("Sketch startup.");
  pinMode(2, INPUT);
}

void loop()
{
  if (digitalRead(2) == HIGH) {
    Reset_AVR();
  }
}
Logged

London
Offline Offline
Tesla Member
***
Karma: 10
Posts: 6255
Have fun!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

No, I must admit that haven't tried it. If its hanging I wonder if the bootloader needs to be modified to turn the watchdog off. See if you can set the interval long enough to get past the bootloader so you can turn the watchdog off in setup. I would have a go myself but am busy getting the GLCD library working with the ATmega644 chip  smiley-wink
Logged

Sweden, Malmö
Offline Offline
Full Member
***
Karma: 2
Posts: 200
Rooky
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks etracer,

That is the same code i used but it did not work for me but then i am using a ATMega644 and sanguino bootloader that may be the problem.

No high priority on this for me right now mem ...
Logged

Indiana
Offline Offline
Full Member
***
Karma: 1
Posts: 234
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The above code works fine for me with an ATmega168 - but then I'm using LadyAda's "no-wait" bootloader.  So maybe that's the difference.
Logged

Pages: [1]   Go Up
Jump to: