I am using AltSoftSerial to receive data from GPS receiver at 57600 bps with Arduino UNO. GPS is set to 5Hz with 6 message types. Real data amount is ~ 24000 bps. Here is how I calculate, hope correct.
1 message is roughly 100 bytes(exaggerated). I have 6 of messages. So 100x6=600 bytes. I am receiving this with 5Hz so in 1 second I get 5x600 = 3000 bytes, which is 24000 bps.
In the main loop, I've removed any UART coomunication, to save time. So the following is my sketch:
void setup() {
pinMode(LED_PIN_RED, OUTPUT);
pinMode(LED_PIN_GREEN, OUTPUT);
altSerial.begin(57600);
}
unsigned short prevFailed = 0;
void loop() {
char c;
unsigned long chars;
unsigned short sentences, failed;
while(altSerial.available())
{
c = altSerial.read();
if(c != -1)
{
gps.stats(&chars, &sentences, &failed);
if (gps.encode(c))
{
if(failed > prevFailed)
{
digitalWrite(LED_PIN_RED, HIGH);
delay(1);
digitalWrite(LED_PIN_RED, LOW);
prevFailed = failed;
}
else
{
digitalWrite(LED_PIN_GREEN, HIGH);
delay(1);
digitalWrite(LED_PIN_GREEN, LOW);
}
}
}
}
}
TinyGPS used to parse NMEA sentences. LEDs are used to indicate success and errors. I got red LED flashing couple times in 10 second, while green LED is flashing very intensively, so good data has bigger proportion.
I know that I could connect GPS receiver to single UART on UNO, but first of all I need to debug my program, which is sensitive about data accuracy. Besides, documentation of AltSoftSerial says:
A commonly asked question is the maximum baud rate these library can support. Both can work with approximately 1 bit time of interrupt latency from OTHER code. So if other interrupts take a maximum of 15 µs (eg, some libraries), then a baud rate of 57600 ought to be possible. Without other libraries, on Teensy or Arduino (with the issue 776 fix), interrupt latency is about 3 to 4 µs. 115200 baud is possible.
However, the maximum baud rate is often not the most important question. Each library imposes interrupt latency on other libraries. AltSoftSerial causes approximately 2-3 µs latency. NewSoftSerial causes 10 bit times of latency for other libraries. Running at 57600 baud, that's 174 µs! This latency is the primary difference between AltSoftSerial and NewSoftSerial.
I have tried to increase RX_BUFFER_SIZE in AltSoftSerial.cpp to different values. No good.
So how to achieve this 57600 kbps?