Electronics, Computers, at leisure time

Main menu

JTAG adapter for Arduino Micro

For the holiday season I get myself an AVR JTAGICE3. Holding the new shiny emulator and a bunch of Arduino boards, what shall I do? Of course to hop onto the all-hail Atmel Studio and ditch the toy-alike Arduino software. Reason being? Debugging Arduino code with serial console is no fun. I need my single steps, breakpoints and watches back. In fact the Arduino boards seems to be more valuable (to me) without the software. The onboard ISP connector seems to be standard and it “just works” with JTAGICE3. Well, I had this “just works” impression until I tried it on the new Arduino Micro board…

Make the story straight. The Atmel ISP connector combines SPI bus and RESET signal. SPI is used for downloading program, and RESET implements Atmel’s “debugWire” on-chip debug system. debugWire OCD is a very fancy protocol that uses only one RESET pin to debug. ATmega328p supports debugWire, and hence the ISP connector on Arduino UNO can be used for debugging. Arduino Micro uses a newer ATmega32U4 chip. Surprisingly debugWire is missing from the product datasheet, instead JTAG is listed. JTAG uses 4 I/O pins, from Arduino Micro schematic we can see the JTAG pins (TDI/TDO/TMS/TCK) are multiplexed with analog pin A0-A3. It appears I have to sacrifice these analog pins for the JTAG interface.

JTAG pins on Arduino Micro

JTAGICE3 comes with a 10-pin JTAG header, with the definition as follows:

JTAGICE3 JTAG Pinout

All I need to do is to make an adapter connecting these pins:

JTAG on Arduino Micro

The actual construction is done on a perf board. I made it Arduino “Shield” type so they can be simply stacked together.

Arduino Micro JTAG Shield

I admit it looks quite dangerous when stacked up 😮

JTAG connected

I hook up JTAGICE3 and choose JTAG interface in Atmel Studio. And no surprise. Murphy gets me everytime! “[ERROR] No JTAG devices detected.” is the only reply I get. I Scratch my head several hours then to realize how stupid I were. Since the pins PF4-PF7 have been used as analog inputs for Arduino, how can JTAG establish connection with these pins! And the resolution is simple: connect using ISP header and enable the JTAGEN fuse bit. Now I feel the usefulness of ISP connector.

Enable JTAGEN Fuse

I can finally talk to ATmega32U4 using JTAG and do some debugging. The coming year will be interesting 🙂

It is also easy to make plug-in JTAG pigtail connection to Arduino 2560. And I have read that the GCC compiler can produce debug information for Studio. But I am a hardware guy and don’t know how to make the Arduino compiler produce C debugging file for Studio. In fact I don’t even know where to go in Arduino environment to change the compiler command line. Is it easy to explain this?