Arduino soft serial port failure problem
Posted: Tue Jun 22, 2021 11:22 am
I encountered a situation where I need 2 soft serial ports, one of them is not working and I can't get the data. The switch listener was also written, but it still didn't work.
There is no problem with the hardware circuit, and the code is executable after switching to another one that uses only one soft interface.
I am new to learning and looking for guidance on whether I am missing something.
There is no problem with the hardware circuit, and the code is executable after switching to another one that uses only one soft interface.
I am new to learning and looking for guidance on whether I am missing something.
- CODE: SELECT_ALL_CODE
#include <Arduino.h>
#include <SoftwareSerial.h>
SoftwareSerial GSMSerial(10, 11); // RX, TX
SoftwareSerial GpsSerial(5, 6); // RX, TX
#define DEBUGSerial Serial
。
。
。
void setup()
{
DEBUGSerial.begin(9600);
GSMSerial.begin(9600);
Init();
GpsSerial.begin(9600);
}
void loop()
{
gpsRead(); //Acquisition of GPS data
parseGpsBuffer();//Parsing GPS data
printGpsBuffer();//Output the parsed data
GSMSerial.end();
if(tic == 0) {
Init();
}else{
url = urlhead+"longitude="+llongitude+"&latitude="+llatitude;
SendMessage();
}
}
**The following GSMSerial.available() is not working, to be precise, it is not listening;**
void gpsRead() {
GpsSerial.listen();
while (GSMSerial.available())
{
gpsRxBuffer[ii++] = GSMSerial.read();
if (ii == gpsRxBufferLength)clrGpsRxBuffer();
}
。
。
。
}
void Init()
{
GSMSerial.listen();
DEBUGSerial.print("Initialization in progress, please wait。。。");
// AT
GSMSerial.print("AT");
。
。
。
}