NeoSWSerial icon indicating copy to clipboard operation
NeoSWSerial copied to clipboard

Different behavior on Uno vs Pro Mini

Open dmnc-net opened this issue 6 years ago • 2 comments

Hi @SlashDevin, I'm doing some GPS tracker with SIMCom board and I'm using NeoSWSerial for AT commanding the modem. At this phase, I'm moving the project from Arduino Uno to the Pro Mini (5V 16bit) which uses the same Mega328P MCU. I've created my own methods for sending AT commands and receiving responses and my limitation is that I need to set ATE0 for disabling echoes because of handling responses.

However Uno is working fine, Pro Mini duplicates the outgoing AT command. For example:

Uno, command: AT+CREG?, response:

+CREG: 0,1

OK

Pro Mini, command: AT+CREG?, response:

AT+CREG?

+CREG: 0,1

OK

But this is not an echo problem, because if I turn echo on with ATE1, response will be:

AT+CREG?AT+CREG?

+CREG: 0,1

OK

I can solve this by adding step #2 to the process

  1. sending/writing AT command (_serialDevice.write("AT..."))
  2. flushing input (while (_serialDevice.available()) _serialDevice.read())
  3. flushing output (_serialDevice.flush())
  4. receiving response

... but I've tried to change NeoSWSerial to SoftwareSerial and the issue is gone. I'm not quite happy from flushing part of the response from modem when I'm going to read and store the response.

I'm using the Arduino USB2Serial board for uploading and reading the Serial console, but SoftwareSerial test has excluded this possibility (of cause).

dmnc-net avatar Nov 01 '18 10:11 dmnc-net

MCVE:

#define USE_NEO
#define BAUD_RATE 38400

#ifdef USE_NEO
  #include <NeoSWSerial.h>
  NeoSWSerial modemSerial(7, 8); // RX, TX
#else
  #include <SoftwareSerial.h>
  SoftwareSerial modemSerial(7, 8);
#endif

void setup() {
  Serial.begin(BAUD_RATE);
  modemSerial.begin(BAUD_RATE);
  Serial.println(F("Ready!"));
}

void loop() {  
  while (Serial.available()) modemSerial.write(Serial.read());
  delay(100);
  if (modemSerial.available()) {
    Serial.print(F("bytes in buffer: "));
    Serial.println(modemSerial.available());
  }
  while (modemSerial.available()) Serial.write(modemSerial.read());
}

dmnc-net avatar Nov 01 '18 10:11 dmnc-net

I'd like to debug this issue, @SlashDevin please do you have some advice for me where to look?

dmnc-net avatar Nov 06 '18 12:11 dmnc-net