kiero
kiero

Reputation: 121

Bridging two serial devices using Arduino. Baud rate mismatch

I am receiving data from a GP20U7 GPS unit at 9600 (NMEA sentence bursts) that I need to forward to NMEA183 network at 4800. I thought that mismatch being not too big, and the NMEA data coming in bursts, internal UART buffers will be able to handle this and I can simply resend sentences using the following code:

#include <SoftwareSerial.h>

// Configure GPS
#define GPS_SerRX 2
#define GPS_SerTX 3
#define GPS_SerBDR 9600  // GPS baudrate
#define GPS_SerINV false // inverted output on or off

// Configure NMEA output
#define NMEA_SerRX 10
#define NMEA_SerTX 11
#define NMEA_SerBDR 4800  // NMEA output baudrate
#define NMEA_SerINV false // inverted output on or off

#define PTT_PIN 4

//##################################################################################

char gps_c;
SoftwareSerial GPS_Serial(GPS_SerRX, GPS_SerTX, GPS_SerINV); 
SoftwareSerial NMEA_Serial(NMEA_SerRX, NMEA_SerTX, NMEA_SerINV); 

void setup() {      
  pinMode(GPS_SerRX, INPUT);    // define pin modes for TX and RX
  pinMode(GPS_SerTX, OUTPUT);
  pinMode(NMEA_SerRX, INPUT);      
  pinMode(NMEA_SerTX, OUTPUT);
  pinMode(PTT_PIN, OUTPUT);     // setup the NMEA PTT pin 
  digitalWrite(PTT_PIN, HIGH);  // set the PTT to TX mode
  
  Serial.begin(NMEA_SerBDR);           // setup serial for debugging
  delay(50);
  NMEA_Serial.begin(NMEA_SerBDR);      // setup the NMEA183 compatible serial
  delay(50);
  GPS_Serial.begin(GPS_SerBDR);        // setup serial for GP20U7 GPS unit
}

void loop() {
   if (GPS_Serial.available()) {
        gps_c = GPS_Serial.read();
        //Serial.print(gps_c);
        //NMEA_Serial.print(gps_c);
        Serial.write(gps_c);
        NMEA_Serial.write(gps_c);
    }
}

but the downstream NMEA receiver is not happy with the transmissions. Any hints?

Upvotes: 0

Views: 197

Answers (1)

Peter Plesn&#237;k
Peter Plesn&#237;k

Reputation: 819

You can't use two instances SoftwareSerial in same time. Reason is that method write disable interrupts during sending character. So then you miss start bit on second interface. Use combination 1 HW and 1 SW channel. Or use arduino MEGA with four HW serial channels. In case of low level programming it is possible doing two software serial channels, but this it not easy. Check arduino site for more info.

In other side, since communication is in burst, you can buffer whole message not only one char and resend whole message.

Upvotes: 1

Related Questions