Pages: [1]   Go Down
Author Topic: RS 232 communication with Serial1 on MEGA 2560  (Read 7140 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

Hello everybody,
I'm having problem communicating with the MEGA 2560 through Serial 1,2 and 3 :
the connection through USB via Serial 0 works perfectly but when I try to send data with Serial3 (pins 14 and 15) the computer recieve weird datas.
It is as if  the bytes are messed up.

here is the code I'm using :

Code:
void setup() {
  // initialize both serial ports:
  Serial.begin(9600);
  Serial3.begin(9600);
  Serial.println("Hello World");
  Serial3.println("Hello World");
}

void loop() { 
  if (Serial3.available()) {
    int inByte = Serial3.read();
    Serial.print(inByte, BYTE);
  }
 
    if (Serial.available()) {
    int inByte = Serial.read();
    Serial3.print(inByte, BYTE);
  }
 
}

for example, there is what I receive instead of Hello World (in Hexa) :
00
AB 3A 3A 0A FA 8B 85 1B 27 37 E5 EB 00


I think it may be a silly mistake but I don't have clues.

I already tried to check the communication with a cross wired DB9 cable between 2 PC to see if the data was sent correctly and it works.
Also the Com port configuration is : 9600 bps - 8 bits - No Parity - 1 Bit Stop - No Control

Do you have any ideas ?
Logged

0
Offline Offline
Full Member
***
Karma: 0
Posts: 186
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The Arduino serial ports are 5v TTL. RS-232 is -12v. You need a level shifter. Sparkfun has one I have used with great success.
http://www.sparkfun.com/products/8780
scroll down below it to related products for one with a connector and/or a kit.
« Last Edit: January 27, 2011, 11:09:19 am by arbarnhart » Logged

0
Offline Offline
Jr. Member
**
Karma: 1
Posts: 74
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Are you trying to drive the DB9 directly from the MEGA pins?   If so, you are trying to use TTL to talk RS232, which can't be done.  I believe you need something like a MAX232 to convert TTL to RS232.

Try this  connect TX2-RX3 and RX2 to TX3 and see what you get on Serial2.  
Logged

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

Ok thanks for the quick replies, I wasn't using a level shifter I'll try with that.

BTW I tried connecting Rx 2 to Tx 3 and Rx3 to Tx2 and it was working perfectly.

Thanks again for the advices
Logged

nr Bundaberg, Australia
Offline Offline
Tesla Member
***
Karma: 126
Posts: 8472
Scattered showers my arse -- Noah, 2348BC.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Transmitting 5v -> 232 often does work, but often doesn't work also. It depends on the receiving hardware.

Receiving 232 into the Arduino is a bad thing to do, +-12v into the Arduino pin is not recomended. smiley

______
Rob
Logged

Rob Gray aka the GRAYnomad www.robgray.com

Pages: [1]   Go Up
Jump to: