Arduino Forum

Forum 2005-2010 (read only) => Software => Development => Topic started by: Nai on Jan 23, 2011, 08:34 pm

Title: Reset to bootloader through sketch
Post by: Nai on Jan 23, 2011, 08:34 pm
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
Title: Re: Reset to bootloader through sketch
Post by: Coding Badly on Jan 23, 2011, 08:38 pm
Quote
The other way I can think of is using a watchdog timer. I would prefer not to use a watchdog.

Why not?
Title: Re: Reset to bootloader through sketch
Post by: Nai on Jan 23, 2011, 08:40 pm
From what I've read, it seems it can cause problems.
Title: Re: Reset to bootloader through sketch
Post by: Coding Badly on Jan 23, 2011, 08:48 pm

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?
Title: Re: Reset to bootloader through sketch
Post by: Nai on Jan 23, 2011, 08:50 pm
I've already been editing the bootloader some. Longer wait time and a higher error count.
Title: Re: Reset to bootloader through sketch
Post by: Coding Badly on Jan 23, 2011, 08:55 pm

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.
Title: Re: Reset to bootloader through sketch
Post by: Nai on Jan 23, 2011, 08:58 pm
The
Code: [Select]
#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?
Title: Re: Reset to bootloader through sketch
Post by: Coding Badly on Jan 23, 2011, 09:02 pm

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

Code: [Select]
     // 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.
Title: Re: Reset to bootloader through sketch
Post by: Nai on Jan 23, 2011, 09:09 pm
So there's no way to reset without using a watchdog or physically?
Title: Re: Reset to bootloader through sketch
Post by: Coding Badly on Jan 23, 2011, 10:45 pm

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.