Go Down

Topic: Arduino ATmega2560 And AVR ONE! [resolved ] (Read 6 times) previous topic - next topic


Mar 13, 2012, 07:21 am Last Edit: Mar 26, 2012, 03:05 am by Mozart Reason: 1
I have an Arduino with an ATmega2560 MC on it.  I was using the Arduino IDE 1.0 but moved on to AVR Studio v5.1.  Recently I found and purchased a new AVR ONE! on the cheap and am having some difficulty using it on the Arduino Mega 2560 board.  According to the AVR ONE! documentation and the Atmel datasheet for the 2560 they should work together, however, I am having a heck of a time figuring out how. I have done the following:

*) Use the AVR ONE as an ISP interface to upload programs successfully.  
*) Performred the self test on the AVR ONE! and it works fine.

However, while I have the ISP interface active I set the JTAGEN fuse to make the JTAG active and while that works fine as well, when I change the interface to JTAG and try to read the Device ID I receive the following error:

"Unable to enter programming mode. Please verify that the programmer is correctly attached to the target and that target power has been switched on. Also verify that the correct device and interface settings have been specified.

Timestamp:   2012-03-13 01:12:08.812
Severity:      ERROR
ComponentId:   20100
StatusCode:   0

Programming session setup failed: TCF command: Device:startSession failed:  Code:1 ,Service:Device ,Message from peer:setEmulatorMode failed:
An unknown emulator error occured."

I may be making a bad assumption here and that is, that the ICSP header is the JTAG interface.  Can someone confirm this for me?

It is not entirely clear as to how to connect the AVR ONE! to the Arduino board.

Thanks for any help you can provide!!


The ICSP header is NOT the JTAG header.  You'll have to pick the JTAG signals off of additional pins.

The JTAG pins are shared with the a-d converter, so they should be reasonably accessible


In case anyone does a search on this I wanted to post the solution I found as it might be helpful:

What westfw said is absolutely correct (by the way thank you much for pointing this out to me!).  A reply to my post on another website indicated the following:

For the ATmega2560:
There are 7 pins that need to be connected
   *)  TDI  - JTAG9 - Pin 90 - PF7 ( ADC7/PCINT15 ) - Analog pin 7
   *)  TDO - JTAG3 - Pin 91 - PF6 ( ADC6/PCINT14 ) - Analog pin 6
   *)  TMS - JTAG5 - Pin 92 - PF5 ( ADC5/TMS ) - Analog pin 5
   *)  TCK - JTAG1 - Pin 93 - PF4 ( ADC4/TMK ) - Analog pin 4
   *)  GND - JTAG2, JTAG10 - Pin 11,32, 62, 81, or 99
   *)  VCC - JTAG4 - Pin 10, 31, 61, or 80

I did not connect - JTAG 6,7, and 8

Since the AVR ONE! comes with an adapter cable I did not have to create one.  The adapter cable has a 10 pin male header on it and 10 multicolored wires so that the pins can be identified easily.

So that was the answer to the first question, but after that I ran into another wall and will put that question in the next post.


Mar 18, 2012, 11:11 pm Last Edit: Mar 19, 2012, 03:55 am by Mozart Reason: 1
Now I have the connections configured between the AVR ONE! and the Arduino ATmega2560.  The configuration hasn't changed (same as earlier posts) and I am able to view the fuses, lock bits and upload programs to the 2560 with JTAG, AVR ONE! and the AVR studio.  However, when I set break points in my source within the AVR Studio and run the IDE in debug mode the program doesn't stop and I am unable to watch the variables I have defined.
*)  I have tried to debug at breakpoints and trace points with the OCDEN fuse on and with it off.
*)  After I run the program in debug mode and then check the OCDEN fuse it has been turned off (set high).
*)  Lock Bits are all set to "NO_LOCK" which should allow me to set the OCDEN fuse.
*)  I have also tried compiling with all optimizations off.

Is there something I may be missing here?

Again, thanks for any help you can provide.


Mar 18, 2012, 11:14 pm Last Edit: Mar 18, 2012, 11:18 pm by westfw Reason: 1
check the OCDEN fuse it has been turned off (set low).

Note that for most of the fuses, "set low" (0) is "on."
Other than that, I have no ideas.  I am following your experiments with JTAG debugging of Arduino with significant interest, though...


Thanks westfw!  I fixed my mistake.  For some reason I associate Low = 0 = Off.


I think I have a handle on this now and thought I would share should anyone ever experience this little bit of frustration I have just worked through. I created a second post (because I think I exceeded the message limits here) to include the JTAG header pinout table for the AVR ONE! along with a table describing what pins on the Arduino/ATmega2560 get connected to what pins on the JTAG header.


AVR ONE! JTAG Debug Fuse Settings

  • If using  AVR Studio the OCDEN fuse will be enabled automatically each time a debug session is started and will be disabled when the debug session is ended.  That being said I did go into AVR programming with the AVRISP mkII and set the OCDEN to be enabled to be sure the settings where default initialized before starting.  Since then I haven't touched OCDEN.

  • The JTAGEN fuse must be enabled.

  • The BOOTRST fuse must be enabled.

AVR Studio 5.1 Project Settings

  • Follow the documented tutorial for including Arduino source code to the AVR Studio environment.  Something to note, however, is that Atmel has appeared to have fixed the need to re-locate the "-Wl,-lcore  -Wl,-lm" within the makefile so there is no longer a need to use an external makefile.

  • Although I believe it is possible to compile and run both C and C++ projects I was only able to set break points and watch variables (i.e. debug)  AVR/GNU C projects.

  • I don't know if this is a defect or not, however, when I compiled and tried to debug the blink example I was unable to set breakpoints or even use the "Start Debugging and Break (Alt+F5)" option within the studio.  Once I commented out the Arduino delay(nMillis) function I was able to set breakpoints and stepping functions again.

  • There is a warning directive defined in Atmel's delay.h file indicating that if the compiler optimizations are turned off then the use of their delay_ms(nMillis) function will not work as designed which makes perfect sense.

  • When I use Atmel's _delay_us(nMillis) inline function defined in their delay.h file I am able to set breakpoints and debug as usual.

  • Finally be sure to turn OFF all Compiler Optimizations.  This was both a good thing and a bad thing because as stated:

    • Bad Thing = if Optimizations = Off then some functions (in my case delay(nMillis) will cause the debugger to never stop, and never hit breakpoints.

    • Good Thing = Opened my eyes to what Atmel has included and they seem to have addressed (at least) this specific issue in their delay.h file via inlining.

***Please let me know if you spot anything that appears to be incorrect so I can keep this updated with accurate info.  I would like to "keep it real" for anyone looking to this forum for answers.


Mar 26, 2012, 03:03 am Last Edit: Aug 26, 2012, 09:11 pm by Mozart Reason: 1
This post is a continuation of my previous one and includes a table representation of the AVR ONE! JTAG pinout and a table describing which pins get connected from the AVR ONE! to the ATmega2560/Arduino.

JTAG Header Pinout

Pin #PinName PinName Pin #

JTAG Pin Description

Name Pin# AVR ONE! ATmega2560 Arduino
Test Clock (clock signal from the AVR ONE! into the target device)Pin 93 - PF4 ( ADC4/TMK )(A4) Analog pin 4
Test Mode Select (control signal from the AVR ONE! into the target device)PF5 ( ADC5/TMS )(A5) Analog pin 5
Test Data In (data transmitted from the AVR ONE into the target device)PF7 ( ADC7/PCINT15 ) (A7) Analog pin 7
Test Data Out (data transmitted from the target device into the AVR ONE!)PF6 ( ADC6/PCINT14 ) (A6) Analog pin 6
Test Reset (optional, only on some AVR devices). Used to reset the JTAG TAP controller
Source Reset (optional) Used to reset the target device. Connecting this pin is recommended since it allows the AVR ONE! to hold the target device in a reset state, which can be essential to debugging in certain scenarios.Pin 30RESET
Target voltage reference. The AVR ONE! samples the target voltage on this pin in order to power the level converters correctly. The AVR ONE! draws less than 1mA from this pin.Pins 10, 31, 61, or 100VCC
Ground. Both must be connected to ensure that the AVR ONE! and the target device share the same ground reference.Pins 11,32, 62, 101, or 99GND

***Please let me know if you spot anything that appears to be incorrect so I can keep this updated with accurate info.  I would like to "keep it real" for anyone looking to this forum for answers.

Edit 08/26/2012 corrected pin spec for nTRST (optional Test Reset) per hemmerling' observation


Correction of a typing mistake:

nTRST = JTAG line 8 ( not 10 )

With my Arduino Mega ADK, and JTAGICE3, it was necessary configure my system for ISP communications ( with the help of the adapter supplied with JTAGICE3, and by AVR Studio 5.1, "Tools / Programming" to enable the JTAGEN fuse bit ( the BOOTRST fuse bit was already  set )- I was told so in a AVRFreaks forum thread :-).

Then the instructions of the one-before posting in this thread helped me to configure my system for JTAG communications, after correcting the wiring mistake: I am now able to read the fuse bits by JTAG.

for complete instructions.

Indeed, this thread was very helpful for me :-).

In the one-before posting, VTRef = JTAG line 4 is connected to VCC.
Should I connect this line on the Arduino Mega to
- 5 Volts
- or Vin ( which might be 9 Volts, as this is said to be the voltage of the power supply, if I power the board not by USB but by an external power supply  ) ?

I understand to use analog inputs for data coming from the debugger. So if you name "Analog pin 4" I suppose that you mean the "Analog in A4" pin at the lower edge of the device in the photo, right ?

But with "TDO,3, Test Data Out (data transmitted from the target device into the AVR ONE!)" an analog input is used for output of analog (?) data. So may we really use "Analog in A7" for that ? And how does that work ? Or is this "just for JTAG" and Analog-out no standard feature of ATmega boards ?

The ATxmega, however, indeed has DAC on board, btw, as explained in many examples.

SCADA Expertness - Quality Intensification for IT + Automation

Go Up