Arduino As An AVR Debugger

When you leave the safety of the Arduino development environment and move to development with Atmel AVR processors, without an IDE, you lose some debugging / printing capabilities.  However, there is a simple technique to recover some functionality. This is not a replacement for real debugging tools, but rather a quick fix for simple print capability. I develop in an OS X environment with Emacs as my editor, avr-gcc as my compiler, and avrdude to download the compiled code to the AVR processor via an AVRISP mark II device.

Now the simple hack. You take an Arduino and make it a slave SPI device that simply reads data off of the SPI bus, when it is selected, and uses the Arduino’s Serial.print() capability to print the data over the USB port to the Arduino console. The following code performs this function.

You now setup the AVR microcontroller to be an SPI master and create print functions that meet your needs.  A simple function that prints a single byte or character is included below.  It simply selects the debug device, sends a byte of data over the SPI bus, and deselects the debug device.  When the Arduino receives the byte of data it is displayed on the Arduino console, our new debug window.

This function can now be used to create additional functions such as printStr(), etc.  As I said, a simple hack to solve a simple problem.

Leave a Reply

Your email address will not be published. Required fields are marked *