Programming AVR won't init b/c of long delay

Discussion in 'Embedded Systems and Microcontrollers' started by washer, Feb 8, 2010.

  1. washer

    Thread Starter New Member

    Nov 25, 2009
    10
    0
    I have been leaning about uCs and messing around with an ATmega 168 trying to get the uart working. I am running a little 'hello world' code blinking an led and messed with the delay time for the output. I slowed it down so it blinked once a second or so, very slow. But when I tried to talk to the AVR after I slowed the code down, I could only get a successful init every 1/10 tries or so.

    I changed the code back to the shorter delay and after pounding on the up-arrow and enter a few dozen times, it finally initialized, re-flashed and is acting normally.

    Could I not init/talk to the uC because I kept hitting it when it was in the long delay? Is there a flag I can use to fix this problem, or is that just really bad code?

    If it matters, I'm using a usbtiny programmer.

    I'm just looking for a little explanation on what exactly was going on and maybe gain a little knowledge. Thanks a ton!
     
  2. AlexR

    Well-Known Member

    Jan 16, 2008
    735
    54
    Without seeing your code one can only guess as to what is going on but I would imagine that you are getting your long delay through delay loops (or probably nested delay loops). While the uC is in the delay loop it can't do any other task so its response looks sluggish.

    A far better way to get long delays is to use one of the uC's inbuilt timers. Then you can either check the timer flag in your main routine or have the timer initiate an interrupt to signal that time's up.
     
  3. John Luciani

    Active Member

    Apr 3, 2007
    477
    0
    Unless you inadvertently changed fuse settings or are loading the SPI lines
    the microcontroller should reset and be programmable via the ICSP regardless of
    your code.

    One other thing to check would be the bitclock switch for avrdude. Depending on
    your fuse setting you may need a slower clock to reliable program the uC.
    I usually use -B 1 which gives 1uS delay. I have seen new devices out of the
    tube require a slower clock. Usually -B 10 will work. -B 100 always works but
    is very slow. Since I set the fuses for an external 12MHz clock I only need the
    slow fuse setting for the initial programming.

    I had a USBtiny programmer that worked sometimes wouldn't work
    other times. Sometimes the USB driver worked other times it didn't.
    I spent $35 for an AVRISPMKII and haven't had any issues
    since.

    (* jcl *)
     
  4. washer

    Thread Starter New Member

    Nov 25, 2009
    10
    0
    Thanks for the feedback.

    I'm starting to think it may be the usbtiny acting a little finicky. I have been using and modifying the code from the Sparkfun beginning embedded electronics tutorial.

    If this keeps happening with the usbtiny, I may look into getting an AVRISP mkII.

    Thanks again for the feedback!
     
Loading...