MPLAB® X IDE - 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 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:

  1. Choose Project: Select Microchip Embedded, and then select Standalone Project.
  2. Select Device: Select the ATmega328PB device.
  3. Select Header: None.
  4. Select Tool: Select the ATmega328PB Xplained Mini. Under Microchip Kits>ATmega328PB Xplained Mini (EDBG) find mEDBG and select "SN: ATML…".
  5. Select Plugin Board: None.
  6. Select Compiler: Select XC8 (v2.05) [bin location].
  7. Select Project Name and Folder: Name the project, such as 328PB_Debugging.
  8. Click Finish when done.

Adding a File to the Project

Once a project is created, the Projects window will open.

  1. Right-click on Source Files and select New>Other. Then choose Microchip Embedded>XC8 Compiler>avr-main.c.
  2. Change the default name to from avr-main.com to main.c.
  3. Click Finish when done.

For this example, no additional code needs to be added to main.c.

Debugging the Project

1

To set the interface to debugWIRE, open the Project Properties dialog. Under the mEDBG category, Communication options category, select Interface as debugWIRE. Click OK.

CommModeSelection_debugWIRE.png

2

Click Debug Main Project DebugProjectIcon.png 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.

3

You are now in debug mode.

Click Pause PauseIcon.png to halt execution temporarily or Finish Debugger Session FinishDebuggerSessionIcon.png to end the debug session.

Programming the Device

When you are done with debugging your code, you can program the target device.

PIC® MCU Developers: A debug executive is not necessary for debugging with AVR MCUs. Therefore, programming for debug does not require different code.

1

To set the interface to programming, open the Project Properties dialog. Under the mEDBG category, Communication options category, select Interface as ISP. Click OK.

CommModeSelection_ISP.png

2

Click Make and Program Device MakeAndProgramDeviceIcon.png.

Reading the Configuration Bits

To set or clear device configuration bits (fuses), use the Configuration Bits window (Window>Target Memory Views>Configuration Bits).

1

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.

AVRConfigBitsMustReadMsg.png

2

Click Read Configuration Bits ConfigBitsReadIcon.png 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.

3

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 ProgramConfigBitsIcon.png.

It is recommended that you 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).

See Also

For more information on debugWIRE, see:

© 2024 Microchip Technology, Inc.
Notice: ARM and Cortex are the registered trademarks of ARM Limited in the EU and other countries.
Information contained on this site regarding device applications and the like is provided only for your convenience and may be superseded by updates. It is your responsibility to ensure that your application meets with your specifications. MICROCHIP MAKES NO REPRESENTATIONS OR WARRANTIES OF ANY KIND WHETHER EXPRESS OR IMPLIED, WRITTEN OR ORAL, STATUTORY OR OTHERWISE, RELATED TO THE INFORMATION, INCLUDING BUT NOT LIMITED TO ITS CONDITION, QUALITY, PERFORMANCE, MERCHANTABILITY OR FITNESS FOR PURPOSE. Microchip disclaims all liability arising from this information and its use. Use of Microchip devices in life support and/or safety applications is entirely at the buyer's risk, and the buyer agrees to defend, indemnify and hold harmless Microchip from any and all damages, claims, suits, or expenses resulting from such use. No licenses are conveyed, implicitly or otherwise, under any Microchip intellectual property rights.