Arduino Forum

Using Arduino => Programming Questions => Topic started by: Watcher on Jan 14, 2016, 07:00 am

Title: Reccomendation: Troubleshootig techinque
Post by: Watcher on Jan 14, 2016, 07:00 am
Hi all,

My project based on Arduino micro, receives hex commands from an RS485 link through the hardware serial port Serial1 and then sends hex strings to a software serial port talking to an external RS232 device.

No feedback from the external RS232 device is needed.

Both received and sent strings are also echoed on the (USB) Serial port for monitoring.

Although it generally works fine, it occasionally seems to be stuck somewhere and spends a considerable amount of time (1-2s) apparently doing nothing or maybe waiting for something. This results in what appears to be intermittent operation.

I know of course I am supposed to post the actual code, but that would be too big and I frankly couldn't see anybody actually trying to go through it easily.

My question is if there was a way to pinpoint where the program is stuck during these times by adding some code for troubleshooting.

Thanks for your help.
Title: Re: Reccomendation: Troubleshootig techinque
Post by: MorganS on Jan 14, 2016, 07:02 am
If you've decided that you need help from the forum then a productive technique is to strip down your program to the smallest possible program which shows the error. Either you get to a small program you can post here or your mistake becomes obvious to you.
Title: Re: Reccomendation: Troubleshootig techinque
Post by: ElusivePi on Jan 14, 2016, 07:49 am
My project based on Arduino micro, receives hex commands from an RS485 link through the hardware serial port Serial1 and then sends hex strings to a software serial port talking to an external RS232 device.

Both received and sent strings are also echoed on the (USB) Serial port for monitoring.

Although it generally works fine, it occasionally seems to be stuck somewhere and spends a considerable amount of time (1-2s) apparently doing nothing or maybe waiting for something. This results in what appears to be intermittent operation.

...

My question is if there was a way to pinpoint where the program is stuck during these times by adding some code for troubleshooting.
Your uC receives, processes, and sends hex commands. Add 3 LEDs and have each light up at each different stages of the routine: turn the first LED on when it it's begun receiving, the next on when it begins processing, and the final LED on when it beings sending, and all off after it's finished sending.

If it stalls, then you'll know which stage of the routine to look at.
Title: Re: Reccomendation: Troubleshootig techinque
Post by: Watcher on Jan 14, 2016, 09:44 am
Quote
Your uC receives, processes, and sends hex commands. Add 3 LEDs and have each light up at each different stages of the routine: turn the first LED on when it it's begun receiving, the next on when it begins processing, and the final LED on when it beings sending, and all off after it's finished sending.

If it stalls, then you'll know which stage of the routine to look at.
Thanks for the tip!

I thought of inserting serial.println statements to have flags appearing on the serial terminal at various steps but I ended up with a screen full of flags which was useless. The led approach you propose might be far better!