AVR/Arduino Hardware Debugger on the Cheap (revisited)
2/17/2018 Update: I've removed the code links at the bottom of this page except for the link to the DebugWireTest, as new code is now available. For the latest code, see my most recent article AVR/Arduino Hardware Debugger on the Cheap (part 3)
This page presents updated information and code for my project "AVR/Arduino Hardware Debugger on the Cheap". Since publishing that article (and its companion video), I've made several improvements and enhancements to the code. However, if you're interested in using my new code, you should still review my original article, as there is a lot of information there which I will not repeat here.
New Features and Changes
I've revised and renamed my original Arduino sketch to reflect its new capability. The new sketch, which you can download below, is now named DebugWireDebuggerProgrammer because it now includes the ISP programming abilities of the ArduinoISP sketch. This means you can use my new code to both upload code to a target device as well as debug code running on it. Note: if you have not done so already you'll need to also download and install my OnePinSerial library and the DebugWireTest sketch for ATTiny85 (both also available below, or on my original page.) I'm also working on a demo video that will show all the steps you need to follow to compile code for the ATTiny85 (or some other target) and then upload it. You can subscribe to my YouTube Channel of you to want to be notified when I release a new video.
Because the ArduinoISP sketch requires you to install a 10uF capacitor from the Arduino's RESET line to Ground in order to use it, you'll need to use a modified version of the test circuit to both program and debug code. This circuit (shown below) adds a SPDT switch that let's you toggle between Program (upload) mode and Debug mode:
Click for Larger View
Click for Larger View
When the switch is in the "Program" position, you can compile and upload code to the ATTiny85 (or other target device) and, when in the Debug position, you can open the Arduino IDE's "Serial Monitor" window (set to 115200 baud) to invoke the debugger. Note: in addition to connecting the 10 uFd capacitor to the Arduino's RESET line when switched to Program mode, pin D8 is used to detect the setting of the switch and change the baud rate to/from 115200 for Debug mode or 19200 for Program mode.
Important: as mentioned in my original article, you cannot use Program mode as long as the DWEN fuse is enabled and you'll be unable to debug code when it is not enabled. However, you can use a special feature in Debug mode to flip this fuse back and forth, as needed:
If DWEN Fuse is enabled and you want to Upload new code, follow these steps:
Put switch in Debug position
Open the Serial Monitor (sketch will display menu of commands)
Type 'B' and press Send to engage the Debugger
Type "EXIT" and press Send to exit the Debugger (this puts the target in a mode where you can change fuse settings)
Type '-' (Minus symbol) and press Send to disable the DWEN Fuse
Type 'F" and press Send to verify DWEN fuse is disabled
Move switch to "Program" position (good idea to also press the RESET button on the Arduino)
Verify the Arduino IDE is configured properly to compile and upload to your target device
Compile and upload your code
If DWEN Fuse is not enabled and you want to Debug your code, follow these steps:
Put switch in Debug position
Open the Serial Monitor (sketch will display menu of commands)
Type '+' (Plus symbol) and press Send to enable the DWEN Fuse
Type 'B' and press Send to engage the Debugger
If DWEN Fuse is already enabled and you want to debug some more, follow these steps:
Put switch in Debug position
Open the Serial Monitor (sketch will display menu of commands)
Type 'B' and press Send to engage the Debugger
Stay Tuned!
I'm still making improvements to the DebugWireDebuggerProgrammer sketch, so stay tuned for future develops by subscribing to my YouTube channel, or checking here at "Wayne's Tinkering Page" from time to time. Some of things that are hopefully coming in the near future, are:
A simple PCB you'll be able to order from OSH park and use to build a Mini Arduino "Programming and Debugging" Shield for ATTiiny25/45/85 chips as well as a an ISP connector you can use to program and debug other target devices that support the debugWire™ interface. This will be an all "thru hole" design, so anyone with reasonable soldering skills should be able to build for a total cost of around $15, or less, depending on what parts you might already have lying around.
New features that will make in-circuit debugging easier and more powerful.
Tips on how to use my debugger to solve some common problems you may encounter when writing code for embedded systems.
Some interesting, ATTiny85-based projects you might want to build and experiment with.
A new and improved AVR High Voltage Fuse Reset circuit you can use to recover accidentally "bricked" AVR devices.
Update - For the latest code, see my most recent article AVR/Arduino Hardware Debugger on the Cheap (part 3)