
JTAG Debugging: Online Debugging of Microcontrollers and PLCs
Hello everyone, I am “Da Yi Zong”. Today, I will talk about a commonly used debugging tool in microcontroller and PLC program development—JTAG debugging interface.
JTAG stands for Joint Test Action Group, which is an industrial standard interface used for chip-level testing and debugging. Simply put, it can be understood as a “black line” that allows you to view the internal operating state of the chip and perform read and write operations on the internal memory of the chip.
The functions of the JTAG interface:
- Online Debugging: You can view the status of variables, memory, registers, etc., during runtime without repeatedly burning the program to the chip. It’s like “implanting a listening device” into the microcontroller.
- Online Programming: Programs can be directly downloaded to the chip’s memory via JTAG, without the need for a programmer.
- Chip Testing: JTAG can scan and detect if the chip is faulty.
Hardware part:
Both microcontrollers and PLCs have reserved JTAG pins, usually ranging from 4 to 10. As long as these pins are connected to the debugger, you can enter debugging mode. Common debuggers include:
JTAG Debugger
The two JTAG debuggers shown in the image can serve various microcontrollers and PLCs. The one on the left is a debugger that comes with the integrated development environment, while the one on the right is a general-purpose J-Link debugger.
Software part:
- Microcontrollers typically use the built-in debugging function of the official IDE.
- For microcontrollers lacking debugging functions, third-party tools like J-Link are needed to read and write memory.
- PLCs generally use the monitoring window provided by ladder diagram software for debugging.
Practical experience:
- I once caused chip damage by short-circuit measuring with a multimeter. Later, I learned to use JTAG for inspection and found abnormal internal registers.
- JTAG can not only detect hardware issues but also diagnose software problems such as infinite loops.
- Some cheap development boards do not have JTAG pins soldered, and you may need to solder them yourself. If that doesn’t work, consider using simulation debugging.
Debugging tips:
- Observation Code: Determine the program execution path by observing changes in variables.
- Breakpoints: Set breakpoints on critical code to check on-site data.
- Step Execution: Execute step by step, especially suitable for observing the countdown process of timers.
Precautions:
- The power supply voltages of PLCs and microcontrollers differ, and using an inappropriate JTAG debugger may damage the device being debugged.
- For production equipment, it is prohibited to dynamically write code and parameters on-site, and thorough testing should be done in a debugging environment first.
- During JTAG debugging, the CPU runs slower, making it unsuitable for applications with strict timing requirements.
If you have learned JTAG debugging, you will be good at code debugging and hardware testing. However, beginners should avoid making random changes on the production site to prevent issues. In the next issue, I will continue to share other debugging tips for microcontrollers and PLCs, so stay tuned!
Practical exercises:
- Check if your development board or PLC supports JTAG debugging. What model of debugger is needed?
- Research how to use debugging software to set breakpoints, step execution, and observe variables.