Using JTD Bit

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

Could someone please help me with using the JTD bit to disable JTAG and be able to use all of the PORTC pins as general purpose I/O during run-time use on the ATMega644?

I have tried all of the following so far:


#define SetBit(x,bit) ((x) |= (1<<bit))
#define ClrBit(x,bit) ((x) &= ~(1<<bit))

        // Attempt 1
	SetBit(MCUCR,JTD);
	SetBit(MCUCR,JTD);

        // Attempt 2
	SetBit(MCUCR,JTD);
	ClrBit(MCUCR,JTD);
	SetBit(MCUCR,JTD);

        // Attempt 3
	SetBit(MCUCR,JTD);
	DDRC = 0xff;
	SetBit(MCUCR,JTD);

        // Attempt 4
	SetBit(MCUCR,7);
	SetBit(MCUCR,7);
	SetBit(MCUCR,7);
	SetBit(MCUCR,7);

etc...

No matter what I seem to do following the ATMega644 documentation, I still cannot get my JTAG pins on PORTC to function properly. I have disabled OCDEN, but left JTAGEN enabled. For some reason, AVRStudio continues to be able to debug regardless... I disconnect my JTAG cable from my board and the results are the same. Just wondering if there was something I was overlooking?

Thanks,
James

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0
   SetBit(MCUCR,JTD); 
   SetBit(MCUCR,JTD); 

This is correct, however you have to ensure that the second line gets executed within 4 clock cycles of the first. With optimization on, each line should reduce to a single opcode (sbi MCUCR, 1<<JTD). Without optimization the code will be considerably longer and be outside the timing requirements. If you want to be absolutely sure that the timing requirements are met, you could use inline assembly. And it is possible that your compiler has a macro defined for it already.

Regards,
Steve A.

The Board helps those that help themselves.

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

That was it!!!! Thank you very much!!! I turned on optimization and it worked fine....

Thank you!!!
James

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

One more question...

Now I'm having problems with AVRStudio consistently letting me program the ATm644 with my JTAG ICE MkII, I'm assuming because of setting the JTD bit in software. When I get the error message that no device was detected... sometimes AVRStudio will ask if I want to force a JTD reset (or something like that) and when I click "yes" it will go through and start programming. Other times, however, it never offers that message... just keeps telling me that no device was found. And right now I'm stuck with it only giving me that message and nothing else. Is there any way to force it to do the JTD clear when it attempts to connect?

Thanks,
James

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

I've found that behavior rather erratic also. You can force it to use the /RESET line either by manually grounding the target's /RESET line, or:

1) Open your project's ELF file in AVRStudio, select JTAG as platform
2) Tick the checkbox to open the JTAG's options screen before attempting programming of the device
3) Check the box for forcing the target reset, press OK

That'll reprogram the target with your wanted HEX file, although you'll then be in debug mode. It's a painful process but one that will be guaranteed to work.

- Dean :twisted:

Make Atmel Studio better with my free extensions. Open source and feedback welcome!

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

Thank you very much Dean!!! I'm just happy to know there's a procedure other than clicking "re-try" 50 times until it finally decides to ask if you'd like to do a target reset, etc...

Thank you,
James