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.