How do I Restore when ICSP not working?

Hi everyone! I'm new to the Arduino but not micro controllers in general. I've had my nano for about a week now and have been playing with it using the both Arduino IDE and AVR studio. Things have been going great until today. I started messing around with counters and interrupts and I have put myself in quite the predicament. So now I'm hoping some expert help will prevent me from needing to buy a new one :).

Basically, what I've done is set up TIMER2 with a 1024 prescaler and an overflow interrupt. When the interrupt handler is called, I'm turning on some LEDs and delaying in order to verify the interrupt was called. Then I return to an empty busy loop in main and wait for the next overflow. I was programming this using AVR Studio and uploaded it via my AVRISP MKII and it ran fine.

However, now that I've uploaded this program, I can no longer connect to the Atmel to update the code. Every time I try to connect in AVR Sudio, it fails, even though I get the Green light on the AVRISP saying it has detected the chip. Should the AVRISP always be able to update the flash regardless of the program that's running? My first guess is that my interrupt handler is taking so long that by the time it exits, the overflow has already occurred again, and immediately calls the interrupt again. So there's no real "free" time for the micro to handle the ICSP connection. Would this constant interrupting prevent the ICSP from being able to communicate?

So I'm now stuck with these LEDs going crazy every time I power on the nano and I can't connect to fix the code. Is there a way I can stop the code from running or completely clear the flash without ICSP? How hosed am I? Be straight with me doc, I can take it...

-Thedigitalsean

OK so I fixed it. The problem was with my notebook not connecting the AVRISP over USB, not with the AVRISP connecting to the Atmel over ICSP. I did the #1 fix in Computer Engineering for Windows.... Restart. I love Vista sooooo much :slight_smile:

But, out of curiosity, what is the restore procedure for this things?

It should be pretty difficult to get the cpu in a state where ICSP doesn't work; I think you'd have to munge the "fuse" bits, which you can't do from a program (but can do from ICSP.) For example, you could turn off the RESET function of the pin, turning it into a general purpose IO. I think that at that point, your only recovery is "parallel programming" with a suitable programmer. It would be annoying but possible, I think, to connect a parallel programmer to an ardunino using an SMT AVR; lots of jumpers to the appropriate PORT pins; much easier to pop out a DIP and put it in the programmer.

It's more common to somehow damaged the bootloader that most people use for loading the code into the arduino. And THAT can be fixed by using ICSP to erase and re-program the AVR.

Helpful info. It's good to know I'd have to try pretty hard to break it. Thanks.