Hi all,
I´m trying to develop an aplication where the arduino Due is continuously working (always powered), and I can connect to it using the native USB, so I can get data about the process. If the native USB is unplugged while sending data, the serialUSB communication gets crazy when plugged again. The data sent via USB isn´t sent in the same order it should.
I have tried to reset the object SerialUSB using the provided functions SerialUSB.end() and SerialUSB.begin(..), but when connected again the messages are wrong.
I wrote a simple code to try to understand what was wrong.
long tm;
uint32_t ct=0;
void setup()
{
SerialUSB.begin(115200);
tm=millis();
while(!SerialUSB)
;
}
void loop()
{
if(millis()-tm>10 && SerialUSB)
{
tm=millis();
SerialUSB.print("Va");
SerialUSB.print("lue");
SerialUSB.print(":");
SerialUSB.print(ct);
SerialUSB.println("");
ct++;
}
}
At the begining, when powered on the board the messages are received correctly.
Value:2
Value:3
Value:4
Value:5
Value:6
Value:7
Value:8
Value:9
Value:10
If unplugged the USB while sending data, and then connected again, the data is sent in different order. When unplugged, the board keeps powered with the other, so it´s not restarted, because I need that the board keeps working although the native USB is not connected.
The received data becomes like this one
2290lueVa2291:Va
:lue
2292lueVa2293:Va
:lue
2294lueVa2295:Va
:lue
2296lueVa2297:Va
:lue
2298lueVa2299:Va
:lue
2300lueVa2301:Va
:lue
2302lueVa2303:Va
:lue
The difference in the count is correct, it´s because the program keeps running.
It keeps sending data in this way until the board is reseted or power off/on.
Any idea about what´s happening with the communication or how could it be solved without reseting the board will be apreciated.
Thanks.