Pages: [1]   Go Down
Author Topic: Software reset  (Read 8652 times)
0 Members and 1 Guest are viewing this topic.
Paris, France
Offline Offline
Jr. Member
**
Karma: 0
Posts: 69
Arduino Yún board + GSM shield
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi there,

I thought I had read a post about that but I don't find it anymore... I'd like to reset my board in a program after a while.

Do you have any idea how I can do it?

Thanks,
Franck
Logged

0
Offline Offline
Sr. Member
****
Karma: 0
Posts: 309
Progress is made by lazy people-H Ford/R Heinlein
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

It is on this forum when I also asked the same question.
It was answered by the "Gatorman" from Rugged Circuits.

void software_Reset() // Restarts program from beginning but does not reset the peripherals and registers
{
asm volatile ("  jmp 0");  
}  

 smiley smiley smiley
Logged

"Never trust an Internet bully who insults and makes fun of your level of intelligence."

Paris, France
Offline Offline
Jr. Member
**
Karma: 0
Posts: 69
Arduino Yún board + GSM shield
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks...
I have another board connected to my Arduino (WiShield), which I'd like to reset also. So I guess it won't work...

Franck
Logged

0
Offline Offline
Faraday Member
**
Karma: 16
Posts: 2855
ruggedcircuits.com
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

You can also use the watchdog timer to self-reset your board as long as you have a bootloader installed that turns it off so it doesn't reset itself forever while waiting for a sketch upload. This has the benefit of also re-initializing all peripherals to default values, while "jmp 0" just starts you program over while leaving peripherals the way they are.

You can reset another Arduino by using a digital output pin and connecting it to the reset line. If you put a pull-down resistor on the line (~1k I'd say) then when the first board goes into reset, the second should do so automatically (since the digital output pin will become an input and the 1k resistor will pull the line low). Then, in your first board's program, make the digital output high to let the second Arduino come out of reset.
Logged

0
Offline Offline
Sr. Member
****
Karma: 0
Posts: 309
Progress is made by lazy people-H Ford/R Heinlein
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Now you want a hardware reset?
One option:
You could do a hardware reset by connecting a transistor 2N3904 NPN to the pullup reset pin on AVR.
The base of BJT via 1k series resistor goes to one of your spare output pins. The emitter goes to ground and the collector goes to pin 1 (reset/10K pullup junction).
 smiley
Logged

"Never trust an Internet bully who insults and makes fun of your level of intelligence."

Paris, France
Offline Offline
Jr. Member
**
Karma: 0
Posts: 69
Arduino Yún board + GSM shield
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks guys for your answers. I'd like to test the watchdog solution though. Not sure about my bootloader.

I found that:
CAUTION! On newer AVRs, once the watchdog is enabled, then it stays enabled, even after a reset! For these newer AVRs a function needs to be added to the .init3 section (i.e. during the startup code, before main()) to disable the watchdog early enough so it does not continually reset the AVR.

Here is some example code that creates a macro that can be called to perform a soft reset:

#include <avr/wdt.h>
#define soft_reset()
do                        
{                          
   wdt_enable(WDTO_15MS);  
   for(;smiley-wink                
   {                      
   }                      
} while(0)
...
// Function Pototype
void wdt_init(void) __attribute__((naked)) __attribute__((section(".init3")));
...
// Function Implementation
void wdt_init(void)
{
   MCUSR = 0;
   wdt_disable();

   return;
}

I guess that should work for my Arduino 328?

Franck
« Last Edit: July 02, 2009, 10:09:27 am by fweens » Logged

Raleigh, NC
Offline Offline
Jr. Member
**
Karma: 0
Posts: 75
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Useful post, thanks!
Logged

Sophia-Antipolis (06)
Offline Offline
God Member
*****
Karma: 4
Posts: 618
Rejoignez le club !
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Fweens, it seems that the bootloader (at least on my Diecimila) does not disable the watchdog, and it is too late to do it in your sketch with the init3 code.

So I consider that using the watchdog does not work easily.

Logged

Pages: [1]   Go Up
Jump to: