0

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?

kiero
  • 121
  • 1
  • 7

1 Answers1

1

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.

Peter Plesník
  • 524
  • 1
  • 2
  • 7
  • Thanx Peter! Now I simplified the problem and use only one instance of SoftwareSerial to send out Strings -- a made up NMEA sentence with dummy GPS coords. Sadly, even this part does not work and the radio is not understanding the sentences. It's weird since Cobra Marine (VHF manufacturer) says they follow standard NMEA183 specs and according to their helpdesk, my GPS sends out sentences their radio understands. Slowly running out of ideas. I will try to check whether the RS-485/TTL module I am using can receive NMEA from the radio as now I started suspecting the module. – kiero May 10 '22 at 19:20
  • 1
    After debug hw modules, for bridging simply use hw serial as second interface. You can use same pin as source for transmiting module and also for connect terminal. Than you can simply display re-sended messages in terminal in same time. Two function in one - debug line and second transmit hw line. – Peter Plesník May 10 '22 at 20:00