Q – What is JTAG ??
A- (from wikipedia)
Joint Test Action Group (JTAG) is the common name for what was later standardized as the IEEE 1149.1 Standard Test Access Port and Boundary-Scan Architecture. It was initially devised for testing printed circuit boards using boundary scan and is still widely used for this application.
Today JTAG is also widely used for IC debug ports. In the embedded processor market, essentially all modern processors support JTAG when they have enough pins. Embedded systems development relies on debuggers talking to chips with JTAG to perform operations like single stepping and breakpointing. Digital electronics products such as cell phones or awireless access point generally have no other debug or test interfaces.
With reference to AVR (Atmega16) MCUs
JTAG interface shares PC2, PC3, PC4 and PC5 of ATmega16.
To use these four pins for general I/O operations, JTAG must be disabled.
There are three methods for disabling JTAG:
1. By programming via software (temporary)
2. Using Avrdude
3. Programming Fusebits (permanent)
1. Programming method:
There is a register in atmega16 MCUCSR (MCU control and status register). It consists of JTD (JTAG disable) bit as 7th bit of register.
JTAG can be disabled by writing 1 to this bit. (note this has t be written as soon as main() starts)
This command must be written twice withing 4 clock cycles to disable JTAG.
This is a temporary method of JTAG disabling because using this method, it is required to write the above command in every program.
sample code: (note this has t be written as soon as main() starts)
_delay_ms(10); // this is optional and must be introduced for instability problems if any arises
2. Using Avrdude:
JTAG can be permanently disabled by configuring two fuse bits, OCDEN and JTAGEN (must be disabled).
This is done by using Avrdude software. The following instruction should be followed carefully to disable the JTAG
1. Connect your microcontroller burner circuit to your system.
2. Go start>run and write “cmd”.
3. Write command “avrdude –p <microcontroller code> –c <programmer type> -t” in Command window
Commands -p to select microcontroller
-c to select programmer type
-t to enter in AVRDUDE’s interactive window.
Microcontroller code m8 for ATmega8
m16 for ATmega16
m32 for Atmega32
Programmer types are bsd for parallel port programmer (Brain Dean’s programmer)
usbasp for USB programmer (USBasp)
The following picture shows the output of above command.
4. Write command “d lfuse” and “d hfuse” at avrdude interactive window to get values of low Fuse byte and high fuse byte.
5. As shown in above picture the value of Fuse bytes is 0x89FF. This value shows that JTAG port of the microcontroller is enabled. To disable JTAG, the value of fuse bytes must be 0xC9FF.
6. To write 0xC9 in higher fuse byte the command “w hfuse 0 0xc9” is written. Lower byte will remain same.
7. Write “d hfuse” command again to make it confirm that value is written or not.
8. For terminating this window by type “quit”.
By this operation JTAG will be disabled and PORTC will work as normal I/O port.
3. Using FuseBits Programming:
The best way according to me is by programming the fuse bits
But beware inexperienced users – you may brick your MCU by improper fusebits programming
here is a nice fusebits calculator
This works for me: disable JTAG – low_fuse=0xd4 high_fuse=0xd9
I personally use the following tools:
SinaProg (click the Advanced option near the Oscillator select button)
AVRLoader (RoboSapiens’s proprietary programming tool has a GUI based jtag disabling system)