Pages: [1] 2   Go Down
Author Topic: Reseting in Software  (Read 2450 times)
0 Members and 1 Guest are viewing this topic.
Sweden
Offline Offline
Full Member
***
Karma: 11
Posts: 237
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello,

is there a way to reset the Arduino (well, it is an ATmega644, programmed with the bootloader from here)?

I have read a bit and found out you can only use the WDT timer, but it seams the Arduino bootloader was in the way for this. Is it the same for the ATmega644 bootloader?

Jan
Logged

Seattle, WA USA
Online Online
Brattain Member
*****
Karma: 653
Posts: 50901
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

It would be much better if you fixed the problem that requires you to reset the Arduino.
Logged

Sweden
Offline Offline
Full Member
***
Karma: 11
Posts: 237
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

It's not a problem, it's a feature. Then I send a specific command via Serial, the board should "start from the beginning", with other words, reseting.

Jan
Logged

Seattle, WA USA
Online Online
Brattain Member
*****
Karma: 653
Posts: 50901
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Then I send a specific command via Serial, the board should "start from the beginning", with other words, reseting.
What is it that you think "start from the beginning" should do? Resetting the Arduino is almost certainly not what needs to be done. If it really is, just close and reopen the serial port. The Arduino will reset when you do that.
Logged

Sweden
Offline Offline
Full Member
***
Karma: 11
Posts: 237
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
What is it that you think "start from the beginning" should do?
Reinit all variables, simply start everything from the beginning, as if the power just would have been connected.
Quote
If it really is, just close and reopen the serial port.
Ahh.. If it only would be so simple...

Ok, the problem is, I have to disable to serial reset, because it may happen the ATmega "changes master" (program controlling it). But, I still need to reset it at some points, so for that I need to have a reset command that executes a software reset.

Jan

EDIT: Small change: In my first post I sad the wrong link for the bootloader. I use the bootloader from here, it's the core files I'm using from avr-developers.
« Last Edit: December 01, 2011, 07:36:43 am by JanD » Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 310
Posts: 26631
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You could do the same "call 0" that the bootloader does; as has been pointed out many times here before (I'm a little surprised your search didn't find them), it isn't exactly a reset, but it is as close as you can get with a software-only solution, unless you invoke the watchdog.
Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Sweden
Offline Offline
Full Member
***
Karma: 11
Posts: 237
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Do you mean "asm volatile ("jmp 0x0000");" when you say "call 0"?

If yes; that isn't enough, the variables wouldn't be reinited then.
If no; haven't found anything like that, what exactly does it do?

I don't have any problems with using the WDT timer, but:
Quote
I have read a bit and found out you can only use the WDT timer, but it seams the Arduino bootloader was in the way for this. Is it the same for the ATmega644 bootloader?

Jan
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 310
Posts: 26631
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
the variables wouldn't be reinited then
Why not?

Quote
Do you mean "asm volatile ("jmp 0x0000");" when you say "call 0"?
No, when I say "call", I mean "call".
Code:
void (*app_start)(void) = 0x0000;
//...
//...
app_start();
(Source: ATmegaBOOT_168.c)
« Last Edit: December 01, 2011, 07:58:11 am by AWOL » Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Sweden
Offline Offline
Full Member
***
Karma: 11
Posts: 237
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Because:
http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1242847196 Third post
http://answerpot.com/showthread.php?2498719-Fwd%3A++arduino+software+reset Second post

There are other, similar posts on the net too.

Jan
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 310
Posts: 26631
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I presume you're referring to this:
Quote
All of the chip's registers, settings and RAM will not be properly initialized.
As far as your sketch is concerned, it will appear as though it has just been booted for the first time, because it will have followed the same path through the pre-"main" initialisation of your sketch.
Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Sweden
Offline Offline
Full Member
***
Karma: 11
Posts: 237
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Ok, I didn't knew that. How is it with the registers?
Logged

Sweden
Offline Offline
Full Member
***
Karma: 11
Posts: 237
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Quote
All of the chip's registers, settings and RAM will not be properly initialized.

Ups... Didn't see that.

Ok, thanks!

Jan
Logged

Dallas, TX USA
Offline Offline
Faraday Member
**
Karma: 70
Posts: 2763
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Jumping to 0x0000, IMHO is a total kludge.
Why are people afraid of correcting the bootloader when there is a problem?
It is open source.....
Just fix the bootloader and be done with it so you can do a real software driven reset
if that is what you want.
Unlike jumping to 0x000, it allows everything to start up clean and fresh.

Jan, the 644 seems to be using an older version of the atmegaBOOT bootloader but the fix
should be the same:
In the bootloader:

Replace this:
Code:
#ifdef ADABOOT          // BBR/LF 10/8/2007 & 9/13/2008
    ch = MCUSR;
    MCUSR = 0;

    WDTCSR |= _BV(WDCE) | _BV(WDE);
    WDTCSR = 0;

    // Check if the WDT was used to reset, in which case we dont bootload and skip straight to the code. woot.
    if (! (ch &  _BV(EXTRF))) // if its a not an external reset...
      app_start();  // skip bootloader
#endif



with this:
Code:
#ifdef ADABOOT
ch = MCUSR;
MCUSR = 0;
wdt_disable();

// Check if the WDT was used to reset, in which case we dont bootload and skip straight to the code. woot.
if (! (ch &  _BV(EXTRF))) // if its a not an external reset...
app_start();  // skip bootloader
#else
asm volatile("nop\n\t");
MCUSR = 0;
wdt_disable();
#endif

Build a new bootloader and then burn it in your chip and enjoy.

Now if you have recent gcc tools, you may also find that your bootloader may no
longer compile.

If you have errors releated to EECR or EEPE,
you will need to also make this change:
Add this up at the top:
Code:
#include <avr/eeprom.h>
then change this:
Code:
                                       while(EECR & (1<<EEPE));
to
Code:
                                       while(!eeprom_is_ready());

Then it should compile again.
Once you get it in your AVR, you can use something like this to reset the AVR:
Sample sketch to demonstrate software control of reset:


Code:
#include <avr/wdt.h>

void setup()
{
Serial.begin(9600);
Serial.println("setup()");
}

void loop()
{
Serial.println("Top of loop()");
for(int x = 3; x ; x--)
{
Serial.println(x);
delay(1000);
}
Serial.println("Reseting Arduino");
#if ARDUINO >= 100
        delay(50); // wait for transmission to finish
#endif
resetArduino();
}

void resetArduino()
{
wdt_enable(WDTO_15MS);
noInterrupts();
while(1); // wait to die and be reborn....
}



If your watchdog reset is working, you will see the messages repeating.
If you have a broken WDT bootloader, you will see it the first time and
then the chip will hang in the bootloader until you manually reset it.
--- bill


« Last Edit: December 01, 2011, 10:58:33 pm by bperrybap » Logged

Sweden
Offline Offline
Full Member
***
Karma: 11
Posts: 237
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks, I will test that when I get home.

Jan
Logged

Sweden
Offline Offline
Full Member
***
Karma: 11
Posts: 237
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hm.. it compiled without problems, but:
Code:
.....\hardware\atmega324_644\bootloaders\atmega644p>avrdude -cdragon_isp -patmega644 -P usb -U flash:w:ATmeg
aBOOT_644_NEW.hex

avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.18s

avrdude: Device signature = 0x1e9609
avrdude: NOTE: FLASH memory has been specified, an erase cycle will be performed

         To disable this feature, specify the -D option.
avrdude: conflicting -e and -n options specified, NOT erasing chip
avrdude: reading input file "ATmegaBOOT_644_NEW.hex"
avrdude: input file ATmegaBOOT_644_NEW.hex auto detected as Intel Hex
avrdude: ERROR: address 0x10010 out of range at line 130 of ATmegaBOOT_644_NEW.h
ex
avrdude: write to file 'ATmegaBOOT_644_NEW.hex' failed

avrdude: safemode: Fuses OK

avrdude done.  Thank you.

Why this???

Jan
Logged

Pages: [1] 2   Go Up
Jump to: