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:
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. 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). GeneralSchematic below:
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. 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).
How to build – step by stepFirst 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 1First 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:
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
Step 2We 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). ChooseTools and AVR Prog menu:
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: Click Short testTo 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: 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 A window should appear with list of programming devices, we choose JTAG ICE and port number to which our interface is connected: If everything works properly a window should appear: 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 Jtag with bascom.Links
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||


