Unreliable serial communications with Leonardo.

Hi,

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?

Does anyone have any idea what could be causing this weirdness?

I have this vague idea that it might be your code. Or, it might be your hardware. But, since you've posted no code, and not described what else is connected to the Arduino, we may never know.

Apologies, I actually have an Uno! That makes slightly more sense, but I'm still not sure how it can be sending and receiving when no host serial app is running...

I have the same problem (I think) with arduino mega and no one knows how to fix it.

http://forum.arduino.cc/index.php?topic=164594.0

Timmmm: 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?

The Tx and Rx LEDs actually represent USB activity, rather than async serial activity. So it would not be too surprising if the state didn't always exactly match the async serial activity.

I've noticed on my UNO that the Tx LED will come on and stay on after a while if the sketch sends data over the serial port while there is no application on the PC reading from it. My guess is that the PC does some buffering of the virtual serial port and then invokes some form of flow control when the buffer is full and this is what triggers the LED states.

Timmmm: I have a Leonardo

Timmmm: Apologies, I actually have an Uno!

Make your mind up! They have very different USB/serial behaviour.

Do you have anything connected to the Rx or Tx pins?

I don't have anything connected to pins 1 or 2. Somebody else suggested that it might be interference from the 2A stepper motor I am using... I am going to try lowering the baud rate a bit and shielding the stepper wires to see if that helps.