Data not transmitted properly from PC to arduino mega2560 using Serial1,2,3

Dear all,

I programmed arduino mega 2560 to transmit data from pc to arduino board using serial 1. I configured RX1 as input_pullup. But data was not transmitted properly to board.Instead i got only unknown data. For example, When i had sent character ‘O’ to board, The received data was ‘H’. However i could read data from board accurately to PC using USB Serial port. I used Tera terminal for viewing data in PC. I used default baud rate 9600 and 8,N,1.

What will be the problem? Any help is highly appreciable.

Following is code:-

//#include<SoftwareSerial.h>
//SoftwareSerial Serial4=SoftwareSerial(11,12);
char ch;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);

while(!Serial)
{
;
}
Serial.println(“Ready…”);
Serial1.begin(9600);
pinMode(18,OUTPUT);
pinMode(19,INPUT_PULLUP);
//digitalWrite(18,HIGH);
//digitalWrite(19,HIGH);
while(!Serial3)
{
;
}
Serial3.println(“Ready…”);
}

void loop() {
// put your main code here, to run repeatedly:
while(1)
{
if(Serial1.available())
{
ch=Serial1.read();
if(ch==‘X’)
break;
}
}

Serial.println(ch);
Serial.println(“Muhilan Veeraraju”);
Serial1.println(ch);
Serial1.println(“Muhilan Veeraraju”);
delay(500);
}

See the post at the top of the forum 'How to use this forum - please read' it gives lots of useful information such as how to post code properly.

Remove all the bits of code your not using, such as the software serial stuff, the code is then easier to read.

You dont need to initialise the pins for Serial1, the Serial1.begin() does that.

Your using Serial3 but there is no Serial3.begin()

Hi, Welcome to the forum.

Please read the post at the start of any forum , entitled "How to use this Forum". OR http://forum.arduino.cc/index.php/topic,148850.0.html. Then look down to item #7 about how to post your code. It will be formatted in a scrolling window that makes it easier to read.

Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?

Thanks.. Tom.. :)