I tried these lines but none works
MCUCSR = 0x80;
MCUCSR |= (1<<7);
I tried these lines but none works
MCUCSR = 0x80;
MCUCSR |= (1<<7);
The datasheet tells you that you have to write to the JTD bit *twice* within four clock cycles as a safety for the disabling to come into effect:
register volatile uint8_t MD asm("r24") = (MCUCR | (1 << JTD)); // Forces compiler to use IN, OR plus two OUTs rather than two lots of IN/AND/OUTs MCUCR = MD; // Turn on JTAG via code MCUCR = MD;
- Dean :twisted:
Hammer111,
Not sure why you made the second one an OR with existing contents. That may require a read-modify-write which violates the 4 cycle rule. Just:
MCUCSR = 0x80; MCUCSR = 0x80;
should be sufficient but ONLY if you have optimisation turned on. It will not work with -O0 (just one of the many reasons not to use -O0!). Rather sadly AVR Studio defaults GCC projects to -O0.
Cliff
Optimization for chip? How can I turn it on, I looked datasheet and searched for optimisation but no results found :(
Do I have to set some register(which one) for optimisation)?
I assume your post in the GCC forum means you are programmingin avr-gcc? If so then if using Studio go to "configuration options" on the "project" menu and set it there. If using an Mfile generated Makefile it should already contain "OPT = s" but you might want to just verify that.
Cliff
yeah I do program avrgcc and I make hex file and upload it by ponyprog
Yes but what do you use for a Makefile system (in other words what invokes the compiler?)
Build and ReBuild all generates me a hex file
So you are using STUDIO to build?!? In that case the optimisation setting is almost definitely wrong (it'll be set to -O0) and therefore you must follow my advice above to use Project/Config options and change it to -Os
Cliff
Optimization for chip? How can I turn it on, I looked datasheet and searched for optimisation but no results found :(Do I have to set some register(which one) for optimisation)?
With optimization turned on, the compiler will typically generate MUCH smaller, faster code than is possible without optimization turned on.
For example, in this case, with optimization turned off, the compiler will never take advantage of the smaller, faster I/O register manipulation instructions. It will always access all I/O registers through their data memory-mapped equivalent locations. So it's not likely to be able to satisfy the 4 clock cycle timing limitation of programming the JTD bit.
It works than you clawson, you are the man :)
Thank you lfmorrison for explanation it's more clear now what it is :) :)
Got it working.
Thanks