Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 5 of 5

Thread: Bootloader and Watchdog Timer

  1. #1
    Junior Member
    Join Date
    Jan 2013
    Location
    New Jersey USA
    Posts
    14

    Bootloader and Watchdog Timer

    So I just tried using watchdog code I've used on 328s w/o bootloader and it works fine. So I tried similar code on the teensy++2.0. And now it seems the bootloader is out to lunch. Can not upload a new program.

    The code I used:
    #include <avr/wdt.h>

    int ledPin = 6;

    void setup() {
    pinMode(ledPin, OUTPUT);
    digitalWrite(ledPin, HIGH);
    delay(200);
    wdt_enable(WDTO_2S);
    }

    void loop() {
    wdt_reset();
    }

    When I commented out the reset is when it hosed the bootloader. So the chip tried to reset from the WDT and the bootloader seems to be fried. What to do? Can I reload the bootloader? I have not seen it on the website anywhere?

  2. #2
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    20,323
    This page has a progress for recovering.

    http://www.pjrc.com/teensy/troubleshoot.html

    The main trick is to hold the pushbutton before plugging in the USB cable, and release it only after the cable is fully mated. Make sure the Teensy Loader auto mode is off. It should detect the board. Then you can load another program and write it.

  3. #3
    Junior Member
    Join Date
    Jan 2013
    Location
    New Jersey USA
    Posts
    14
    Paul,

    Yes! that fixed it. So I guess the moral of the story is that I can't use WDT?

    Thanks,
    Rich

  4. #4
    Junior Member
    Join Date
    Mar 2019
    Posts
    2
    Quote Originally Posted by rbhollabaugh View Post
    Paul,

    Yes! that fixed it. So I guess the moral of the story is that I can't use WDT?

    Thanks,
    Rich
    I'm having a similar problem with a Teensy 2.0. Enabling the Watchdog Timer with
    Code:
    wdt_enable(WDTO_2S);
    causes the bootloader to start acting funny and I need to disconnect the cable and plug it again to recover.

    Is there any verdict here? Does this mean we shouldn't use the Watchdog Timer with Teensy 2.0?

  5. #5
    Junior Member
    Join Date
    Jul 2019
    Posts
    1
    Hi All,

    I realize this thread is quite old, but I haven't found any answers to this question, and thought this might be some helpful knowledge to share. Using the setup code in <avr/wdt.h>, I was not able to successfully get my Teensy 2.0 to reboot via WDT. My theory here is that the way the ATMEGA32U4 resets after the watchdog is tripped, is not compatible with how the Teensy 2.0 is setup? (Someone correct me if I'm wrong here). Anyhow, what I ended up doing was setting up the WDT so that it calls an interrupt, as opposed to performing an automatic reset, and then invoking the function _restart_Teensyduino_(); . So far this seems to be working for me. Here is how I've set up the code, which is essentially a modification of the WDT_Prescaler_Change() function example in the ATMEGA32U4 datasheet.

    Code:
    #include <avr/wdt.h>
    #include <avr/interrupt.h>
    
    //WDT Interrupt which will soft reset the board
    ISR(WDT_vect)
    {
      _restart_Teensyduino_();
    }
    
    void WDT_Prescaler_Change(void) {
    
      // make sure wdt flag in mcusr isn't set...
      MCUSR = MCUSR | (0xFF & (0 << WDRF));
    
      //disable interrupts
      cli();
      /* Start timed sequence */
      WDTCSR |= (1 << WDCE) | (1 << WDE);
      /* Set new prescaler (time-out) value = 256kcycles (~2.0s) (Refer to table on pg61 to choose your timeout value) */
      WDTCSR = (1 << WDIE) | (1 << WDP2) | (1 << WDP1) | (1 << WDP0);
      
      //enable interrupts
      sei();
    
    }
    
    void setup(){
    //INITIALIZE WATCHDOG TIMER
      wdt_reset();
      WDT_Prescaler_Change();
    
    }
    
    void loop(){
       wdt_reset();
    }
    I think this should be enough code to help get the WDT up and running. Cheers.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •