Skip to content

Commit

Permalink
Add baud rate check #254
Browse files Browse the repository at this point in the history
  • Loading branch information
lewisxhe committed Nov 26, 2024
1 parent 213e7a7 commit 52b4197
Showing 1 changed file with 37 additions and 3 deletions.
40 changes: 37 additions & 3 deletions examples/Arduino_AT_Debug/Arduino_AT_Debug.ino
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,29 @@
// Set serial for AT commands (to the module)
#define SerialAT Serial1

uint32_t AutoBaud()
{
static uint32_t rates[] = {115200, 9600, 57600, 38400, 19200, 74400, 74880,
230400, 460800, 2400, 4800, 14400, 28800
};
for (uint8_t i = 0; i < sizeof(rates) / sizeof(rates[0]); i++) {
uint32_t rate = rates[i];
Serial.printf("Trying baud rate %u\n", rate);
SerialAT.updateBaudRate(rate);
delay(10);
for (int j = 0; j < 10; j++) {
SerialAT.print("AT\r\n");
String input = SerialAT.readString();
if (input.indexOf("OK") >= 0) {
Serial.printf("Modem responded at rate:%u\n", rate);
return rate;
}
}
}
SerialAT.updateBaudRate(115200);
return 0;
}

void setupModem()
{
#ifdef MODEM_RST
Expand Down Expand Up @@ -47,11 +70,22 @@ void setup()
// Set console baud rate
SerialMon.begin(115200);

// Set GSM module baud rate and UART pins
SerialAT.begin(115200, SERIAL_8N1, MODEM_RX, MODEM_TX);

setupModem();

if (AutoBaud()) {
Serial.println(F("***********************************************************"));
Serial.println(F(" You can now send AT commands"));
Serial.println(F(" Enter \"AT\" (without quotes), and you should see \"OK\""));
Serial.println(F(" If it doesn't work, select \"Both NL & CR\" in Serial Monitor"));
Serial.println(F(" DISCLAIMER: Entering AT commands without knowing what they do"));
Serial.println(F(" can have undesired consiquinces..."));
Serial.println(F("***********************************************************\n"));
} else {
Serial.println(F("***********************************************************"));
Serial.println(F(" Failed to connect to the modem! Check the baud and try again."));
Serial.println(F("***********************************************************\n"));
}

}

void loop()
Expand Down

0 comments on commit 52b4197

Please sign in to comment.