I have a Leonardo that is programmed to send data at 115200 baud via serial to a desktop app (written in C++). Most of the time it works fine, however occasionally it gets into a very strange state. The actual program only sends data every 100 ms so in normal operation the tx light flashes and the rx light is off.
Occasionally the tx and sometimes rx lights will become solid as if it is sending lots of data, but my desktop program never receives any. Nor does putty or the Arduino serial monitor. Very strangely, resetting the Arduino does nothing but sometimes simply opening the Arduino serial monitor (which also resets the Arduino) fixes it. I have even a few times had it so that the tx and rx lights are on solid even though no serial program is open on my computer! Surely that should be impossible? At other times the tx and rx lights never come on at all, even though I'm 95% sure my program is sending data.
I should note that this behaviour is stochastic.
Does anyone have any idea what could be causing this weirdness? I suspect maybe it is some issue with buffering or something? Is there a way to check the state of the tx buffer on the Arduino?