How to program a locked ATMega16

Go To Last Post
41 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I've been searching around in circles to find a procedure to reset an ATMega16 to its factory programmed fuse bits state. I used an ISP programmer to lock up the chip to further programming. The chips arrived set to use the 1 MHz internal RC osc and all attempts by me to try to change just the clock options thru ISP to enable an external crystal result in locking up the chip.

From what I've read it seems it might be possible to use a JTAG programmer to program both the SPIEN and JTAGEN fuse bits, but the ATMEga16 spec sheet is extraordinarily glib on whether or how this can be done. How does the factory reprogram locked devices ? If both JTAGEN and SPIEN are disabled, how can further programming attempts succeed at all ?

Do I have to just throw away this chip ??? :x

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

High voltage parallel programming on an STK500 can recover it.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The spec sheet indicates that high voltage programming is not available. Only older, smaller parts have this capability.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:

I used an ISP programmer to lock up the chip to further programming.

You can't disable the SPIEN fuse with ISP. You like many others just set the wrong type of fuse setting for the external clock. The usual cure is to supply a clock signal ~1Mhz to the chip.

If you do have a jtag programmer then it has its own clock so it should allow you to get back into it.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

pascor wrote:
The spec sheet indicates that high voltage programming is not available. Only older, smaller parts have this capability.

From the STK500 High Voltage Programming supported device table:

    AVR devices - Atmega16
    STK500 socket - SCKT3100A3
    Color - Red
    Number - 3
    High voltage programming method - Parallel programming as above, mount the BSEL2 jumper. See section BSEL2 Jumper.

See also page 262 of the datasheet.

High voltage serial programming is not supported.[/]

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You probably programmed the fuses to the inverse of what you wanted. A fuse bit is set by writing a ZERO to its' bit and is cleared by writing a ONE to its' bit. AVR studio will show a check mark on active fuses, but the VALUE of that fuse is a zero. I'm almost certain that avrdude reports the stored value of the fuse bits, NOT their ACTIVE STATE.

While you can disable the JTAG with the fuses, you can't disable the ISP programming (at least NOT on the atmega16). On some of the smaller avr's you can disable the reset pin, which WILL disable the ISP programming as well. If the internal crystal oscillator and RC oscillator have been disabled, then an external clock must be injected to the clock input pin to program the part. Get a cheap 1mhz crystal oscillator 'can' or build a simple oscillator. Even an RC oscillator with a 555 or cross connected gates will work if it's running at least a few hundred KHZ.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The ATMega16 does have a parallel programming mode, but no high voltage programming mode. Using the STK500 to program in high voltage programming mode just might blow up the chip. Including the ATMega16 in the STK500's high voltage compatible programming device list is a typo.

Perhaps 5V parallel programming will work, but I haven't seen a newer development board (as mine) that supports parallel programming. This indicates that there is another way to program the fuse bits. That is, by not using a RS232 or parallel port xface, or by popping the chip into another programming board.

Does anyone know for sure that I can use a JTAG xface programmer to reset the chip ?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I don't think you need to use the parallel programmer. I think the ISP will work if you provide the chip with an external clock. Have you tried this yet? It is likely that you have 86ed the jtag fuse and do NOT have this option. The atmel avrjtagmkII will do ISP programming by using the squid cable to make the connections. IIRC the avr dragon does parallel programming.

NOTE:
It is possible to disable the SPIEN (spi enable) fuse from the JTAG. It is also possible to disable the JTAGEN fuse (jtag enable) from the JTAG. These bits are set to 0 (programmed) at the factory. SO using the jtag you CAN disable both the SPI and JTAG programming of data and fuse bits. (outch!)

If this actually happened, then you will need to use the parallel programmer to restore the chip.

The stk500 will do parallel programming. The instructions are given in the high voltage programming section. The spec sheet for the atmega16 says that to enter parallel programming 11.5-12.5 volts is applied to the reset line. This is why it is called HV programming. This will NOT destroy the chip.
The avr dragon will do this as well.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:
The spec sheet indicates that high voltage programming is not available.
High voltage serial programming is not available on the mega16. High voltage parallel programming is.

Regards,
Steve A.

The Board helps those that help themselves.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:
The ATMega16 does have a parallel programming mode,
Use THAT. Remember 20+ wires needed on the STK500. That's provided you can get the chip into the STK500 easily like a socketed PDIP.

John Samperi

Ampertronics Pty. Ltd.

www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

If the OP has a STK500 then why not just hook up the onboard oscillator and use that.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I stand corrected. There is a "high voltage" parallel programming mode, but it isn't referred to as "high voltage". Atmel just calls it parallel mode programming. Everyone else calls it "high voltage programming".

I had confused a parallel port programmer with a parallel mode programmer. It seems that stand-alone parallel mode programmers should be available in all flavors of PC data interfaces.

I'll apply an external clock and try using my serial programmer. If that doesn't work it looks like I'll have to get a parallel mode programmer. I really don't want to purchase an STK500.

Thanks

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

As mentioned, it is quite difficult to "brick" an AVR using what you have described.

Find the many many "brick" and "inject" threads with a forum search.

We've done scores of production AVR apps over the last decade, and have never yet done a parallel/HV programming. No need. Ever. Period.

(But it seems that many want to immediately jump on that bandwagon. Go figure.)

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

pascor wrote:
I stand corrected. There is a "high voltage" parallel programming mode, but it isn't referred to as "high voltage". Atmel just calls it parallel mode programming. Everyone else calls it "high voltage programming".

I had confused a parallel port programmer with a parallel mode programmer. It seems that stand-alone parallel mode programmers should be available in all flavors of PC data interfaces.

I'll apply an external clock and try using my serial programmer. If that doesn't work it looks like I'll have to get a parallel mode programmer. I really don't want to purchase an STK500.

Thanks

You can do the same thing for less money with the avr dragon

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I applied a 250 KHz 5V clock to the XTAL1 pin and slowed down the Avrdude programming clock as much as possible with its "-i" option, but still had no luck even reading from it. Since there's no way for me to tell if JTAG access has also been disabled it looks like I'll have to use a parallel mode programmer to rescue the chip.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

what value did you use for the -i parameter? With a 250KHz clock injected, you need to be less than 62.5KHz [or a period > 16uS] **Note that if you're using a windows machine the actual delays are not very accurate. [If it's a fast machine, the delays can be much shorter than expected] also note that -i only applies to bit-banged type programmers. use -B for non bit-banged programmers like the AVRISP.

Writing code is like having sex.... make one little mistake, and you're supporting it for life.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:
... you need to be less than 62.5KHz
What does this mean mean ?

The "-i" parameter value seems to max out at 10,000 usecs/10 milliseconds according to the Avrdude trace statements. This should be a 100 Hz programming clock which I haven't verified.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You can not cripple a mega16 via ISP.
You can select inappropriate clock fuses.

If you only have a JTAG programmer, you can get stuck if the JTAGEN fuse gets cleared. You can cripple yourself if you clear the SPIEN fuse too.

If you quote your ISP interface, post a schematic, post a photo ... you could get step by step help.

David.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

David, I know it's not crippled, just inaccessible by my LadyAda USBTinyISP programmer to my Olimex AVR-P40-8535 development board.

See the attached file for all my info.

Attachment(s): 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The oscillator circuit you have isn't giving you a 50% duty cycle, but it should be close enough. You might want to square up the waveform a bit with an 'HC14 before feeding it to the AVR, I don't know if that dip on the rising edge will cause any problems otherwise.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The spec sheet gives no clock duty requirement, just minimum high and low durations. The glitch on the rising edge is above the high state minimum voltage requirement of the m16.

A series output resistor would slow down the edges and prevent the glitch in the first place. I did try a 100 ohm resistor, but it had no effect. 100 ohms works well on gate outputs that have 5 ns rise and fall times and drive long wires, but the oscillator is based on a NE556 and the entire hand-wired perf board measure a little over 1 square inch.

Adding another IC of any kind would require creating a new oscillator board and a buffer IC which I don't have on hand. Later on I might just buy a canned 5V oscillator ($$ and relatively lots of milliamps) and a buffer IC to make building a new external clock board a lot easier.

Attachment(s): 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

If you have a crystal on hand you could dead bug an oscillator using cross coupled gates with the rock in the feedback path.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Your dev board has a JTAG header. So you can use any JTAG programmer that you like. (does not need a clock)

I have never used a usbtiny. It appears that it accepts the -B switch from avrdude. So you can use your 250kHz clock with 'avrdude -c usbtiny -B20' i.e. 50kHz ISP.

I assume your 250kHz clock works ok. Listen with an AM radio on 750kHz, 1250kHz, 1750kHz ...

David.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Unfortunately, I don't have a JTAG programmer. Besides, misprogramming the fuse bits with my USBTinyISP may have disabled JTAG programming. So, if I get another programmer it will have parallel mode programming capability which can't be disabled on the '16.

I've looked, but haven't found any USB-in/parallel mode programmers anywhere. Just some old parallel port/parallel mode and RS232/parallel mode programmers. The only non-Centronics/parallel mode programmer I've found so far is the STK500. But, it has RS232-in and I guess I'd have to use a USB-RS232 converter to talk to it. Or, I could get a COM port header cable+IO bracket to add to my PC. I think the USB-RS232 converter is actually cheaper. Go figure.

Does anyone know of any other non-parallel(Centronics)-port/parallel mode programmers ?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I give up. I presume you understand English.

Try reading the replies.

I apologise if English is not your first language.

David.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

As has been stated earlier... look at the AVR-DRAGON

--greg
Still learning, don't shout at me, educate me.
Starting the fire is easy; the hardest part is learning how to keep the flame!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The original question was about resurrecting his mega16 chip.

He possesses a 'usbtiny' ISP programmer from SparkFun. So he has a reliable commercially built programmer.

He has already made a 250kHz clock. I have no idea whether it works. But if he has constructed it carefully from a respected design, I am sure that it should work fine. Since he does not mention the component values there is little point in readers checking his photo.

He needs no extra equipment for recovering his mega16.

Of course he could buy a Dragon or JTAGICE-1 clone or even a JTAGICE-mkII for JTAG programming.

Or he could buy a STK500 or Dragon for completely unnecessary HVPP. But hey-ho, people like to spend money.

Personally, I would unbrick the mega16 with the existing tools (usbtiny + 250kHz clock)

If he enjoys the hobby, purchasing a Dragon for JTAG debugging is a worthwhile expense.

David.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

perhaps the chip is already destroyed somehow, hence no amount of fiddling will revive it....why not just try another chip--they are very cheap

getting your application running is more important than hookup gymnastics

Hoyt

When in the dark remember-the future looks brighter than ever.   I look forward to being able to predict the future!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The files showing my setup are attached.

Quote:
He needs no extra equipment for recovering his mega16.
How did you you come to this conclusion ?

JTAG programming can easily be disabled by ISP (mis)programming the fuse bits. I have no JTAG programmer, so this is a moot point at the moment.

Exactly how can I recover this '16 using an ISP programmer if my ISP programmer can't talk to the chip even with an external clock ?

Attachment(s): 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

As I said earlier. Read the replies.

If there is something you do not understand, quote the passage.

Your scope trace is clear evidence that your 250kHz clock is working ok.

Please copy-paste the avrdude command and its response.

David.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:
So you can use your 250kHz clock with 'avrdude -c usbtiny -B20' i.e. 50kHz ISP.
Quote:
-B Specify JTAG/STK500v2 bit clock period (us).
The "-B" option is described to be only for JTAG programmers.
Quote:
> avrdude.exe -F -B 20 -p atmega16 -P USB -c usbtiny -U hfuse:w:0x99:m

avrdude.exe: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.02s

avrdude.exe: Device signature = 0x1e9403
avrdude.exe: reading input file "0x99"
avrdude.exe: writing hfuse (1 bytes):

Writing | ################################################## | 100% 0.01s

avrdude.exe: 1 bytes of hfuse written
avrdude.exe: verifying hfuse memory against 0x99:
avrdude.exe: load data hfuse data from input file 0x99:
avrdude.exe: input file 0x99 contains 1 bytes
avrdude.exe: reading on-chip hfuse data:

Reading | ################################################## | 100% 0.01s

avrdude.exe: verifying ...
avrdude.exe: 1 bytes of hfuse verified

avrdude.exe: safemode: Fuses OK

avrdude.exe done. Thank you.

What threw me is the Avrdude "-B" option documentation is horribly wrong !. And, this still leaves the question as to what the heck is the "-b" option is for since there is no RS232 programming interface.

Thanks for your help.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Is English your first language?

Avrdude can control many different programmers using many protocols.
You use the -B option for 'intelligent' programmers like a STK500, Dragon, AVRISP-2, usbasp, usbtiny, ...

You use the -b option for programmers with a RS232 i/f like an Arduino, STK500, AVRISP-1, ...

Please do not ever use the -F option.
It is like cutting the end off a condom.

There are 'I bricked my AVR' questions every day.

As you can see, the solution is not difficult.

Simply quoting the avrdude command with its response makes it easy to suggest a solution.

If you care to read most of the threads, the OP seldom describes her setup or command. Most of them are determined to do something involving High Voltages.

Anyway, I am pleased that you have got going.
Good Luck!

David.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

-F Override invalid signature check. My reason was simple: I was getting invalid signature checks.

Is English your first language ?

Why do you give suggestions with absolutely no useful explanations ? Do you wish to be like a Brahman distributing tiny nuggets of wisdom only when you feel like it ?

Get off you high horse.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

If you use the -F flag with a write operation, avrdude will perform the write!
Think about it. You can send commands that may be interpreted wrongly by the AVR.

Even a read command could be interpreted as a write command. The fusebits of one AVR model do NOT correspond with another model. I have sent mega32 fuse values to a mega168 before now (using Studio).
Avrdude would have caught the error (providing you did not have -F)

Yes. English is my first language.

I think that I have spent a lot of time and effort trying to assist you.

I have given you practical advice and explanations.

Your replies showed little understanding at all. I admit that I became exasperated with your 00.47 GMT reply.

At that point I decided that I would only respond to posts that showed effort on your part. e.g. quoting some message or showing your 250kHz clock trace.

I am well aware that it is very frustrating when you appear to have 'bricked' an AVR. You may prefer a 'spend $300' advice. You have got going by eventually following the 'spend no money' instructions.

I note your appreciation.

David.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Pascor,

If you start insulting people that are simply trying to offer assistance then you are likely to find your thread(s) being locked.

Moderator.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

*sigh*

-i is for BIT-BANGED programmers only. [ie the ones that use the PC's parallel port, or the RS-232 handshake lines]

-B is for everything else [ie it is an intelligent programmer that has a command protocol over RS-232 or USB] -- Yes the docs are bad with this respect, as they mention the JTAG ICE, this is because this parameter is always required with the JTAG ICE, most other programmers default to the last used speed, so this parameter can be omitted. [unless you wish to change the rate]

Writing code is like having sex.... make one little mistake, and you're supporting it for life.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:
-i is for BIT-BANGED programmers only. [i.e., the ones that use the PC's parallel port, or [just] the RS-232 handshake lines]

-B is for everything else [i.e., it is an intelligent programmer that has a command protocol over RS-232 or USB] -- Yes the docs are bad...


Thanks for sorting this out. Now I understand you mean bit-banged serial data using COM or LPT ports on the PC end, not the circuit end.

Just to be clear, there are 2 clocks involved: The AVR chip clock (XTAL1 pin) and the AVR chip programming data interface (SPI/JTAG/parallel_mode) clock (SCK pin), which functions more like a data enable signal. Specifying "-B 20" causes Avrdude to produce programming data bits 20 usecs apart which is 50 KHz. Since my external system clock runs at 250 KHz (4 usecs), this gives the AVR chip's internal programming state machine 5 state cycles per 1 programming interface data "clock" cycle for the AVR hardware to "do its programming thing".

Also, Avrdude's use of the term "STK500v2" had me puzzled because I'm unfamiliar with the STK500 kit. I assumed it referred to a v2 of the kit hardware rather than a programming protocol.

So, if I understand everything correctly, some of avrdude's command line flags are better described as:

-b Override the host RS232 port baud rate

-B The ISP/JTAG/parallel_mode STK500v2 programming protocol
programming bit clock period specified in microseconds.

-i The bit-banged host interface programming bit clock period specified in microseconds

It's too bad Avrdude didn't use frequencies instead of clock periods for "-B" and "-i" similar to the "F_CPU" parameter in avr-gcc.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Yes. I agree with you 100%.

Have a word with Joerg. Discuss a different selection of commands. Offer help with the documentation.

Public Domain Software benefits from its users.

Since you have had a frustrating experience, you are in a very good position to offer advice.

Likewise, a good Tutorial or Wiki may help others in the same situation. However, I can tell you from bitter experience that a punter in panic mode is reluctant to follow advice.

As you have discovered for yourself, the solution is very simple. You were fortunate in having 'correct wiring' and a 'professionally made programmer'. A simple software command made your AVR better!

Most 'panics' are caused by incorrect wiring. No one can offer realistic advice because they cannot physically see the 'wiring'. The punters are reluctant to get out a pencil and paper checklist.

Bear in mind that 'Studio4', 'stk500.exe', 'avrdragon.exe', 'jtagicemkii.exe' are Atmel programs. They are only designed to run on Windows. If there is a bug, swear at Atmel.

'avr-gcc.exe' or 'avrdude.exe' are volunteer contributed programs. Swear 'politely'. It is more effective!

David.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Actually, no bugs were found, just poor Avrdude documentation. It's a cross-platform program originally written for *nix OS's and has been ported to Windows platforms using the MinGW environment. Its documentation is all too typical of many apps developed for *nix systems. I guess the authors figure that all the users are expected to read the source code to be able to figure out how the application is supposed to work.
--------------------------
Anonymous Chinese saying:
"Give a man a fish and you feed him for a day. Teach a man to fish and you feed him for a lifetime."

I'm not trying to eat a fish. I'm trying to learn how to fish.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I wouldn't say that it is typical of documentation for *nix systems, but rather that it is typical of documentation for open source software. [I'm going to guess that your opinion was based on the fact that your only *nix exposure has been with open/free platforms like Free BSD & Linux]

Writing code is like having sex.... make one little mistake, and you're supporting it for life.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I have no desire to research the history of avrdude.

From a user's point of view it is brilliant. It will run on almost any o.s. and control almost any hardware.

So someone can suggest an explicit command and have confidence that it will behave identically for a user running MAC-OS in Outer Mongolia.

Yes. The documentation could be improved. However, I have always found it accurate. In common with many technical docs, it is worth reading things twice! Just to ensure you have absorbed the information.

Personally, I like the 'Unix manual' style. It enables you to find the information in a consistent way. Yes. The -B entry could be improved.

OTOH, I would suggest that your first port of call is to always google "Usbtiny manual". After all, this is the hardware that you are using!

David.