Skip to content

Commit f06ae26

Browse files
authored
optimize baud rate handling
- optimise times - avoid issues when ruining from from task and with concurrent access when changing baud rate
1 parent ea91e5d commit f06ae26

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

src/SparkFun_u-blox_SARA-R5_Arduino_Library.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -914,10 +914,8 @@ SARA_R5_error_t SARA_R5::reset(void)
914914
{
915915
beginSerial(SARA_R5_DEFAULT_BAUD_RATE);
916916
setBaud(_baud);
917-
delay(200);
918917
beginSerial(_baud);
919918
err = at();
920-
delay(500);
921919
}
922920
return init(_baud);
923921
}
@@ -5022,19 +5020,20 @@ SARA_R5_error_t SARA_R5::init(unsigned long baud,
50225020
int retries = _maxInitTries;
50235021
SARA_R5_error_t err = SARA_R5_ERROR_SUCCESS;
50245022

5023+
beginSerial(baud);
5024+
50255025
do
50265026
{
50275027
if (_printDebug == true)
50285028
_debugPort->println(F("init: Begin module init."));
50295029

5030-
beginSerial(baud);
5031-
50325030
if (initType == SARA_R5_INIT_AUTOBAUD)
50335031
{
50345032
if (_printDebug == true)
50355033
_debugPort->println(F("init: Attempting autobaud connection to module."));
50365034

50375035
err = autobaud(baud);
5036+
50385037
if (err != SARA_R5_ERROR_SUCCESS) {
50395038
initType = SARA_R5_INIT_RESET;
50405039
}
@@ -5047,6 +5046,7 @@ SARA_R5_error_t SARA_R5::init(unsigned long baud,
50475046
powerOff();
50485047
delay(SARA_R5_POWER_OFF_PULSE_PERIOD);
50495048
powerOn();
5049+
beginSerial(baud);
50505050
delay(2000);
50515051

50525052
err = at();
@@ -5806,6 +5806,7 @@ int SARA_R5::hwAvailable(void)
58065806

58075807
void SARA_R5::beginSerial(unsigned long baud)
58085808
{
5809+
delay(100);
58095810
if (_hardSerial != NULL)
58105811
{
58115812
_hardSerial->begin(baud);
@@ -5859,7 +5860,6 @@ SARA_R5_error_t SARA_R5::autobaud(unsigned long desiredBaud)
58595860
{
58605861
beginSerial(SARA_R5_SUPPORTED_BAUD[b++]);
58615862
setBaud(desiredBaud);
5862-
delay(200);
58635863
beginSerial(desiredBaud);
58645864
err = at();
58655865
}

0 commit comments

Comments
 (0)