Serial2 read errors


#1

I’m connecting a GPS (MTK3339) to the second serial port. For the most part it works, but I’ve noticed I had a high error rate on GPS updates. I’ve ditched all libraries and reduced everything to a simple read loop (see on the bottom). It seems that there are number of characters getting missed or injected. For eg:

00K$GPGGA,211115.084,,,,,0,00,,,M,,M,,*73
$GPRMC,211118.0,08$,,N$GPGGA,211119.084,,,,,0,00,,,M,,M,,*7F
$GPGSV,1,1,02,07,,,160
2,.,GTN*$GPGGA,211210.083,,,,,0,00,,,M,,M,,*72

The first line shouldn’t start with 00, and the second is missing a newline (and a checksum on the first GPS sentence), while the 3rd and 4th have an extra newline. I’m connecting rx, tx, and gnd. I’ve tried reading the MTK3339’s serial with other devices (my computer, raspberry pi, different arduinos) and none of them seem to exhibit this issue.

Does anyone have any pointers where to look or what could be going wrong?

Thanks,
Mayo

void setup() {
  Serial.begin(9600);
  Serial.println("GPS test");
  Serial2.begin(9600);
  delay(10);
}

void loop() {
  if (Serial2.available()) {
    char c = Serial2.read();
    Serial.write(c);
  }
}

#2

Usually in these scenarios I double double check the signals using a scope. Is it possible to get a scope trace to ensure the signal is transmitting properly over the serial bus?


#3

I don’t have access to a scope, but I tried the closest thing I could think of: I stole signal straight from the Dash’ Serial2 TX pin and brought it to a separate serial port (common ground), basically mirroring what’s being sent to Dash. The mirror serial port receives everything in tact.


#4

“Separate serial port” in this case is an external device like a USB-to-serial converter plugged into a computer?

So you’re thinking that the Serial2 hardware may be malfunctioning?

Any chance you have a second Dash on hand to swap out and try?


#5

Sorry, that wasn’t clear. That’s right, I broke it out to a serial USB converter.

I don’t want to be too fast to blame the Dash, but it certainly seems that way. I also have some intermittent problems with the built-in USB serial side (there is another thread on here … it renders my USB ports useless until I reboot my machine. Maybe it shorts them somehow?). I don’t think these were related, but I wonder.

I don’t have a second Dash, but I did order a scope, so I’ll get a trace once it gets here.

I might also order a new Dash, mine is older, one of the early post-pro designs. It doesn’t look like any of the diagrams/pictures on the site, but the pinouts match the 1.1 version.

Thank you for your help so far.


#6

Hi Chris, here are couple of images from scope off the pin on Dash. To me it looks pretty good, but you might see something I’m missing. Any suggestions are very welcome.

21

Thanks,
Mayo


#7

Actually that looks pretty good.

What is the transmit speed? 115,200?


#8

I’m using 9600


#9

Hi - I get exactly the same at 9600, running the same code as you. I have had a look on a scope with a serial decoder and everything looks just fine. The serial decoder decodes the data from the scope as it should.

The dash gets the data in and reads:

83911V2C02.40460,P040X,K$GPGGA,134701.000,2432.1270,N,00137.9615,W,1,04,,N918A2,3P,3,G082,
3,
45N908G,AA00F0T5$GPGGA,134702.000,2432.1270,N,00137.9615,W,150,00
,14V26119S2,220$04$050W1,.6KP.,0T,K$GPGGA,134703.000,2432.1270,N,00137.9615E,.S0,17P,13$,2$75,2.,PTN,01


#10

Ah… I see what the problem is… Basically you are getting in each char with a loop in between. Every time it passes the “loop” it misses time and if there is a char on it’s way in when it loops. that char gets missed.

This works for me on 38400 but I would think it still works on 9600. I will give that a go too.
So - instead of the “IF”, use “WHILE” to stop it from jumping through the loop to the start again.

void setup() {
Serial.begin(115200);
Serial.println(“GPS test”);
Serial2.begin(38400);
delay(10);
}

void loop() {
while (Serial2.available())
Serial.write(Serial2.read());

delay(1);
}

Edit to say that 9600 worked for me too. :slight_smile:


#11

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.