I'm getting corrupted data... please help

Hi, I'm tryin to interface a GPS antenna with an arduino mega. The antenna has a RS232 interface which I'm using to connect to with the arduino tx/rx pins. I'm using the mega for "debugging" because it has more than one serial connectors and I can redirect the data received so I can see what's really the arduino receiving from the antenna, but the real target is an arduino 2009 with an microSD shield, where the data is going to be stored..... now the problem: If I connect the antenna directly to my computer I get the following result:

0x1 0x3 0x0 0x6 0xd3 0xa 0x0 0x0 0x2e 0x18 0xfe 0xd3 0x4 0x1 0x3 0x0 0x6 0xd3 0
xa 0x10 0x21 0x0 0x2e 0x7c 0xfe 0x6e 0x4 0x1 0x3 0x0 0x6 0xd3 0x35 0x2 0x0 0x6 0
x0 0xfe 0xe6 0x4

Notice, these are messages which start with an 0x1 0x3 and end with 0x4, and inside are the lenght, payload and CS. (Thats the antenna protocol). With the arduino between the gps and computer I get something like:

0x7f 0x7e 0xf5 0x59 0x7a 0xbc 0xab 0x3 0xf 0x1f 0x7f 0x7e 0xf5 0x59 0x7a 0x
78 0xad 0x3 0xf 0x1f 0x7f 0x7e 0xdf 0xb7 0x59 0xb9 0xdf 0xb7 0x1 0x7c 0x1f 0x7f
0x7e 0xdf 0xb7 0x59 0xee 0xd7 0x9b 0x3 0x82 0x1f 0x7f 0x7e 0xdf 0xb7 0x59 0x6e 0
xd1 0x3 0xc1 0x1f

I noticed that the 0x1 from the original switches to 0x7f, 0x3 to 0x7e and 0x4 to 0x1f....

Heres the code I use to test in the arduino (taken from another user with problems)

void setup () {
  Serial.begin(115200);        // initialize the serial port
  Serial3.begin(115200);
  //Serial3.flush();
  
}
void loop () {
  int data[128];
  int idx = 0;

  while (idx != 128) {
    int avail = Serial3.available();
    if (avail > 0) {
      data[idx] = Serial3.read();
      //Serial.print("-- Avail: "); Serial.print(avail);
      //Serial.print(" / Data: ");
        Serial.print(byte(data[idx]));
      //Serial.print(" / Byte: ");Serial.print(idx);Serial.println("");
        idx++;
        delay(5);
    }
  }
}

and to see the results I'm using python interpreter with the following code:

import serial
import sys
ser = serial.Serial("com7", 115200)
while True:
      sys.stdout.write(" "+str(hex(ord(ser.read()))))

Note that I tried with several baudrates, combinations of baudrates, prints formats, delays and no delays, etc... The data inside the microSD was also corrupted, it's something thats happening between the antenna and the arduino serial buffer I think.

Please, if someone could tell me what's going on with the data i'd be very grateful... Thanks in advance.

I've yet to see an antenna with an RS232 interface. I think you mean a receiver.

Have you thought about the inverted nature of an RS232 interface, with respect to Arduino serial signals? Also have you thought about the possible damage to your Arduino that could be caused by applying negative voltages to its inputs?

Yep, receiver... sry !!

what do you mean by the inverted nature of rs232 interface?

Thanks for the reply.

edit:

You mean rx on arduino goes to tx on the receiver? Yes, I considered that, otherwise I wouldnt be receving data.

inverted nature of rs232 interface?

I mean that on RS232 a 1 is represented by a negative voltage (below zero volts), and a zero by a positive voltage (above zero volts).

The voltage swing between negative and positive could be as much as 30V.

But shouldn't the arduino be prepared to receive such voltages as they are specified in the rs232 standard?

Should I put some resistors between the rs232 pins and the serial cable?

Thanks in advance.

But shouldn't the arduino be prepared to receive such voltages as they are specified in the rs232 standard?

If the Arduino were an RS232 device, then yes, I'm sure it should. But it isn't, which is why they invented the MAX232 chip from Maxim.

Wow.. my bad... I read about the serial interfaces on arduino and I automatically assumed it was a rs232 interface....

well, thanks for your replies, and excuse me for my ignorance. Bye!

I read about the serial interfaces

Well, serial could include USB (it doesn’t really do that either), or I2C (it does do that one) or SPI (and that one) or…lots of other options.

The Arduino does do serial which with an inversion and level shift would be electrically compatible with RS232.

RS232 Serial [ch8800] TTL Serial in regards to voltage levels.

TTL Serial is 0 to +5Vdc and is what microprocessors generally use.

RS232 Serial is nominally -15Vdc to +15V and must be level converted so it doesn't fry something.

Never assume on this stuff, or the smoke gets out :'(

Here's an example of interfacing a MAX232 chip for level conversion: http://www.cutedigi.com/pub/Arduino/arduino_RS232.pdf

There is also a tutorial here http://www.arduino.cc/en/Tutorial/ArduinoSoftwareRS232 However it uses the MAX3323 chip, which is a very special variant, and most likely overprized.. I don't see why, because it's special features are neither used nor needed.....

http://www.cutedigi.com/pub/Arduino/arduino_RS232.pdf ← this worked for me, Thanks everyone for your advices and help!