Inserting a breakpoint and checking the result of data exchanged between 2 uC's tend to interfere with the timings and other factors. Is there a way wherein i can sniff all the data exchanged between 2 uC's and store them to a log file that can be later interpreted maybe using python.

Even if it means using a #define to Enable and disable logging in code is fine. I just dont want to use breakpoints and verify the results.

  • \$\begingroup\$ Do you have any unused pins to toggle say for a Comm error code? Busy flag? \$\endgroup\$ – Tony Stewart Sunnyskyguy EE75 Apr 12 '18 at 3:24
  • \$\begingroup\$ State analyzer on a unused external port is often a necessary DFT requirement. \$\endgroup\$ – Tony Stewart Sunnyskyguy EE75 Apr 12 '18 at 3:30
  • \$\begingroup\$ Maybe the pins used for Flashing the code? \$\endgroup\$ – AkshayImmanuelD Apr 12 '18 at 4:28
  • 1
    \$\begingroup\$ IMO creating a communication sniffer is a broad question. A practical solution is to buy one. \$\endgroup\$ – Dmitry Grigoryev Apr 12 '18 at 7:48
  • \$\begingroup\$ It is smarter to include process/test vectors to a spare port for field tests but an LA is also an essential tool \$\endgroup\$ – Tony Stewart Sunnyskyguy EE75 Apr 12 '18 at 22:36
  • Use two serial port adaptor RX channels (ftdi usb adaptors), one for each direction. Realterm has a Monitor mode where it will take the RX from two different ports and interleave it on screen in different colors. You will want a recent version. If you have an old school 2/4port serial adaptor (not usb) it will work better in terms of not messing up the timing between the two channels. If it is all fairly slow, no problems. Realterm can also put timestamps into the data if useful.

  • Use an oscilloscope or logic analyser. Some can decode the data for you

  • use a single serial port and OR the two directions together. Only works if they don't talk at the same time, and you can make some sense of what is going back and forth.
  • Make a special adaptor from a micro with two uarts. Send each byte of the incoming data out as two bytes, using a bit to identify which rx it came from. [you can have 1 bit for channel, 1 for B7 of data,6 for a timestamp, or monitor a couple of pins]. Using ftdi usb adaptor, you can output at 3MB, which would allow 150kBd on the rx channels (in total). This method would also make it possible to handle 9 bit protocols too. Arduino Mega would be perfect for this as it has 4 uarts and usb already on board

I have 4 proposals that I think are the easiest solutions. 2 have been already proposed by Henry, but I complete them a bit.

Logic Analyzer

There are some of them that connect directly to your PC via USB, so you see the measured signal directly in your PC. A software in the PC decode some protocols such as UART, I2C, SPI... so it present to you the data sent in a more human readable way, not only the electric signal. I haven't tried many of them, but I bough a very cheap (around 10€) clone of Saleae Logic Analizer that lets you to use original software from Saleae, which is great and free.

FTDI adaptor attached to an uC

Ftdi have adaptors UART to USB, I2C to USB, SPI to USB...choose the one you need. The computer recognizes it as a virtual serial port, so it is very easy to read and write, even from your SO console, no need of writing complicated code for PC (either Win, Linux, Mac...)

FTDI website is not very intuitive to browse their catalogue. Better you google what you need (for example "FTDI USB to SPI").

One possible usage is attaching it to one of the uC's if it have an unused communication peripheral (and pins). For example, if communication between uC's is I2C, and one of them have a free UART port, buy a UART to USB adaptor. Then in the program of that uC, you send all data sent and received via i2c to the uart, so your PC also receive it. This is more or less the same that Henry proposed.

FTDI adaptor attached to the same communication bus than uC's

Other possible usage is attaching the adaptor directly to the paths that connect both uC's. This way, you don't need to have free pins, nor adding any code to uC program.

In this case, you must be careful of not disturbing the communication with the adaptor, not sending any data from the PC.

If communication between uC's is done with a bus topology communication, such as I2C or SPI, you can use just one adaptor to read messages from both uC's. If communication between uC's is done via UART, you will need 2 adaptors.

Create log in memory and pause execution a bit later

If the amount of data you want to analyze is not too big, because not many data is exchanged or because you only need to analize a small amount of time, you can create big buffers in the memory of the uC's and store there the received data. Don't use breakpoints to pause execution always any data is received, just let the program run for the time you want (5 seconds, for example). Then, pause execution with the debugger and inspect the content of the buffer.

Depending on the IDE you are using, sometimes you can export the data for easier inspection to excel, for example (I used to do this with Microchip MPLAB X)

You can do this depending on how much free memory do you have in the uC's and in the amount of data you need to record.


Not the answer you're looking for? Browse other questions tagged or ask your own question.