Debugging with debugWIRE for AVR® MCUs
Overview
debugWIRE provides a single-pin (RESET pin) debugging solution for small pin count AVR® MCUs (e.g., the ATmega48/88/168/328) (PB) family. Many of these devices are used on the popular Arduino development boards.
The ATmega328PB Xplained Mini is used to demonstrate the debugWIRE interface. The interface (ISP or debugWIRE) is set in the Project Properties dialog. MPLAB® X Integrated Development Environment (IDE) sets/clears relevant configuration bits for you.
Software and Hardware Used in This Example
For the best experience, install in the order below:
Creating a Project in the IDE
From the IDE, launch the New Project Wizard (File > New Project).
Follow the screens to create a new project:
Adding a File to the Project
Once a project is created, the Projects window will open.
For this example, no additional code needs to be added to main.c.
Debugging the Project
To set the interface to debugWIRE, open the Project Properties dialog. Under the mEDBG category, Communication options category, select Interface as debugWIRE. Click OK.
Click Debug Main Project to start debug.
During device programming, you may see this warning message:
Configuration memory will not be programmed because no configuration bits settings have been defined in your code. To program configuration memory, either define the settings in your code or use the Program Configuration Bits button on the configuration memory window.
For this example, no configuration bits settings were added to the code and no device configuration bits values were changed. For more on configuration bits, see the "Reading the Configuration Bits" section.
Programming proceeds and once complete, debug mode begins.
You are now in debug mode.
Click Pause to halt execution temporarily or Finish Debugger Session to end the debug session.
Programming the Device
When you are done with debugging your code, you can program the target device.
To set the interface to programming, open the Project Properties dialog. Under the mEDBG category, Communication options category, select Interface as ISP. Click OK.
Reading the Configuration Bits
To set or clear device configuration bits (fuses), use the Configuration Bits window (Window > Target Memory Views > Configuration Bits).
When this window is first opened, all text is red and a pop-up message states that you must read the configuration bits from the device before you can edit.
Click Read Configuration Bits on the window. The read should be successful and show this message in the mEDBF window:
Read complete
Data in the Configuration Bits window will be black and reflect the settings read from the device.
For this example, you have not changed any configuration bits. However, if you did want to change any bit values, you can write the new values to the device by clicking on Program Configuration Bits .
DO NOT edit the value of the SPIEN bit or DWEN bit. MPLAB X IDE will handle interface changes for you (i.e., programming interface to debug interface and vice versa).
If the SPIEN bit is cleared and the DWEN bit is set, you will be able to use debugWIRE but to switch back to SPI you will need to use High Voltage Programming (HVSP/HVPP). No current Microchip tool supports this type of High Voltage Programming.