0

When I was programming an arduino uno with atmel studio via usb cable, everything worked fine. Now I am trying to upload a code via usbasp programmer, it works, whereas arduino keeps restarting and L labelled pin flashes even when I have not activated it by code. After a bit searching I've found that,I should unprogram watchdog timer by adding this command:

C:\Users\Eldar>avrdude -c usbasp -p m328 -P COM5 -b 19200 -U lfuse:w:0xEF:m -U hfuse:w:0xD9:m output of that:

 avrdude: warning: cannot set sck period. please check for usbasp firmware update. avrdude: AVR device initialized and ready to accept
    instructions Reading |
    ################################################## | 100% 0.03s avrdude: Device signature = 0x1e950f avrdude: reading input file
    "0xEF" avrdude: writing lfuse (1 bytes): Writing |
    ################################################## | 100% 0.01s avrdude: 1 bytes of lfuse written avrdude: verifying lfuse memory
    against 0xEF: avrdude: load data lfuse data from input file 0xEF:
    avrdude: input file 0xEF contains 1 bytes avrdude: reading on-chip
    lfuse data: Reading |
    ################################################## | 100% 0.01s avrdude: verifying ... avrdude: 1 bytes of lfuse verified avrdude:
    reading input file "0xD9" avrdude: writing hfuse (1 bytes): Writing
    | ################################################## | 100% 0.02s
    avrdude: 1 bytes of hfuse written avrdude: verifying hfuse memory
    against 0xD9: avrdude: load data hfuse data from input file 0xD9:
    avrdude: input file 0xD9 contains 1 bytes avrdude: reading on-chip
    hfuse data: Reading |
    ################################################## | 100% 0.02s avrdude: verifying ... avrdude: 1 bytes of hfuse verified avrdude:
    safemode: Fuses OK avrdude done.  Thank you.

I changed 0xD9 to 0xC9 but it`s still the same.Moreover,when i try to program arduino with usb cable again,avrdude gives this error:

avrdude.exe: stk500_getsync(): not in sync: resp=0x00
avrdude.exe done.  Thank you.

This is my code that I try to upload just for testing

#define F_CPU 16000000UL
#include <avr/io.h>
#include <util/delay.h>
int main(void)
{
    DDRD |= 0B11111111;
    DDRB |= 0B11111111;
    while(1)
    {
    PORTD |= 0B00110000;
    PORTB |= 0B00110000;
    _delay_ms(1000);
     PORTD ^= 0B00000000; 
     PORTB ^= 0B00000000;
    }
}

Ive also tried unprogram watchdog timer inside the program itself,its still the same.There are attempts below. Attempt1

#define F_CPU 16000000UL
    #include <avr/io.h>
    #include <util/delay.h>
    #include <avr/wdt.h>
     int main(void)
    {
    MCUSR = 0;
    wdt_disable( );
     while(1)
     {
        //nothing 
     }
     }

Attempt2

#define F_CPU 16000000UL
#include <avr/io.h>
#include <util/delay.h>
#include <avr/wdt.h>
 int main(void)
{


    wdt_reset();
     MCUSR=0;
     WDTCSR|=_BV(WDCE) | _BV(WDE);
     WDTCSR=0;
     while(1)
     {
        //nothing 
     }
     }

Also,why it does not work when i configure the chip with avrdude directly via command line either?

migrated from electronics.stackexchange.com Jan 29 at 21:36

This question came from our site for electronics and electrical engineering professionals, students, and enthusiasts.

  • Professional programs always have the watchdog enabled. The correct fix is to write to the relevant watchdog refresh register once from the main while(1) loop. For debug build, you can disable the watchdog. But it's good to have even then, if you can set it to freeze upon single step debugging, because it will expose timing problems in your program. – Lundin Jan 29 at 13:35
  • (But then again, Ardunio was never meant to be used for non-hobbyist purposes) – Lundin Jan 29 at 13:36
  • Could you suggest relevant code for watchdog refresh register once from the main while(1) loop,because Ive tried these(in the below comment),but its still the same – Eldaronics Jan 30 at 19:12

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Browse other questions tagged or ask your own question.