Pages: [1] 2   Go Down
Author Topic: Bootloader only works once?  (Read 2000 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 18
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I'm trying to set up some ATMega328 parts with the Arduino bootloader.  I'm using the following commands to upload the bootloader to the part:

avrdude -B 25 -c stk500v2 -P com3 -p m328p -u -U hfuse:w:0xDA:m

avrdude -B 25 -c stk500v2 -P com3 -p m328p -u -U efuse:w:0x05:m

avrdude -B 25 -c stk500v2 -P com3 -p m328p -u -U lfuse:w:0xFF:m

avrdude -B 1 -c stk500v2 -P com3 -p m328p -u -U flash:w:ATmegaBOOT_168_atmega328.hex

The operation completes successfully.  When I use the Arduino IDE (v 0018) to upload the "Blink" sketch, it works.  However, subsequent attempts to upload another sketch fails until I re-load the bootloader code.

Any idea what I've screwed up?  Thanks all.

g.
Logged

Left Coast, CA (USA)
Offline Offline
Brattain Member
*****
Karma: 331
Posts: 16470
Measurement changes behavior
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I suspect the problem is with the proper use of the locking fuse:

atmega328.bootloader.unlock_bits=0x3F
atmega328.bootloader.lock_bits=0x0F

I suspect that the chip isn't being locked after the bootloader is burned in and then when a new sketch is uploaded it clobbers the bootloader. Can't help with the gory details of how to do all that properly, but I've read of this problem before from others.

Lefty
Logged

SF Bay Area (USA)
Offline Offline
Tesla Member
***
Karma: 106
Posts: 6367
Strongly opinionated, but not official!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Have you implemented auto-reset, or are you using a manual reset button?  The bootloader is only active immediately after reset, unless of course the chip contains no sketch at all, in which case the bootloader will continue to run...
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 18
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I don't know about the lock bits - The avrdude commands were in a batch file I found linked from a tutorial video...

I'm using the firmware that came with the Arduino IDE - I've tried uploading the sketch both before and after hitting the reset button on my STK500, where the chip is installed.

[Update]
I should also mention that the sketch that was originally uploaded continues to operate, it just won't accept new sketches.

Thnx.

g.
« Last Edit: March 16, 2010, 08:33:27 am by geneb » Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 18
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

C'mon guys, throw me a bone here. smiley

I know it's gotta be something stupid that I'm missing.  Help!


g.
Logged

Left Coast, CA (USA)
Offline Offline
Brattain Member
*****
Karma: 331
Posts: 16470
Measurement changes behavior
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Well perhaps if you could say what hardware programmer you are using and how you are using AVRDUDE. Are you using command line staatements to control AVRDUDE or using some script?

I still think it has to do with the locking and unlocking fuse settings, but can't give you help as I've never mastered manual control of AVRDUDE.

Lefty

Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 18
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The exact commands used to program the bootloader are in the first message I posted.  I'm using an STK500 to do the programming of the bootloader.  I'm also using it to download sketches to the '328.

Events are:

1.  Program bootloader
2.  Download "blink" sketch via Aruino IDE
3.  Attempt to download new sketch fails, first downloaded sketch is undisturbed and still running.

I've tried hitting the RESET button the STK500 both before and after starting the 2nd download and it doesn't appear to make any difference.

tnx.

g.
Logged

Left Coast, CA (USA)
Offline Offline
Brattain Member
*****
Karma: 331
Posts: 16470
Measurement changes behavior
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
I've tried hitting the RESET button the STK500 both before and after starting the 2nd download and it doesn't appear to make any difference.


That's a little confusing to me. Does that mean you are using the STK500 to load the second sketch, after loading the first sketch using the Arduino IDE?

The Arduino IDE uses the serial USB link to upload sketches with the active bootloader running on the board talking to AVRDUDE. Loading the bootloader into the AVR chip with the STK500 is a one time operation, after that normal uploading is done via the serial link, not via a STK500. If you use a STK500 to load a sketch it will overwrite the bootloader.

I may just not be understanding your last statement. smiley-wink

1.  Program bootloader With a hardware STK500 programmer, correct?

2.  Download "blink" sketch via Aruino IDE Using normal USB serial connection?

3.  Attempt to download new sketch fails Using USB serial connection or a hardware STK500 programmer?, first downloaded sketch is undisturbed and still running.


Lefty
« Last Edit: March 17, 2010, 02:54:00 pm by retrolefty » Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 18
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

After programming the bootloader,  I remove the ISP cable and move the serial connector to the second DB9 on the STK500.  This port is cabled into the '328 via a 2 wire jumper (rx/tx).  I then use the Arduino IDE to upload the sketch.  It works once, but only once.

tnx.
Logged

Left Coast, CA (USA)
Offline Offline
Brattain Member
*****
Karma: 331
Posts: 16470
Measurement changes behavior
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
I remove the ISP cable and move the serial connector to the second DB9 on the STK500.

I'm not familiar enough with that hardware programmer. I use a USBtiny programmer for burning bootloaders and it uses it's own separate USB connection to the PC and has a ISP cable to attach to the Arduino board, I then use the normal build-in USB serial connection from the Arduino board to the PC for normal IDE uploads of sketches, works fine.

Lefty
« Last Edit: March 17, 2010, 03:02:29 pm by retrolefty » Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 18
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

*blinks*

There's nothing wrong with the hardware.  The programmer operates just fine.  The programmed part also works - it takes a sketch download *once*.  Subsequent tries fail.

I really need help getting this straightened out.

g.
Logged

Left Coast, CA (USA)
Offline Offline
Brattain Member
*****
Karma: 331
Posts: 16470
Measurement changes behavior
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Maybe you can get help over at the AVRfreaks site, they have a lot of professional types that really know a lot.

http://www.avrfreaks.net/index.php?name=PNphpBB2&file=viewforum&f=3&sid=08ebf312d189415fb5b177cde07c5a66

Lefty
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 18
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

So essentially, you're shoving me off on to another forum because you're not interested in helping me or understanding the problem.

Gee, thanks.

g.
Logged

Left Coast, CA (USA)
Offline Offline
Brattain Member
*****
Karma: 331
Posts: 16470
Measurement changes behavior
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
So essentially, you're shoving me off on to another forum because you're not interested in helping me or understanding the problem.

Gee, thanks.

I'm sorry you feel that way. I have claimed no expertize that can solve your problem. I have explained how I accomplish the same task even if I don't understand all the internal complexity that is required. As no one else has been responding to your post lately, I gave you the only lead (avrfreaks) that I can think off. I am certainly not holding back any secret knowlege or solution for your problem.

Again sorry to not be able to rise to your expectations. I suspect it's more about your frustration with your problem, then about my responses.

Lefty
« Last Edit: March 17, 2010, 03:54:27 pm by retrolefty » Logged

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

Have you tried using the Arduino IDE to burn the bootloader?
Logged

Pages: [1] 2   Go Up
Jump to: