How to debug atmega328 using JTAG?

Go To Last Post
13 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Is it possible to connect JTAG to atmega328? Does anyone have schematic to share on how to connect JTAG?

If not what is the best way to debug using atmega328?

Last Edited: Fri. Sep 24, 2010 - 04:17 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You can debug a 328 with JTAGICEmkII or Dragon but it won't be using JTAG - it uses the one wire On Chip Debug interface called debugWire. You start using the debugger in ISP mode to set th DWEN fuse (unlike JTAG chips which have the JTAGEN fuse enabled by default the debugWire chips have DWEN disabled by default). Once you have used ISP to switch to dW mod in theory you only need two of the 6 wires in the ISP header but as you need all 6 to get the chip back from dW to ISP mode (you can't change fuses in dW mode) you might as well leave all 6 connected.

Having switched the chip to debugWire you just use Debug-Select Platform and Device to select either JTAGICEmkII or Dragon then when you use "Start Debug" Studio will communicate with the chip in dW mode and download the latest build of the code into its flash then start the debug interface with the PC positioned at 0x0000 (Asm window active) or main() (C window active).

Cliff

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

In AVR Studio, select "AVR Tools Guide" from the Help menu. Then, click on JTAG ICE MkII and read through the help file section describing exactly how to connect to the target.

Don Kinzer
ZBasic Microcontrollers
http://www.zbasic.net

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I want to post a question on in application programming of atmega328 , i know i am posting in the wrong place but could not figure out how to start a new post.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Apparently the "New Discussion" button doesn't appear on some computers.

John Samperi

Ampertronics Pty. Ltd.

www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Also, the  "New Discussion" button doesn't appear anywhere except at the top of the Topic list of a specific forum

 

The fact that this is not easy to find and, therefore, unhelpful to new users has already been documented:  http://www.avrfreaks.net/forum/n...

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Can I use an USBasp programmer to program and/or debug an ATmega328P PCB ?

 

 

<º))))><

I am only one lab accident away from becoming a super villain.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You can program the device, but you cannot debug.

 

Jim

If you want a career with a known path - become an undertaker. Dead people don't sue! - Kartman

Please Read: Code-of-Conduct

Atmel Studio6.2/AS7, DipTrace, Quartus, MPLAB user

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks for getting back to me Jim.

 

If I can pick your brain some more, how do you program the ATmega328p, is that using a JTAG interface ? Is there a download program or is it supported in Studio ?

 

To explain why I know absolutely nothing about these devices/PCBs, I found this equipment hanging around the lab. I wondered if this spare kit was useful to knock up a quick small interface project to help debug the current project. I had a brief hunt through the 328 datasheet, but I didn't see anything about a JTAG. I could have missed it and I need to make some more time to sit down and actually RTFM ! Has it come to that, who would have ever thought ?

 

It maybe that these ICs already have the bootloader, they are marked 'P' - is that for Pre-Programmed ?

 

All the best

 

Dren

 

 

<º))))><

I am only one lab accident away from becoming a super villain.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Is this a wind-up? You have 361 posts here and I can remember that you were previously a quite active user here.

 

Anyway assuming it is a genuine question the fact is that the On Chip Debug interface in a mega328 (and all AVRs with 28 or fewer pins) is debugWire not JTAG. It achieves the same thing (in theory) but uses a one-wire communication on the _RESET pin so does not require the other 4 pins to be tied up like JTAG does.

 

The Atmel devices that can do JTAG debugging: JTAGICEmkII, JTAGICE3, Dragon, AVR-One!, Atmel-ICE can all do debugWire as well. So if you own one of those you can debug the 328. These devices are all supported for both programming and debugging from within Atmel Studio.

 

The P on the end of 328P means "Picopower" - simply that it is a 328 but with additional facilites to reduce energy consumption when operated from a battery. Apart from some USB models no Atmel AVRs come with a bootloader pre-programmed.

 

(having said that the 328P is also the chip used at the heart of most Arduino boards and many chip suppliers will preprogram "Optiboot" (the Arduino bootloader) into the chips and sell them as "bootloader ready". There's unlikely to be any external markings on the chip to signify that this has been done though).

 

I still think you are trolling though - in which case I guess I just wasted my time.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hello Clawson,

 

great to hear from you after all this time, thanks for replying, no I am not trolling, no wind-up, I've been away for years using all sorts of other kit/devices. I forget or get confused between devices after a while, maybe I am getting old ? TBH I do think it's well time I retired ! It's a juggling act, how much money do you need, how long will it take to earn it, how many years do you have left to spend it, what about the family etc ? Well according to my other half, no I cannot retire yet and we DO definitely need a new Range Rover.... for the dogs ! 

 

I have always used JTAG to program AtMELs before, even the ATtiny24v, or maybe my memory is going about that too ?

 

Theres' a stack of credit card sized 328 PCBs in the lab, that were bought for another project that was abandoned. I want to use them to control the interface in my current project, rumour has it that they already have a bootloader installed. There is also a USBasp programmer with them, no idea if that would work using 'debugwire' - I'll give it a go early next week

 

All the best

Dren

<º))))><

I am only one lab accident away from becoming a super villain.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Dren wrote:
I forget or get confused between devices after a while, maybe I am getting old ?

Worn that T-shirt! :-)

Dren wrote:
even the ATtiny24v, or maybe my memory is going about that too ?

It is. That one has debugWire in fact.

Dren wrote:
Theres' a stack of credit card sized 328 PCBs in the lab, that were bought for another project that was abandoned. I want to use them to control the interface in my current project, rumour has it that they already have a bootloader installed. There is also a USBasp programmer with them, no idea if that would work using 'debugwire' - I'll give it a go early next week

Fraid a USBAsp is only an ISP programmer - no chance of doing debug with that. As I say to debug a 328 you need one of JTAGICEmkII, JTAGICE3, Dragon, AVR-One!, Atmel-ICE. If you don't have one to hand the latest and greatest is the $50 Atmel-ICE that supercedes everything else. As to whether the chips already have a bootloader - I suppose you could apply power+clock and see if you can make them "talk" but without know the bootloader protocol it would be a complete stab in the dark trying to guess what variant they want to talk and the speed and so on. But as you have USBAsp anyway you might as well just ISP code into them. In fact I suppose you could ISP a known 328 bootloader code into them if you then wanted to ditch the USBAsp and switch to using a bootloading mechanism instead.