Go Down

Topic: can't use Serial1 after pinMode(16.HIGH) (Read 579 times) previous topic - next topic

zeroun01

Hi,
I am using TX2 and RX2 in serial communication.
But after setting  pin 16  to LOW , I can't reuse it in serial communication.
Here is my code for arduino due:
Code: [Select]
if (inputString1.equalsIgnoreCase("BREAK")) {

Serial2.end();

pinMode(16,OUTPUT);

digitalWrite(16,LOW);

delay(350);

Serial2.begin(baudeADP);

}

AWOL

That was a snippet of code, so here's a snippet of an answer: because.
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

zeroun01

this is the complete code:
Code: [Select]

void setup() {
   Serial.begin(9600);
   Serial2.begin(4800);
}

void loop() {
   // read from port 0, send to port 2: 
   if (Serial.available()) {
     int inByte = Serial.read();
     
     if(inByte == 'B')
     {
      pinMode(16,OUTPUT); // using pin 16 as an output
      digitalWrite(16,HIGH);
      delay(350);
      Serial2.begin(4800); // using pin 16 again on serial communication
     }

     Serial2.write(inByte);

   }
   // read from port 2, send to port 0:
   if (Serial2.available()) {
     int inByte = Serial2.read();
     Serial.write(inByte);
   }
}


RX2 (pin 17) is wired with TX2 (pin16).
This code allow the arduino to recieve bytes on port 0 and send it to port 2.
Recieving 'B', pin 16 is switched to pinmode and returning again to Serial mode.

Its works perfectly on mega board:
With Serial Monitor:
hi -> hi
B   -> B
hi  -> hi
But problems come with the Due board:
With Serial Monitor:
hi  -> hi
B   -> <nothing>
hi  -> <nothing>

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy