Cannot connect to arduino... Watchdog mistake please read

Hi everyone, i have an arduino pro mini 5v and it worked perfectly fine till the moment i start testing the watchdog sleep functions…
The problem was that the example code i had made the serial not work… It would send strange characters even in the begining of the setup while i still didnt even start messing with the watchdog settings.

Anyway, here is the example code, i commented everything with // so then i started uncommenting till i got to the point where the serial would stop working…

And when i got to this part the LED 13 started flashing very fast and i now i can’t upload anything, cant even connect to arduino :frowning: please help can i reset the program memory ??

/* In order to change WDE or the prescaler, we need to

  • set WDCE (This will allow updates for 4 clock cycles).
    */
    WDTCSR |= (1<<WDCE) | (1<<WDE);

Original code uploaded:

/*
* Sketch for testing sleep mode with wake up on WDT.
* Donal Morrissey - 2011.
*
*/

#include <avr/sleep.h>
#include <avr/power.h>
#include <avr/wdt.h>

#define LED_PIN (13)

volatile int f_wdt=1;
int counter=0;


/***************************************************
*  Name:        ISR(WDT_vect)
*
*  Returns:     Nothing.
*
*  Parameters:  None.
*
*  Description: Watchdog Interrupt Service. This
*               is executed when watchdog timed out.
*
***************************************************/
ISR(WDT_vect)
{
 if(f_wdt == 0)
 {
    f_wdt=1;
 }
 else
 {
    Serial.println("WDT Overrun!!!");
 }
}


/***************************************************
*  Name:        enterSleep
*
*  Returns:     Nothing.
*
*  Parameters:  None.
*
*  Description: Enters the arduino into sleep mode.
*
***************************************************/

void enterSleep(void)
{
 set_sleep_mode(SLEEP_MODE_PWR_SAVE);

 sleep_enable();

 // Now enter sleep mode.
 sleep_mode();

 // The program will continue from here after the WDT timeout
 sleep_disable(); // First thing to do is disable sleep.

 //Re-enable the peripherals.
 power_all_enable();
 
}

/***************************************************
*  Name:        setup
*
*  Returns:     Nothing.
*
*  Parameters:  None.
*
*  Description: Setup for the serial comms and the
*                Watch dog timeout.
*
***************************************************/
void setup()
{
 Serial.begin(9600);
 Serial.println("Initialising...");

 /*** Setup the WDT ***/

 /* Clear the reset flag. */
 //MCUSR &= ~(1<<WDRF);

 /* In order to change WDE or the prescaler, we need to
  * set WDCE (This will allow updates for 4 clock cycles).
  */
 WDTCSR |= (1<<WDCE) | (1<<WDE);

 /* set new watchdog timeout prescaler value */
 //WDTCSR = 1<<WDP0 | 1<<WDP3; /* 8.0 seconds */

 /* Enable the WD interrupt (note no reset). */
 //WDTCSR |= _BV(WDIE);

 Serial.println("Initialisation complete.");
 
}



/***************************************************
*  Name:        enterSleep
*
*  Returns:     Nothing.
*
*  Parameters:  None.
*
*  Description: Main application loop.
*
***************************************************/
void loop()
{
 if(f_wdt == 1)
 {
    counter++;
    if (counter>=1)
    {
    /* Toggle the LED */
    digitalWrite(LED_PIN, !digitalRead(LED_PIN));
    counter=0;
     Serial.println("Switched the led");
    }
    /* Don't forget to clear the flag. */
    f_wdt = 0;
    /* Re-enter sleep mode. */
    //enterSleep();
   
 }
 else
 {
    /* Do nothing. */
 }
}

Try this:
Press & hold reset button. Download sketch that does not have an issue.
When the IDE says "compiled xxx of 32xxx bytes", release reset.
May have to try a couple of times to hit the correct release point.

Don't know how to help on watchdog coding issue.

if i fail to do that because i already tried more than 20 times is there anyother solution ?

Re-install the bootloader, should kill the sketch, then download the sketch again.

Hi, i am having the same problem, how to re-install the bootloader? I tried to reinstall via Arduino as ISP but it keep giving me problems. Thanks in advance

I made it…

if i press reset button it goes quickly to the blinking shit again b ut when i disconect it and connect it again from the FTDI board it takes like half a second…

So i disconected it from the ftdi board clicked upload and right after it show it would start uploading i pluged ftdi and it started uploading a sample sketch and no works fine again :smiley:

“if i press reset button it goes quickly to the blinking shit again”
That’s why I said Press and Hold the reset button, when to release it is the part that’s a bit time dependent.

Re-installing the bootloader: I use a dedicated AVR ISP
http://www.mdfly.com/index.php?main_page=product_info&cPath=5&products_id=415

If you have another Arduino then you can run a bootloading sketch on it, see reply #17 here for suggestions on that.
http://arduino.cc/forum/index.php/topic,107791.15.html

With the "hold reset" thing, you can release the button when the Rx light flashes once, rather than relying on what the IDE says.