Pages: [1]   Go Down
Author Topic: can't use Serial1 after pinMode(16.HIGH)  (Read 445 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 2
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
if (inputString1.equalsIgnoreCase("BREAK")) {

Serial2.end();

pinMode(16,OUTPUT);

digitalWrite(16,LOW);

delay(350);

Serial2.begin(baudeADP);

}
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 299
Posts: 26194
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

That was a snippet of code, so here's a snippet of an answer: because.
Logged

"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.

Offline Offline
Newbie
*
Karma: 0
Posts: 2
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

this is the complete code:
Code:
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>
Logged

Pages: [1]   Go Up
Jump to: