Hello everyone,
I am currently programming an app for an Arduino UDE which will be a serial gateway between a device and my computer, it needs to transmit a Linux debug flow to my computer's serial port. Sadly, the issue i am encoutering is that for a reason i ignore, the SerialUSB port seems to freeze and crash all the other serial ports on the DUE without emitting a single byte. I have tried sending this debug flow through the Programming Port and it worked just fine. HEre is the program i made.
//DUE
const String DEVICE_NAME = "IMX_Loader";
const String SCRIPT_VERSION = "v1.0";
const String DEVELOPPER = "by Joris LE MALLET";
String Data1 = "Data 1 received = ";
String Data2 = "Data 2 received = ";
int n = 0;
int number;
int BootPin = 8;
int ResPin = 51;
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
Serial1.begin(115200);
SerialUSB.begin(115200);
Serial.setTimeout(2);
SerialUSB.setTimeout(6);
Serial1.setTimeout(6);
pinMode(BootPin, OUTPUT);
pinMode(ResPin, OUTPUT);
digitalWrite(ResPin, HIGH);
digitalWrite(BootPin, LOW);
number = 0;
while(!SerialUSB){
};
}
void loop() {
// put your main code here, to run repeatedly:
//SerialUSB.println(number);
if(Serial.available() > 0){ //Programming port of the DUE, used to toggle the signals (RESET, BOOTSTRAP) and to put the DUE in Gateway mode or in piloting mode
String strRecu = Serial.readString();
if(strRecu.equals("*IDN?")){
SerialUSB.println(DEVICE_NAME+" "+SCRIPT_VERSION+" "+DEVELOPPER);
}
if(strRecu.equals("Toggle pilot mode")){ //Command to start the piloting mode for the relays
Serial.println("Entering piloting mode");
while(Serial.available() == 0){
}
strRecu = Serial.readString();
if(strRecu.equals("start bootstrap")){ //Command to turn the LED on
digitalWrite(BootPin, LOW);
}
else if(strRecu.equals("stop bootstrap")){
digitalWrite(BootPin, HIGH);
}
else if(strRecu.equals("Reset")){
digitalWrite(ResPin, LOW);
delay(3000);
digitalWrite(ResPin, HIGH);
}
}
else if(strRecu.equals("Toggle gateway mode")){
//Serial.println("Entering gateway mode");
int i = 0;
Data1 = Data1 + i;
//Serial.println(Data1);
SerialUSB.println("Hello1");
while(Serial1.available() == 0/*&&(SerialUSB.available() == 0)*/){
}
while(1){
while(Serial1.available() != 0/*&&(SerialUSB.available() == 0)*/){
Serial.println(Serial1.readString());
}
}
Data2 = Data2 + i;
//Serial.println(Data2);
//Serial.println("Data 2 received = %i");
SerialUSB.println("Parsing...1");
while((Serial2.available() > 0)||(SerialUSB.available() > 0)){
Serial.println("Data received to be parsed");
SerialUSB.println("Parsing...2");
if(Serial2.available() > 0){ //Hardware Serial 2 (pins 16 and 17), used to send the commands and to read the debug flow from the PFD2020
/*strRecu = Serial2.readStringUntil(0x0D);*/
SerialUSB.print(Serial2.readString());
SerialUSB.print("\n");
}
if(SerialUSB.available() > 0){ //NAT port of the DUE, used to read the commands destined to the PFD2020
// strRecu = ;
Serial2.print(SerialUSB.readString());
Serial.println("Hello2");
}
}
}
}
//number ++;
// delay(20);
}```