Weird Serial2/Serial3 problem

Hi,

I am trying to communicate with a GSM shield (iComSat) using my arduino Mega’s serial2 port (pin16, pin 17).
My code is as follows:

#include <string.h>

char incoming_char=0;

void setup()
{
  Serial.begin(9600);
  Serial2.begin(9600);
  
  Serial.println("Starting Communication...");
}

void loop() {

  if(Serial2.available() >0)
  {
    incoming_char=Serial1.read();
    Serial.print(incoming_char);
  }
  
  if(Serial.available() >0)
  {
    incoming_char=Serial.read();
    Serial2.print(incoming_char);
  }
}

The problem is that when I use serial2 (or serial3), as soon as I send any AT command (even just “AT”) the terminal program (Bray’s terminal) just starts printing periods like so: …
and so on, until I disconnect.
Now if I switch my setup and use serial1 instead, everything works as it should.
Does anyone have any idea of what could be going wrong? Is my board broken/fried?

Are you sure this is correct?

  if(Serial2.available() >0)
  {
    incoming_char=Serial1.read();
    Serial.print(incoming_char);
  }

If you check Serial2, you should read Serial2.

Opps!

I'm sorry for wasting your time. I can't believe I didn't see that.... :blush:
Thanks for the help. It works perfectly now!

Sparked:
Opps!

I'm sorry for wasting your time. I can't believe I didn't see that.... :blush:
Thanks for the help. It works perfectly now!

If it works, you didn't waste my time at all! :slight_smile: