How to use a second Uno as a debugging device

I have made a posting (link below) which describes how you can use SPI to output debugging messages from a processor "under test" to a second one which simply echoes the messages to a serial port.

This is particularly useful if you are debugging serial messages, because it can be tricky to connect up a serial device for two-way communication, and also do debugging prints at the same time.

To make this work you only need to connect 5 wires from one Uno (or similar) to the other.

This technique could also be useful for testing or debugging "bare bones" processors which don't have a built-in serial or USB connection to your PC.

Nice one Nick.

I did something similar a while back

http://arduino.cc/forum/index.php/topic,54005.0.html

I used the WD interrupt on the target system (the server) and had a fairly comprehensive monitor program running on the second Arduino (the client). It allowed memory dumps, IO read/write etc as per a normal monitor.


Rob

Thanks, Rob!

I updated the post to show how you could do it with I2C as well.

I just read your post. Looks really comprehensive. :slight_smile:

This is the thing that troubles me about the forum, a lot of good ideas just disappear unless you know what to search for.

Yeah, I haven't done any more on this but it could be a useful tool I reckon. Maybe I'll get back onto it one day :), truth is I haven't done much software since (been designing hardware) so I haven't had the incentive to finish it off.


Rob

This is the thing that troubles me about the forum,

Could post to an appropriate section, and make it sticky.
Though I'm not exactly sure what the appropriate section would be.
Maybe a new section over at the Playground for debug techniques?

Are you using the I2C port + 2nd Uno as the equivalent of a second serial port? 'Cos this is also doable with the (New)SoftSerial library, and for one-way data flow only occupies one DIO pin.

Absolutely. There are quite a few ways of doing it. Using software serial is a viable approach under many circumstances. However the software serial does tend, I believe, to be rather CPU intensive as it relies on software rather than hardware. Also serial comms in general tends to be slower than I2C or SPI.

It depends a lot on what pins (if any) you have free for debugging. If your main project uses SPI, then you might need to use serial, software serial, or I2C for debugging messages. Or if the main project uses I2C then SPI might work for you.

Another debugging approach is to just turn a pin on or off (eg. to a LED) if timing is critical.

What I like about the SPI approach is that it has a minimal impact on the program execution (as clocking out SPI is quite fast).

Hmm. You have a "new" version of the Uno-SMD !

With mine I used bit-banged SPI, that has a pretty small footprint and of course can use any pins but does need 3 pins as it was a two-way link.

As it was all running in the WD ISR the main program didn't even know this was going on, and IIRC it used about 1% of processor time.

At a simpler level I always try to have 2 free pins that can be toggled and seen with a logic analyser.


Rob

Hi Rob,

I posted to your other thread, but am not sure that you still monitor it, so at risk of being wrapped over the knuckles for cross posting I will repeat it here :slight_smile:

I installed and tested the code that Nick Gammon posted (Thanks Nick) and was interested to try the additional features that you have implemented.
I am using two MEGA2560 boards and have connected them via the SPI pins (50 - 53).
Nicks' Code is working fine, so I am reasonably confident that my cabling is correct, but when I run your code the serial monitor reports:

QUUBmon v1.0
Compiled for
  Server: ATmega2560
  Client: ATmega2560
on Sep  2 2011

QM> Server offline.
QM> bad frame

I have confirmed that both Server and Client have the settings:

//#define RUNNING_ON_328
#define RUNNING_ON_2560

and have confirmed that the pins defined for SPI are 50 - 53.

Any suggestions of where I should start looking to debug it?

Cheers
Chris

Hi caroper, I answered on the other thread.


Rob

Here's the other thread

http://arduino.cc/forum/index.php/topic,54005.15.html

I think that *r problem was fixed, I'll post the last code version there.


Rob