Pages: [1]   Go Down
Author Topic: How can I save my arduino mega 2560  (Read 936 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 1
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I've uploaded a watchdog timer code. When I connected to the battery, it keep resetting and I can't stop it. I tried to upload another code, but it kept resetting and it stopped at the uploading part.
Logged

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 602
Posts: 33362
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

You need to reflash the boot loader.
Logged

SF Bay Area (USA)
Offline Offline
Tesla Member
***
Karma: 124
Posts: 6645
Strongly opinionated, but not official!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

If you need watchdogs to work, you need a new bootloader.

if you simply need to recover the MEGA so you can used ordinary sketches, you should be able to use the "hold the reset switch down while plugging in the board, and don't release it till exactly the right time during the upload of a new sketch" procedure.
Logged

Left Coast, CA (USA)
Offline Offline
Brattain Member
*****
Karma: 361
Posts: 17262
Measurement changes behavior
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

If you need watchdogs to work, you need a new bootloader.

if you simply need to recover the MEGA so you can used ordinary sketches, you should be able to use the "hold the reset switch down while plugging in the board, and don't release it till exactly the right time during the upload of a new sketch" procedure.

 That depends on the time out value that the WDT is using, if too short then even the manual 'hold the reset button down' doesn't work. The following sketch using a 15 millisecond WDT value will brick any standard bootloader equiped mega1280/2560 board and can only be recoved via reburning the bootloader.

Code:

// Test sketch to see if WDT interrupts are handled properly by the bootloader

/*
 Warning Warning Warning this is a semi-destructive test in that
 if your bootloader does not reset WDT interrupts upon starting
 it will be forced into a tight loop of bootloader starts/WDT resets
 chip/bootloader starts again/lather rinse repeat. One can only
 recover to normal operation by reburning the bootloader with
 a ICSP programmer. If this sketch runs properly on a chip with a WDT aware bootloader,
 you will see continuous serial output on the serial monitor.

Note that current arduino mega boards will fail this test and brick

*/

// Code from arduino forum poster (sorry name not remembered) 1/11/13

#include <avr/wdt.h>

void setup(){
  Serial.begin(57600);
  delay(100);
  Serial.println("Hello world");
  wdt_enable(WDTO_15MS);
}

void loop(){
  Serial.println("I am going to not get stuck..");
  for(int x=0; x<100; x++) {
    wdt_reset();
    x++;
    delay(10);
  }
  wdt_reset();
  Serial.println("I am going to get stuck now..");
  for(int x=0; 1; x++) {
    delay(10);
  }
}
Logged

SF Bay Area (USA)
Offline Offline
Tesla Member
***
Karma: 124
Posts: 6645
Strongly opinionated, but not official!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
That depends on the time out value that the WDT is using, if too short then even the manual 'hold the reset button down' doesn't work.
Why would that be the case?  By holding the RESET switch during powerup, you're preventing the WDT from ever being enabled by the sketch (by preventing the sketch from running), so it doesn't matter what the sketch sets the timeout to.  A sketch can't set the fuse that enables the WDT at poweron...

The "problem" is that the WDT is not disabled by a external RESET operation, so once a sketch turns on the WDT, it STAYS on through the usual "upload" resets.  But the WDT is still off at power on (unless you change the fuse.)

Nevertheless, I decline to try out your sample sketch :-)
Logged

Left Coast, CA (USA)
Offline Offline
Brattain Member
*****
Karma: 361
Posts: 17262
Measurement changes behavior
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
That depends on the time out value that the WDT is using, if too short then even the manual 'hold the reset button down' doesn't work.
Why would that be the case?  By holding the RESET switch during powerup, you're preventing the WDT from ever being enabled by the sketch (by preventing the sketch from running), so it doesn't matter what the sketch sets the timeout to.  A sketch can't set the fuse that enables the WDT at poweron...

The "problem" is that the WDT is not disabled by a external RESET operation, so once a sketch turns on the WDT, it STAYS on through the usual "upload" resets.  But the WDT is still off at power on (unless you change the fuse.)

Nevertheless, I decline to try out your sample sketch :-)


You are of course correct, I just read past the power off then hold reset while powering back up part. That will allow a new sketch to be reloaded, however it will tax one's skill at timing the release as it took me 3 or 4 attempts before it would take.

Quote
Nevertheless, I decline to try out your sample sketch :-)

Probably a good choice unless you have some time to spare.  smiley-wink

Lefty
Logged

Pages: [1]   Go Up
Jump to: