Pages: [1]   Go Down
Author Topic: [Solved!] Help! Target stuck in a sketch.  (Read 1690 times)
0 Members and 1 Guest are viewing this topic.
Dallas, Texas
Offline Offline
God Member
*****
Karma: 0
Posts: 861
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Okay, I got a 16MHz crystal today and installed it in the AAG logic board. Just for fun, I compiled and attempted to upload the sketch that was topmost in the IDE window. Without doing anything special, I got a successful upload. The sketch ran and printed what it was supposed to to the serial monitor. I was ecstatic.

Now, when I try to upload another sketch, I get this error:

Quote
avrdude: stk500_recv(): programmer is not responding

I hooked the logic analyser up to the USB/serial bridge and captured TX, RX, by triggering off of the reset pulse. Lo and behold, the AAG is running the sketch I programmed into it first.

My reset pulse from the USB/serial bridge at the processor is 200 µsec and the sketch starts transmitting characters 3.8 msecs after the end of the rest pulse.

Obviously, the bootloader is not talking to the IDE, but why?
« Last Edit: September 20, 2011, 03:46:23 pm by EmilyJane » Logged

Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 548
Posts: 27372
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

The sketch is too busy talking to listen.
Try this - press & hold the reset button. Start the download - when the sketch says "downloading xxxx of xxxx bytes" release the reset - this will let the bootloader sync with the IDE.
Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

Dallas, Texas
Offline Offline
God Member
*****
Karma: 0
Posts: 861
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The sketch is too busy talking to listen.
Try this - press & hold the reset button. Start the download - when the sketch says "downloading xxxx of xxxx bytes" release the reset - this will let the bootloader sync with the IDE.

I tried that numerous times. Actually, I don't have a reset "button" but I have a wire lead that I can plug and unplug pretty much like a button.
Logged

Dallas, Texas
Offline Offline
God Member
*****
Karma: 0
Posts: 861
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The AAG logic board originally had a 200K resistor to 5V and a 0.1µF cap to ground. I removed the cap so that the auto-reset from the serial interface would work. I have a 100nF cap from the reset pin to the serial interface like on the Arduino boards. Do you suppose that resistor is too large? The Arduinos have a 10K.

I left it alone because it is an SMD and I didn't have anything to replace it with but I can parallel a discrete with it to get the equivalent down to around 10K. I'll try that.
Logged

Dallas, Texas
Offline Offline
God Member
*****
Karma: 0
Posts: 861
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

That didn't help. I noticed I wasn't capturing all the activity on the serial IO so I stretched my sample period out to a couple of seconds. After reset, which it 32 µsec with the 10K pull-up, the programmed sketch runs three times and then the IDE sends 0x30 and 0x20 twice to the target. This happens about 1400 msec after reset.

It's acting like that first upload could have overwritten part of the bootloader, but I don't know how that would happen. Maybe the latest combination of Arduino(22) and the Atmega8 bootloader delivered with it are not compatible and no one has noticed it yet. I'm graspin' at straws here.
« Last Edit: September 16, 2011, 04:06:35 pm by EmilyJane » Logged

Global Moderator
Dallas
Offline Offline
Shannon Member
*****
Karma: 210
Posts: 13039
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset


Did you use the Arduino IDE to install the bootloader?

If yes, which board did you have selected?
Logged

Dallas, Texas
Offline Offline
God Member
*****
Karma: 0
Posts: 861
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset


Did you use the Arduino IDE to install the bootloader?

If yes, which board did you have selected?


Yes, I did. I'm pretty sure I selected "Arduino NG or older w/ Atmega8". Maybe the thing to try is to re-burn the bootloader.

Edit: Now that I think about it, I think I used avrdude to install it.
« Last Edit: September 17, 2011, 09:51:25 am by EmilyJane » Logged

Global Moderator
Dallas
Offline Offline
Shannon Member
*****
Karma: 210
Posts: 13039
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Now that I think about it, I think I used avrdude to install it.

Did you set the "lock bits"?

Fair warning: I have not installed a bootloader from the command-line.  I have always used the IDE.  I believe installing a bootloader is a multi-step process...  unlock, set fuses, upload bootloader, lock.  But, I could be wrong.
Logged

Dallas, Texas
Offline Offline
God Member
*****
Karma: 0
Posts: 861
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Did you set the "lock bits"?

I don't think I did. The lock bits were set to 0x3f in the original. They are probably still that.

It's been several days since I was successful in getting avrdude to read the original flash so my memory is a little foggy about what all I did. I was so happy just getting to that point, that I think I just burned the bootloader .hex file for Atmega8 from the Arduino 0022 distribution with avrdude and called it a day. Since I didn't have a freestanding USB bridge then, I just pulled the 3.68MHz crystal and put it aside until I could use it at 16MHz.

I have a USBtinyISP on the way which I thought would arrive today but it didn't. I have torn down the breadboard to use Arduino as a programmer so I'm just going to wait for the dedicated programmer.

If I use USBtinyISP to burn the bootloader from the IDE, does it select the .hex file to use based on the IDE:Board setting or is there an additional dialog where you set that? From your comments, I presume it takes care of all the fiddly-bits as well?
Logged

Global Moderator
Dallas
Offline Offline
Shannon Member
*****
Karma: 210
Posts: 13039
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
If I use USBtinyISP to burn the bootloader from the IDE, does it select the .hex file to use based on the IDE:Board setting

Yes.  If you'd like the details, the mapping from menu selection to .hex file is in a file named "boards.txt".

Quote
or is there an additional dialog where you set that?

No.

Quote
From your comments, I presume it takes care of all the fiddly-bits as well?

It always has for me.  Which is why I use the IDE (brain ... overloading ... on ... fiddly-bits !!!).
Logged

Dallas, Texas
Offline Offline
God Member
*****
Karma: 0
Posts: 861
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Yes.  If you'd like the details, the mapping from menu selection to .hex file is in a file named "boards.txt".

Yes, that's how I found the .hex file to use with avrdude. I wondered at the time if I should have done anything with the fuse and lock bits. Probably should have wondered harder. smiley I'd still like to know exactly what happened to cause my current problem.

Quote
It always has for me.  Which is why I use the IDE (brain ... overloading ... on ... fiddly-bits !!!).
I hear that! smiley-grin I've gone cross eyed figuring them out for PIC processors. Before flash, if you made a mistake you ended up bricking the chip. Still possible with flash but you really have to have your moron hat on. smiley

I have plenty to keep me occupied this weekend so I'm just going to wait for USBtinyISP and re-do the bootloader. Maybe I'll read the current flash beforehand and see if I can tell what got clobbered.
Logged

Dallas, Texas
Offline Offline
God Member
*****
Karma: 0
Posts: 861
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Re-flashing the bootloader solved the problem. This time, I did it through the IDE menu, specifying USBtinyISP as the programmer. I think the problem was that I didn't program the fuses when I did it using the Arduino as the programmer.

Holding Reset until I get the first LED flash from the USB interface works fine. I'll try an auto-reset later.
Logged

Global Moderator
Dallas
Offline Offline
Shannon Member
*****
Karma: 210
Posts: 13039
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset


Nice!  Now you can fiddle with the application instead of the tools!
Logged

Dallas, Texas
Offline Offline
God Member
*****
Karma: 0
Posts: 861
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset


Nice!  Now you can fiddle with the application instead of the tools!


Yes, it's nice to get all that behind me. Auto-reset works too.
Logged

Pages: [1]   Go Up
Jump to: