Homebuilt underwater robot

 

JTAG for AVR processors

This article provides information about JTAG interface and describes how to create simple JTAG interface. This interface is original design of Aquaticus ROV team.

The interface is compatible with every software that supports JTAG ICE, it works perfectly with AVR Studio and Linux tools. You can program the AVR chip using JTAG interface, but you can not consider this interface as replacement for AVR ISP or any other AVR programmer.

List of supported Atmel micro controllers:
  • AT90CAN128
  • ATmega128
  • ATmega16
  • ATmega162
  • ATmega169
  • ATmega32
  • ATmega323
  • ATmega64
The above list is the same for all JTAG ICE clones.

Once Atmel published schematics of their JTAG interface for AVR processors (JTAG ICE II), you just had to develop PCB board and program it, but... original Atmel AVR JTAG interface is quite complicated – contains antistatic protection, support for wide range of voltages on target device, contains advanced power supply, etc. For amateur purposes it can be simplified which allow it to fit on a quite small PCB board.

JTAG interface: Home designed JTAG interface for AVR chips.JTAG interface: Home designed JTAG interface for AVR chips.

At the end you can find all files needed to create your own PCB.

What's JTAG and how it works?

Simply JTAG interface allows you to look inside a processor and see what's going on there - read registers, alter memory, etc. You can read more about on Wikipedia JTAG article. Atmel AVR JTAG contains some extensions to original JTAG which allows it to program internal memories (FLASH, EEPROM).
Communication between PC computer and AVR JTAG (also called JTAG ICE) is realized using RS232. Communication between AVR JTAG and target device uses 10 wire cable (there are less than 10 active signals). Below figure explains it: Block diagram: JTAG communicationBlock diagram: JTAG communication

General

Schematic below:

Schematic of JTAG interface for AVRSchematic of JTAG interface for AVR

Everything is taken care by ATMega16, originally, in Atmel's application note, there was a different processor, which is actually discontinued, ATMega16 is a 100% replacement for it. You can see also MAX232, which converts voltage levels from TTL to RS232 (PC) standard. Mind that you can use MAX3232, that way your interface will work with lower voltages - 3.3V - additionally some capacitors would have to be exchanged to other values (C3, C4, C5, C6) and C5 connected to ground (not VCC). Mind that there are few versions of MAX3232, capacitor values and connections may differ across different producers (consult datasheet). If you do a 3.3V version don't forget about proper ATMega16 version (see ATMega16 documentation). The rest consist of resistors, capacitors and 2 LEDs. There's one jumper which will be described later on; normally pins 2 and 3 should be short circuited.
The interface can be powered from external 5V supply or from AVR JTAG connector.

Please note that you can not replace ATmega16 with ATmega32 chip. Original Atmel firmware have to be modified (interrupt table) to work with ATmega32. This task can be automatized using special bootloader. You can read JTAG ICE Clone for ATMEGA32 thread on AVRFreaks for more info. As ATmega32 is electrically compatible with ATmega16, you can use PCB with ATmeg32 without any modification, but you must download modified software for ATmega32.

Below AVR JTAG connector pinout - it connects AVR JTAG interface and the target device (2x5 pins, IDC10, 10 wires). JTAG connectorJTAG connector

AVR JTAG connector
Pin Name In/Out Details
1 TCK Output Test Clock, clock signal from JTAG ICE to target device
2 GND - Ground
3 TDO Input Test Data Output, data signal from target device to JTAG ICE
4 VTREF Input Voltage level of target device
5 TMS Output Test Mode Select, mode select signal from JTAG ICE to target device
6 NSRST Input/Output Open collector output from JTAG ICE to target device, it is also used as input to detect resets on target device
7 VSUPP Input Power supply for JTAG ICE. This line is cut off when external power supply is attached (see schematics)
8 NTRST Input/NC Not connected, reserved for other JTAG devices (JTAG interface reset)
9 TDI Output Test Data Input, data signal from JTAG ICE to target device
10 GND Ground

How to build – step by step

First you have to make a PCB board (all downloadable things are at the end of article), solder everything. PCB board is 100×46mm in size. It's good to place ATMega16 and RS232 in socket. Be sure that there aren't any shortcuts and elements have proper values. IC2 has to be MAX232A (with A at the end), that way 0.1μF capacitors can be used; you can use normal MAX232, but remember to use proper capacitor values (greater). In case of a mistake rather nothing bad should happen, because there's nothing to break. There's a simple protection against improper power supply polarization - D1 diode.

Now it's time to program ATMega16 - it's done in two stages:

Step 1

First stage it to program the microcontroller with bootloader (download attached file avrboot.hex), which will, later on, be used to load JTAG program into microcontroller. More about bootloader beneath the table. You must also remember about correct configuration of fuse bits and lock bits (these should not be programmed). To flash a bootloader you need a programmer for Atmel AVR processors, here you can find simple programmer which can be assembled in no time (PonyProg): schematics, I used PonyProg to do the programming. Below a picture which bits need to be programmed and a table with more details: Fuse bits settings in PonyProgFuse bits settings in PonyProg

Fuse bits settings - details
Name Value Details
OCDEN 1 Turn off On Chip Debug, if on CPU may use more current in sleep modes, because some clock distribution subsystem are constantly powered
JTAGEN 1 JTAG not used here
SPIEN 0 A must be during SPI programming (you can't set it to 1 (not programmed) in SPI programming mode)
CKOPT 1 This value is due to use of 7,3728 MHz crystal, see ATMega16 doc
EESAVE 1 EEPROM content doesn't have to be preserved between programming - it can be turned off (1)
BOOTSZ1 0 Bootloader size set to 1024 words, ie. 2048 bytes (see documentation for details)
BOOTSZ0 0 Bootloader size set to 1024 words, ie. 2048 bytes (see documentation for details)
BOOTRST 0 After reset jump to bootloader.
BODLEVEL 1 Brown Out Detector level - detection of power failure - not used here - turned off (1)
BODEN 1 Brown Out Detector level - detection of power failure - not used here - turned off (1)
SUT1 1 Start Up Time - set to 65 ms (it doesn't actually matters here)
SUT0 1 Start Up Time - set to 65 ms (it doesn't actually matters here)
CKSEL3 1 This value is due to use of 7,3728 MHz crystal
CKSEL2 1 This value is due to use of 7,3728 MHz crystal
CKSEL1 1 This value is due to use of 7,3728 MHz crystal
CKSEL0 1 This value is due to use of 7,3728 MHz crystal

Bootloader is compliant with avrboot protocol, I compiled it using this project. It works this way: after you power up the processor program flow jumps to special area called bootloader. Bootloader prepares microcontroller to receive control commands and data through serial port (RS232, 19200, 8N1), this way we can send flash ATMega16 using serial port, it's easy and good solution. A disadventage is that you loose some FLASH space for bootloader (in most cases this can be omitted). Important: JP1 jumper must be short-circuited in position 1-2, this way CPU jumps to bootloader, else (2-3 position) normal code (not bootloader) is executed. You can check communication with bootloader with simple terminal connected do serial port, try to send S character or V character. Below you can see the effect, white background means sent character:

Terminal connected to avrboot deviceTerminal connected to avrboot device

Step 2

We have bootloader programmed, remember about jumper (position 1-2). Now we have to load JTAG control program. We start AVRStudio. Examples below are from version 4.0, similar should be with version 3.5. Important: there may be problems with installation of AVRStudio 4.0 using Win XP SP2 (problem is well known, it's about setup program). Choose Tools and AVR Prog menu: Running AVR prog from AVR StudioRunning AVR prog from AVR Studio

AVR Prog window should appear. Remember that JTAG interface should be turned on and connected with computer with serial cable and jumper set in position 1-2, else there will be a message informing that no (avrboot) interface was detected. Note that AVRProg do not recognize serial ports other than COM1 and COM2, so be sure to use one of these ports. This is AVR Prog window, it will show up when everything is OK: AVR prog windowAVR prog window

Click Browse and locate file upgrade.ebn, in standard installation it is located here: C:\Program Files\Atmel\AVR Tools\JTAGICE\Upgrade.ebn. This file contains ciphered version of JTAG ICE control program - AVRStudio takes care of everything, it thinks that our interface is the original one. Click Program (in section Flash). Ready. At the end place jumper in position 2-3 so that bootloader will no longer be invoked.

Short test

To test this interface I build simple device with only ATMega16 (it has JTAG interface, for example ATMega8 doesn't). When you buy a new processor it has the JTAGEN fuse bit programmed, to be sure I programmed it once again along with OCEN bit (this stage may not be necessary). Here's the schematic of the test device: Schematic of test deviceSchematic of test device

We connect signals TCK, TDO, TMS, TDI with appropriate CPU pins, connect VCC to VTREF and optionally NSRST with CPU reset. If you do not power interface externally, connect 5V to VSUPP pin! We connect test circuit with JTAG interface with 10 wire cable. My first JTAG interface almost worked instantly - I only forgot to connect VTREF signal, after correction AVR Studio stopped nagging that the power supply is not connected. And here's how to check the interface: choose Tools -> Program AVR -> Connect: JTAG test step 1: Choose appropriate menu itemJTAG test step 1: Choose appropriate menu item

A window should appear with list of programming devices, we choose JTAG ICE and port number to which our interface is connected: JTAG test step 2: Select JTAG ICEJTAG test step 2: Select JTAG ICE

If everything works properly a window should appear: JTAG test step 3: Ready to work.JTAG test step 3: Ready to work.

One thing that doesn't work the way it supposed to is proper measurement of VTREF voltage, it should be 5V, but the program detects 6.2V. It doesn't affect the proper functionality of JTAG device. Original Atmel JTAG could change voltage levels to work with 3.3V and 5V microcontrollers. This JTAG works with only one voltage level, so voltage divider responsible for proper measurement was not implemented.

The interface was successfully tested under Linux using programs: avarice and avr-insight

To see how to use JTAG interface with BASCOM see "Using jtag with bascom program".

Links

AttachmentSize
avrboot.hex3.88 KB
atmel_avr_jtag.pdf85.53 KB
avrjtag_board.pdf49.09 KB
avrjtag_elem.pdf67.01 KB
avrjtag_all.pdf126.91 KB
eagle_project_jtag.zip66.35 KB
avrjtag_schematic.pdf36.73 KB

Submitted by Anonymous on Fri, 2009-02-06 08:27.

I use AVRStudio 4.13 SP2 build 571.
Some problem i can handle, like Update the STK500DLL.dll with new one.
Now I can use the AVRJTAG to download program.
But tell me how to debug of target?
Cause when i start debug, AVRStudi give mess "Could not connect to JTAG ICE".
What happen?
Thanks.

Submitted by Anonymous on Sun, 2009-03-08 13:29.

Make sure the "Programmer" window i closed. The window keeps the COM-port reserved. Hth.
Peter

Submitted by Anonymous on Fri, 2009-02-06 06:13.

How to debugging with JTAGICE?
Cause when i start debug, AVRStudio give warning "Could not connect to JTAG ICE".
Thanks.

Submitted by Anonymous on Wed, 2009-02-04 12:08.

My JTAGICE Clone can't read the fuses bit of the target.
What wrong?
i think my target is dead, but when i try with new one. Problem is still same.
I can read target signature, HW info and other except fuses bit.
Help me please.
Thanks.

Submitted by admin on Wed, 2009-02-04 12:20.

AVRStudio 4.13 SP2 has a bug resulting fuse bits can't be correctly read.
Download AVR Studio 4.13 SP2 JTAGICE Fix from http://www.atmel.no/beta_ware/
or upgrade you AVRStudio to the latest version.

Submitted by Anonymous on Wed, 2009-02-04 16:30.

I cannot find it, just find AVRSudio 4.14 and 4.15 and other. Which one must i download?
Thanks

Submitted by admin on Wed, 2009-02-04 16:33.

use google

Submitted by Anonymous on Wed, 2009-02-04 17:02.

My JTAGICE now can read fuse bit.
http://www.avrportal.com/?page=download&file=files/stk500Dll.zip
download and unzip.
Replace stk500Dll.dll in C:\Program Files\Atmel\AVR Tools\STK500 with new one.
Just share, maybe someone have problem like me.
Thanks very much.

Submitted by Anonymous on Wed, 2009-02-04 04:02.

My AVRJTAG now is work. But when read fuse bit of target, there mess if JTAG target error and can't read fuse bit. Signature, Lockbit, HW setting and HW info is OK (can read).
Would you give me full schematic between AVRJTAG and the target.
Thanks.

Submitted by Anonymous on Tue, 2009-02-03 10:04.

Im use AVRStudio 4.13 SP2, it can upgrade the JTAG?
Cause if i Choose "Tools" and "AVR Prog" menu:
The device is no ATmega16 BOOT, But ATmega163.
Until now, my JTAG not work.
Thanks

Submitted by admin on Tue, 2009-02-03 10:33.

It seems avrstudio does not recognize your board. Have you program mega16 with bootloader? If so, check your PCB, connection and stuff like that

Submitted by Anonymous on Tue, 2009-02-03 10:48.

I Have program mega16 with bootloader. respon is ok when i try with hyperterminal. what wrong?

Submitted by admin on Tue, 2009-02-03 10:55.

try to use com1 or com2. avrprog do not recognize other ports.

Submitted by Anonymous on Tue, 2009-02-03 11:03.

Yes i tried with com2, use usb2serial. Cause my laptop dont have COM serial. its a problem?
Oh, when i upgrade mega16. AVRstudio give warning about verify is error in address 0x0000.

Submitted by admin on Tue, 2009-02-03 11:11.

us2com is ok.
0x0000 means avrstudio can't communicate with jtag.
It seems your hardware is ok, but for some reason avrstudio can not get connected with jtag. I remember such message but don't remember how to skip it.
I guess you should play with avrstudio- sometimes it works in a strange way.

Submitted by Anonymous on Sun, 2009-01-18 21:23.

Dear All,
I am trying to make JTAG and facing problem whlile using it. I am using stk500 and not AVRISP. Is it necessay to use ISP instead on stk500. if not could any one help me out to give solution for making JTAG with stk500

Regards,
Sid

Submitted by admin on Sun, 2009-01-18 21:49.

STK500 has no JTAG connector. You can not use ISP connector.
You can use JTAG if you connect JTAG lines to the chip, e.g. using connector like this one:
http://www.ecrostech.com/AtmelAvr/AvrIceCube/Stk500.htm

Submitted by Anonymous on Mon, 2009-01-19 08:16.

Hi, I m trying to design JTAG using ur description. The first step is to download the boot.hex . I have connected the stk500 to serial port and using it with the ISP 6 pin connector . And placed the blank IC ATMEGA16 into the IC base. As said by u , I m using Pony Prog 2000 set the fuses . IT is not detecting the device .
Also for Upgrade.ebn Which interfacing device can i used ,ISP,STK500 or some other. I have no ISP. Can i replace it by using the STK500 in ISP mode
Plz help me out. and give me the detail description.

Thankx
Best regds
Sidh

Submitted by admin on Wed, 2009-01-21 01:15.

You can use STK500 to program boot.hex as you described. I have no idea why Pony Prog does not detect device. You can try any other programmer if you like, fuse bits are described in the table.
When you program boot.hex you can move atmega16 to JTAG PCB and follow the instruction.

Submitted by Anonymous on Fri, 2009-01-09 20:55.

Hi!
I have built a JTAG clone two years ago, using this article as reference.I redesigned the PCB, added an AVR ISP compatibile programmer to the board.The JTAG is fast enough to use with avr-gcc compiler, so I'm pretty satisfied with it!
Thank You for the detailed description,
cheers
Levykk

Submitted by admin on Fri, 2009-01-09 22:48.

Good to hear it was useful you.

Submitted by Anonymous on Sun, 2008-12-14 08:52.

hi
i need to make this jtag ice clone for atmega32
is this board ok for atmega32?
help me with changes that i shud make in thez steps
thanx

Submitted by admin on Sun, 2008-12-14 16:00.

You can use PCB with mega32. But the software needs to be modified, as original Atmel soft works only with meg16.
Read avrfreaks discussion mentioned in the article to find more details.

Submitted by Anonymous on Sun, 2008-12-07 11:44.

Hi,
First of all, thanks for making the circuit schematics of the JTAG board available!

I prepared the circuit as shown in your site and proceeded to program the atmega16 with the avrboot.hex file. But before that I wanted to program the fuse bits.

But when I programmed the fuse bits as shown as in the ponyprog screenshot, my ponyprog refuses to recognize it and refuses to program it.

Can you please help ? Are the fuse bit settings correct? I did notice a discrepancy between the screenshot and the detailed description. As per the detailed description, OCDEN and JTAGEN should be left unprogrammed(set to 1) but in the screen shot, both are check marked (set to 0). Which one is correct , the screenshot or the description ?

regards,
Seemanta

Submitted by admin on Sun, 2008-12-07 23:48.

Detailed description is OK. Ignore screenshoot.

Submitted by Anonymous on Mon, 2008-12-08 07:28.

My earlier problem is solved now by adding an 8Mhz crystal to the ponyprog hardware.

Can you please include a note in your page saying that setting these fuse bits may not cause ponyprog to work unless an external crystal is added to the PonyProg hardware? Because newcomers like me may not realize this until they set the fuse bits and then see that the micro does not respond to ponyprog.

But now, I am facing another error. I am not able to flash the upgrade.ebn file using avrprog from within AVR Studio. I get a 'Programming Failed' error. Can you please help if you have faced a similar issue before ?
I am however able to get proper response from the board to the S and V command in HyperTerminal after loading the bootloader.

regards,
Seemanta

Submitted by admin on Tue, 2008-12-09 16:32.

Hard to say, be sure you COM port is 1 or 2. AVR Studio got problems using other ports.

Submitted by Anonymous on Tue, 2008-12-09 23:11.

It was an ungrounded capacitor in pin 6 of the MAX232. I went with a manual inspection of the circuit, connection by connection. I am using a pre-drilled general purpose PCB and did not 'fabricate' one.

Million thanks in making this available for people like us to get started with JTAG on AVR!!

regards,
Seemanta

Submitted by Anonymous on Tue, 2008-12-09 23:19.

One more question, may I use the JTAG communication block diagram in my blog with your permission, of course?

Submitted by admin on Wed, 2008-12-10 00:12.

sure