ATmega dual pin function JTAG and analog input

adcatmegaatmeljtag

I need measure temperature to adjust ticks as temperature changes. I suppose thermistor nearby crystal (10ppm) as low cost solution. I'm using AT90USBxxx but I have allocated PF0-3 for more important analog signals. So I need reuse pins shared with JTAG interface and I need debugging option enabled when thermometer is disabled. Thermistor is not capacitive load hence I can connect circuit behind serial resistor as explained in AVR042 app note.

schematic

simulate this circuit – Schematic created using CircuitLab

When starting I can adjust JDT bit of MCUCR register.

But is somehow possible to detect if JTAG cable is plugged in?

I don't think so. As workaround is possible to modify bootloader or implement a custom JTAG on/off parameter stored in EEPROM.

What JTAG pin (TCK, TDO, TMS, TDI) is preferred or does not matter?

Any ideas or objections against proposed solution?

Reference: http://blog.lse.epita.fr/articles/61-dealing-with-the-pull-up-resistors-on-avr.html (but they do not want to support JTAG)

Best Answer

I made meanwhile full testing and can answer myself.

Instead of thermistor I'm using MCP9700 active thermistor connected behind 4k7 resistor.

When JTAG is enabled then really all PF4-7 have pull-up resistors (even cable is disconnected) but JTAG communication is not affected by thermistor. ADC probably is working but probes JTAG TTL signals. Seems software JTAG detection is too complicated to get it working reliably.

Thermistor may be connected to any PF4-7 pin. I'm using TMS/PF5.

When JDT is applied ADC can measure temperature. Just I must not forget to remove also JTAG cable.