I am trying to disable the JTAG port on an ATmega2560 using C code in WinAVR. I have read the documentation which says the JTD bit must be set twice within four clock cycles. I tried the obvious:
MCUCR = (1 << JTD); MCUCR = (1 << JTD);
which didn't work so I then tried the next obvious thing of setting it more than twice:
MCUCR = (1 << JTD); MCUCR = (1 << JTD); MCUCR = (1 << JTD); MCUCR = (1 << JTD);
which didn't work either. One of the other forum posts said the bit shift may be consuming clock cycles so I tried:
MCUCR = 0x80; MCUCR = 0x80;
as well as:
MCUCR = 0x80; MCUCR = 0x80; MCUCR = 0x80; MCUCR = 0x80;
which didn't work either. Someone mentioned that it may have to do with compiler optimizations.
I believe the right way to address it would be to use inline assembly statements. I read the documentation and I'm not exactly sure how to use the asm function.
I tried the following:
asm volatile ("sbi 0x0E,2;");
as a sample and KNOW that it sets bit 2 on PORTE. When I try:
asm volatile ("sbi 0x35,7;");
which is what I believe logically needs to be done, I get the error message "number must be than 32" (for the register).
Can anyone provide the proper syntax on how to set the JTD bit using inline asm code?