I have a loop() that is executing a function and then the identical code in the function (in series). The code looks like:
void modemverification () {
Serial2.write("AT\r\n");
while (!Serial2.available()) continue;
while (!Serial2.available()){
char feedback = Serial2.read();
Serial.print(feedback);
}
}
void loop() {
Serial.println("function");
modemverification();
delay(10000);
Serial.println("direct code");
Serial2.write("AT\r\n");
while (!Serial2.available()) continue;
while (Serial2.available()) {
char feedback = Serial2.read();
Serial.print(feedback);
}
delay(10000);
}
Interestingly the serial monitor looks like:
15:58:42.575 -> function
15:58:52.551 -> direct code
15:58:52.551 -> AT
15:58:52.551 -> OK
15:58:52.551 -> AT
15:58:52.551 -> OK
15:59:02.550 -> function
15:59:12.540 -> direct code
15:59:12.540 -> AT
15:59:12.540 -> OK
15:59:12.540 -> AT
15:59:12.540 -> OK
15:59:22.576 -> function
15:59:32.563 -> direct code
15:59:32.563 -> AT
15:59:32.563 -> OK
15:59:32.563 -> AT
15:59:32.563 -> OK
15:59:42.556 -> function
15:59:52.544 -> direct code
15:59:52.544 -> AT
15:59:52.544 -> OK
15:59:52.544 -> AT
15:59:52.544 -> OK
16:00:02.544 -> function
But if I delete the function, leave the direct code, and then add another block of identical direct code I get a different serial monitor output the code and serial monitor look like this respectively.
void loop() {
Serial.println("direct code1");
Serial2.write("AT\r\n");
while (!Serial2.available()) continue;
while (Serial2.available()) {
char feedback = Serial2.read();
Serial.print(feedback);
}
delay(10000);
Serial.println("direct code2");
Serial2.write("AT\r\n");
while (!Serial2.available()) continue;
while (Serial2.available()) {
char feedback = Serial2.read();
Serial.print(feedback);
}
delay(10000);
}
16:04:33.325 -> direct code1
16:04:33.325 -> AT
16:04:33.325 -> OK
16:04:43.322 -> direct code2
16:04:43.322 -> AT
16:04:43.322 -> OK
16:04:53.328 -> direct code1
16:04:53.328 -> AT
16:04:53.328 -> OK
16:05:03.336 -> direct code2
16:05:03.336 -> AT
16:05:03.336 -> OK
16:05:13.338 -> direct code1
16:05:13.338 -> AT
16:05:13.338 -> OK
16:05:23.346 -> direct code2
16:05:23.346 -> AT
16:05:23.346 -> OK
16:05:33.318 -> direct code1
16:05:33.318 -> AT
16:05:33.318 -> OK
16:05:43.321 -> direct code2
16:05:43.321 -> AT
16:05:43.321 -> OK
16:05:53.339 -> direct code1
16:05:53.339 -> AT
16:05:53.339 -> OK
16:06:03.344 -> direct code2
16:06:03.344 -> AT
16:06:03.344 -> OK
16:06:13.349 -> direct code1
16:06:13.349 -> AT
16:06:13.349 -> OK
16:06:23.358 -> direct code2
16:06:23.358 -> AT
16:06:23.358 -> OK
16:06:33.355 -> direct code1
16:06:33.355 -> AT
16:06:33.355 -> OK
16:06:43.319 -> direct code2
16:06:43.319 -> AT
16:06:43.319 -> OK
16:06:53.346 -> direct code1
16:06:53.346 -> AT
16:06:53.346 -> OK
16:07:03.339 -> direct code2
16:07:03.339 -> AT
16:07:03.339 -> OK
16:07:13.347 -> direct code1
16:07:13.347 -> AT
16:07:13.347 -> OK
16:07:23.357 -> direct code2
16:07:23.357 -> AT
16:07:23.357 -> OK
My question is how can these two programs give different results?