I encountered some errors using the hardware serial of Teensy 4.1.
When Teensy boot, my code always checks if Serial (in my case, Serial8) is available, but when I'm parsing the received data, it shows no value, and it will stock my Teensy until watchdog resets, and it will continue until infinity.
Here is a sample code of what I'm doing
Then this will be the result
As you can see, it always reboots and stocks at printing "delimiter location", not going to "data received" of my code.
I also tried to test all of my hardware serial using this code:
And here is the result:
As you can see, at the start of the program, Serial8.available is already = 1.
I noticed when I pressed the program button for 15 seconds, all hardware serial "resets" but it also erased my program and went back to blinking the built-in LED program. Is there any other way I can write in my program before "void loop" to reset the hardware serial?
When Teensy boot, my code always checks if Serial (in my case, Serial8) is available, but when I'm parsing the received data, it shows no value, and it will stock my Teensy until watchdog resets, and it will continue until infinity.
Here is a sample code of what I'm doing
Code:
String test = "";
int findDelimiter;
String Value = "";
#include "Watchdog_t4.h"
//WatchDog_1
WDT_T4<WDT1> wdt;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
Serial8.begin(9600);
Serial.setTimeout(100);
//Set Watchdog
WDT_timings_t config;
//Use WatchDog_1
config.trigger = 5; /* in seconds, 0->128 */
config.timeout = 10; /* in seconds, 0->128 */
wdt.begin(config);
//start
Serial.println("Begin");
}
void loop() {
// put your main code here, to run repeatedly:
if (Serial8.available() > 0) {
while (Serial8.available()) {
test = Serial8.readString();
}
//print what you read in Hardware Serial
Serial.print(F("SerialData Received: "));
Serial.println(test);
Serial.flush();
//print the location of delimiter
findDelimiter = test.indexOf(",");
Serial.print(F("Delimiter Location : "));
Serial.println(findDelimiter);
Serial.println();
Serial.flush();
//print the data starting from zero to delimiter location
Value = test.substring(0, findDelimiter); //rtcSync //wpControl
Serial.print(F("Data Received : "));
Serial.println(Value);
Serial.println();
Serial.flush();
}
wdt.feed();
}
Then this will be the result
As you can see, it always reboots and stocks at printing "delimiter location", not going to "data received" of my code.
I also tried to test all of my hardware serial using this code:
Code:
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
Serial.setTimeout(100);
Serial1.begin(9600);
Serial1.setTimeout(100);
Serial2.begin(9600);
Serial2.setTimeout(100);
Serial3.begin(9600);
Serial3.setTimeout(100);
Serial4.begin(9600);
Serial4.setTimeout(100);
Serial5.begin(9600);
Serial5.setTimeout(100);
Serial6.begin(9600);
Serial6.setTimeout(100);
Serial7.begin(9600);
Serial7.setTimeout(100);
Serial8.begin(9600);
Serial8.setTimeout(100);
Serial.print("Test Serial : ");
Serial.println(Serial.available());
Serial.print("Test Serial1: ");
Serial.println(Serial1.available());
Serial.print("Test Serial2: ");
Serial.println(Serial2.available());
Serial.print("Test Serial3: ");
Serial.println(Serial3.available());
Serial.print("Test Serial4: ");
Serial.println(Serial4.available());
Serial.print("Test Serial5: ");
Serial.println(Serial5.available());
Serial.print("Test Serial6: ");
Serial.println(Serial6.available());
Serial.print("Test Serial7: ");
Serial.println(Serial7.available());
Serial.print("Test Serial8: ");
Serial.println(Serial8.available());
}
void loop() {
// put your main code here, to run repeatedly:
}
And here is the result:
As you can see, at the start of the program, Serial8.available is already = 1.
I noticed when I pressed the program button for 15 seconds, all hardware serial "resets" but it also erased my program and went back to blinking the built-in LED program. Is there any other way I can write in my program before "void loop" to reset the hardware serial?