Howdy All,
I wrote an Arduino program and tested it on other Arduino boards. Now, I'm porting that working program to the Teensy 4.1. I'm running into odd serial port behavior that I don't understand.
Here's the function ( tested and works on both Arduino Uno and Sparkfun Artemis ).
This code seems to crash the serial port -- the Serial.println("ACK>") never gets called if I send a string like "abcdefg~" -- but if I send "abcdefgh", it does.
In both cases, the board stops sending any serial.Print strings after the readStringUntil function is called, and the board seems to be crashed.
I've tried replacing the readStringUntil function with a byte-by-byte read loop, and even that seems to crash the board. What am I doing wrong?
I wrote an Arduino program and tested it on other Arduino boards. Now, I'm porting that working program to the Teensy 4.1. I'm running into odd serial port behavior that I don't understand.
Here's the function ( tested and works on both Arduino Uno and Sparkfun Artemis ).
This code seems to crash the serial port -- the Serial.println("ACK>") never gets called if I send a string like "abcdefg~" -- but if I send "abcdefgh", it does.
In both cases, the board stops sending any serial.Print strings after the readStringUntil function is called, and the board seems to be crashed.
I've tried replacing the readStringUntil function with a byte-by-byte read loop, and even that seems to crash the board. What am I doing wrong?
Code:
//-----------------------------------------------------------------------------------------------------------------------------
// Function:
// ReadSerialPortData keeps reading the port until it sees a ~ character, appends what it reads to the command
// buffer.
boolean CommandManager::ReadSerialPortData()
{
boolean returnCode = false;
int serialBytesRecieved = 0;
serialBytesRecieved = Serial.available();
Serial.print("Received data bytes::");
Serial.println(serialBytesRecieved);
// we can recieve data in fragments, and need to coalate it together.
if (serialBytesRecieved > 0)
{
returnCode = true;
Serial.println("ACK>");
// we got a valid buffer but it's likely fragmented Keep reading until we see the ~ character.
m_commandBuffer += Serial.readStringUntil('~');
}
return (returnCode);
}
Last edited by a moderator: