If the serialusb unplugged, Due can't respond at another serial.

Hi all,

Arduino Due
Serial0 — LoRa networking
Serial3 — Ethernet networking

If I send a signal to Serial0,
I get some response signals.
And this output shows to SerialUSB and Serial3 together.

Then, when the SerialUSB unplugged, the response does not come.
(The transmission message goes well.)
However, if the SeiralUSB cable is reconnected,
It also get response signals to SerialUSB and Serial3 well.

I really don’t know why.

#include <DueTimer.h>

const byte numCharsLoRa = 200;    
char receivedLoRa[numCharsLoRa];
void setup() {
  Serial.begin(115200, SERIAL_8N1);    // LoRa
  SerialUSB.begin(115200, SERIAL_8N1);   // Monitoring
  Timer0.attachInterrupt(COUNT_1S).start(5000000);
}

void loop() {
 
  recvWithEndMarker();

}
void COUNT_1S(){
  Serial.print("AT_CH");
  Serial.write('\n');
  Serial3.print("AT_CH");  
}
void recvWithEndMarker() {
 static byte ndx = 0;
 char endMarker = '\n';
 char rc;
 if (Serial.available()>0) {
  rc = Serial.read();
  SerialUSB.print((char)rc);
 }     
}
void COUNT_1S(){
  Serial.print("AT_CH");
  Serial.write('\n');
  Serial3.print("AT_CH"); 
}

Bad idea to do serial communication in an interrupt.

And this output shows to SerialUSB and Serial3 together.

Not with the posted code!

Then, when the SerialUSB unplugged, the response does not come. (The transmission message goes well.)

How do you know that the transmission succeeded?

Thank you for your reply

sorry, I forget this code, but result is same.

If USB unplug, I can check from the ethernet(Serial3) port

void recvWithEndMarker() {
 static byte ndx = 0;
 char endMarker = '\n';
 char rc;
 if (Serial.available()>0) {
  rc = Serial.read();
  SerialUSB.print((char)rc);
  Serial3.print((char)rc);             <--- new code
 }     
}

If don’t unplug, Due works very well…

And, I try to remove the SerialUSB code , and try to unplug
then Due works well.

Is there an exception code for SerialUSB?

void recvWithEndMarker() {
 static byte ndx = 0;
 char endMarker = '\n';
 char rc;
 if (Serial.available()>0) {
  rc = Serial.read();
  //SerialUSB.print((char)rc);
  Serial3.print((char)rc);             <--- new code
 }     
}

If USB unplug, I can check from the ethernet(Serial3) port

Please explain what the relation from Serial3 to Ethernet is. Usually a serial interface doesn't connect to Ethernet so I'm a bit confused.

I'm using some RS232 to Ethernet converter module (like that https://www.amazon.com/Serial-Ethernet-Converter-Device-Server/dp/B00FJEHNSO)

I just used this to check data log.

now I solved temporarily using FLAG, like this.

void recvWithEndMarker() {
 static byte ndx = 0;
 char endMarker = '\n';
 char rc;
 if (Serial.available()>0) {
  rc = Serial.read();

  /* if special active, FLAG = true and use SerialUSB port */ 
  if(FLAG){
      SerialUSB.print((char)rc);
  }


  Serial3.print((char)rc);             
 }     
}

It is assumed that there is a problem connecting the serial0 port to LoRa networking. I originally monitored the serial0 port with the programming port. Then I connect the serial0 port to LoRa and upload it to serialUSB and monitor it. If I disable serialUSB and monitor it with serial3 and run LoRa Module connecting with serial0, it works fine. But I wonder why it stops if I use serialUSB only.

I hope I understand you correctly. I summarize what I got: You have a due and connect it to your PC by the integrated USB connection. You have additional serial connections for other purposes. You say now that if you write to the SerialUSB object in your sketch but disconnect the USB connection to the PC not data will be written to the other serial connections while that USB connection to the PC is not re-established. Is that correct?

If yes, please simplify your setup to have only 2 serial connections and write a sketch that writes to both. Does it react the same way? It shouldn't as the code for the Due USBSerial object doesn't block if if there is not USB connection but will simply reports an error. Do you use the latest SAM core?

I solved.

I'm using the Arduino SAM3x(DUE), but It's not the Arduino Due board. I made a new PCB by this same CPU If turn off and turn on without cable or with cable, It's always work well, But, If I unplug the USB cable suddenly while connecting to the serial communication program for monitoring, program just stopped. I checked by using the SD card logger and Ethernet port to see where it stops I have confirmed that Exactly stopped at SerialUSB.println (); line I switched from LoRa --- Serial to LoRa --- Serial2, but the symptoms were the same.

But finally, the solution found After the rs-232 communication is reliably terminated in the serial communication program I disconnected the USB cable and confirmed the operation. and from this time, it work well.

I guess because of abnormal termination If my guess is correct, How can I throw exceptions in the firmware to ensure serial port safety termination?