NerdKits - electronics education for a digital generation

You are not logged in. [log in]

NEW: Learning electronics? Ask your questions on the new Electronics Questions & Answers site hosted by CircuitLab.

Microcontroller Programming » Bootloader woes

April 02, 2013
by jgauthier
jgauthier's Avatar

Hey Everyone,

I was doing some programming with my 168p, when it suddenly stopped verifying. I assumed something bad happened, so I ordered another without a bootloader. I picked up a usbasp (http://www.9xrprogrammer.com/). Unfortunately, I have been unable to get the bootloader on the device. I have read this article (http://www.nerdkits.com/library/howto_install_bootloader/).

I get this error:

avrdude: error: programm enable: target doesn't answer. 1

So, since this is a blank chip, I am assuming it's using the 1Mhz internal oscillator. However, I have tried putting in the NK 14.74Mhz, and a 16Mhz external. Same error!

So, I decided to take the original NK processor, and low and behold.. not only was I able to write it a new bootloader, but that restored it to full functionality!

So, I know my programming rig is set up well.

So, my last thought is that the programmer needs to be in low speed mode (from the previous link: If you are using the USBASP like I have, you will need to have the low speed jumper installed when programming the bootloader.)

But I don't seem to have a jumper or anything. There is a blank space on the board called J2. However, when I look at the manufacturer's website (http://www.aliexpress.com/store/product/USBasp-3-3V-5V-AVR-Programmer-USB-ATMEGA8-ATMEGA128-New-5PCS/812021_554471139.html) I am pretty sure that it auto-changes speeds. The broken English is very hard to read.

Anyone have any suggestions?

Thanks!

April 02, 2013
by jgauthier
jgauthier's Avatar

Incidentally: I also have two 328Ps, that I purchased with an existing bootloader, and I was able to erase them and program them! I'm nearly certain that this has something to do with the fact that the 168 is empty.

I have an ATRtiny85 I will try later.. But I have to research it's fuse settings first. Thanks!

April 02, 2013
by Noter
Noter's Avatar

http://www.9xrprogrammer.com/index.php/learn/31-usbasp-firmware suggests using the -B option in AVRDUDE.

April 02, 2013
by Noter
Noter's Avatar

From AVRDUDE doc ...

-B bitclock Specify the bit clock period for the JTAG interface or the ISP clock (JTAG ICE only). The value is a floating-point number in microseconds. The default value of the JTAG ICE results in about 1 microsecond bit clock period, suitable for target MCUs running at 4 MHz clock and above. Unlike certain parameters in the STK500, the JTAG ICE resets all its parameters to default values when the programming software signs off from the ICE, so for MCUs running at lower clock speeds, this parameter must be specified on the command-line. It can also be set in the configuration file by using the ’default_bitclock’ keyword.

April 03, 2013
by jgauthier
jgauthier's Avatar

Thanks! I didn't mention my attempts at using -B1 in the command line. I did try that, but did not succeed with it.

However, I only used -B1, so I will read up a little and see if there's an better option.

April 03, 2013
by jgauthier
jgauthier's Avatar

According to the datasheet, the 168 is set internally to 8Mhz, with divider making it 1Mhz. So, it looks like -B1 is the correct option.

April 03, 2013
by Noter
Noter's Avatar

"-B 1" equals one microsecond which according to the text is good for microprocessors clocked at 4Mhz and up. So I would expect it to fail on a microprocessor clocked at 1Mhz. Try some other values like "-B 0.9", "-B 0.8" and work your way down until it works or you hit bottom.

April 03, 2013
by Noter
Noter's Avatar

Or maybe you need to go the other direction. A longer clock period would be a slower rate. Try "-B 2", "-B 3", etc.

April 03, 2013
by Noter
Noter's Avatar

The 1st thing I do when programming a new chip is to set the fuses to run at at 8Mhz internally or to use an external crystal. http://www.engbedded.com/fusecalc is helpful in figuring fuse values.

April 03, 2013
by jgauthier
jgauthier's Avatar

Thanks, I did try to increase it, but not decrease it below -B1. I will try that.

I can't do anything with the fuse configuration yet, because I cannot even talk to the chip.

April 03, 2013
by Noter
Noter's Avatar

I don't have any other ideas to get your new programmer to work. You might try contacting the seller and see if he can help. In the mean time you can take your working chip and use it as a programmer to set the fuses on your new chips - Nerdkit ISP Programmer.

April 03, 2013
by Rick_S
Rick_S's Avatar

This is the makefile I use for installing a bootloader on a new blank chip using the USBASP I reference in my bootloader tutorial.

AVRDUDEFLAGS=-c usbasp -pm328p -B 6

all: fuses install

fuses:
    avrdude ${AVRDUDEFLAGS} -U lock:w:0x2f:m
    avrdude ${AVRDUDEFLAGS} -U efuse:w:0x05:m
    avrdude ${AVRDUDEFLAGS} -U hfuse:w:0xd2:m
    avrdude ${AVRDUDEFLAGS} -U lfuse:w:0xf7:m

install:
    avrdude ${AVRDUDEFLAGS} -U flash:w:foodloader.hex:a

Works every time for me.

Rick

April 04, 2013
by jgauthier
jgauthier's Avatar

Well, I have tried just about everything. I can re-program chips that have been programmed, but not unprogrammed chips. I have tried every variation of -B under both Linux and Windows. I have no idea what's wrong, unless the programmer is not really changing speeds. I am going to look into the programmer, and perhaps using an existing 168 or 328 to program.

April 04, 2013
by jgauthier
jgauthier's Avatar

Hold the phone... I apparently was wrong. There was a combination I did not try under Linux and I got it to work. I moved it back to Windows.. No go!

Turns out, the version of avrdude I have (5.6), didn't work. 5.11 does.

facepalm

April 05, 2013
by Rick_S
Rick_S's Avatar

Sorry, I didn't think of that. The easiest way to get a current release of avrdude in Windows is to download the current arduino software. After you extract the ZIP, look in the

arduino-1.0.4\hardware\tools\avr\bin folder for avrdude.exe

and the

arduino-1.0.4\hardware\tools\avr\etc folder for the current avrdude.conf file.

1.0.4 is the current release of the arduino software as of 4/5/13 - depending on the version you have, you may have a different number for the first folder.

Rick

Post a Reply

Please log in to post a reply.

Did you know that you can use printf and scanf functions to talk to your computer from your USB NerdKit? Learn more...