Pages: [1]   Go Down
Author Topic: Reset to bootloader through sketch  (Read 5964 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 8
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello,
I currently am working on a small project and I need to reset the whole arduino into bootloader programming mode. I have a pro mini, atmega328

The way I currently tried is: asm volatile ("  jmp 30720");
This does send it into the bootloader, but it won't respond to any serial commands. Normally when it boots, I can send a '1 ' command to get 'AVR ISP'

The other way I can think of is using a watchdog timer. I would prefer not to use a watchdog.

I am doing this without a standard FDTI cable, so upon connecting there are a few extra characters sent to the arduino before the connection is established.

I've changed the bootloader to have a longer wait time(yes, I did it in the makefile) and to have a higher max error.

Any other suggestions?

Thanks,
Nai
Logged

Global Moderator
Dallas
Online Online
Shannon Member
*****
Karma: 200
Posts: 12774
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
The other way I can think of is using a watchdog timer. I would prefer not to use a watchdog.
Why not?
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 8
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

From what I've read, it seems it can cause problems.
Logged

Global Moderator
Dallas
Online Online
Shannon Member
*****
Karma: 200
Posts: 12774
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset


The original bootloader has problems with the watchdog.  The Pro Mini uses the original bootloader...
pro5v328.bootloader.file=ATmegaBOOT_168_atmega328.hex

How do you feel about replacing the bootloader?
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 8
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I've already been editing the bootloader some. Longer wait time and a higher error count.
Logged

Global Moderator
Dallas
Online Online
Shannon Member
*****
Karma: 200
Posts: 12774
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset


Oh right.  I need to pay more attention (not the first time my attention span has been an issue).

In that case, just disable the watchdog at the very start of the bootloader and use the watchdog to reset.  Problem solved.
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 8
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The
Code:
#ifdef WATCHDOG_MODS
      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
#else
      asm volatile("nop\n\t");
#endif
Section?
Logged

Global Moderator
Dallas
Online Online
Shannon Member
*****
Karma: 200
Posts: 12774
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset


Almost.  You will need to comment-out (or remove) this part...

Code:
     // 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

That bit of code skips the bootloader and jumps straight to the application in the event of a watchdog reset.  In your case, you want the bootloader to run.
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 8
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

So there's no way to reset without using a watchdog or physically?
Logged

Global Moderator
Dallas
Online Online
Shannon Member
*****
Karma: 200
Posts: 12774
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset


Exactly.  The jump you tried only "restarts" the software.  It does not reset the processor.  Interrupts will be enabled and able to fire.  Any pins set to outputs will remain outputs.  Any PWM running will continue to run.  The hardware is left exactly as it was when the jump was executed.
Logged

Pages: [1]   Go Up
Jump to: