Software serial hangs if not connected on Electron?

Hi!

I have connected external devices to Serial4 and Serial5 of the Electron and when there is incoming data on the interface, the code below runs just fine. However, when the other device is not connected, after a few iterations the whole process just hangs. (The number of iterations is always changing, I don’t know what does it depend on).

Am I doing something wrong or is this a bug in the firmware? Is there an other way to know if the serial link is connected? Since I only need to receive data, I only connected GND and RX.

Suggestions are greatly appreciated.

excerpt:

do
    {
        while ( 
                (Serial5.available() > 0) 
              )
            {
            incomingText ="";
            bool lineBreak = false;
            do {
                int inByte = Serial5.read();
                inByte == 13 ? lineBreak = true : lineBreak = false; 
                if (inByte != -1 && inByte != 10 ) {
                    incomingText = incomingText + char(inByte);
                }
            } while (!lineBreak);
            doStuff();
            }   
        }
    } while ((millis() - startProcessingTime) < 0.25*60*1000 );

I guess the problem is your while(!lineBreak) which hasn’t got a timeout.
Given the (with floating pins quite likely) chance that you once in a while enter while(Serial5.available > 0) you will rather unlikely be able to drop back out again - unless you are lucky to get a “floating” CR.

2 Likes

Thanks for the quick response. I’ll try when I get access to my Particle again (it is deployed on a boat :smile: )

Let us know if you can get it fixed @ltamas