I am having an issue with serial communication on a Teensy 4.1
(1) -- When I first power the board up, I cannot receive serial characters from the Teensy with my Delphi application.
(2) -- If I close that application and open Terminal.exe , The response characters show up, but preceeded by byte values 00 00
(3) -- If I close terminal and then reopen my application , communication resumes normally.
What is causing the Teensy serial to transmit (2) null characters?
Code:
char USBrxData[20];
int USBrxptr = 0;
// *********************************************************************
void setup()
{
Serial.begin(115200);
while (!Serial) {}; // Wait for serial to start
}
// *********************************************************************
void loop()
{
USBrx();
}
// *********************************************************************
void USBrx()
{
char RXChar;
if (Serial.available() > 0) // USB UART RX = 0
{
RXChar = Serial.read();
if (RXChar == 0x0D )
{
USBrxData[USBrxptr+1] = 0; // terminate string
DecodeCmd();
}
else
{
USBrxData[USBrxptr] = RXChar;
USBrxptr++;
}
}
}
// *********************************************************************
void DecodeCmd()
{
int ptr;
if (USBrxData[0] == '?' && USBrxData[1] == 'V') // Respond to GUI
Serial.println("TWA2test");
for (ptr=0;ptr<20;ptr++) // clear rx buffer
USBrxData[ptr] = 0;
USBrxptr = 0; // reset pointer
}
// ------------------------------------------------------------------------