Dear Robin,
I updated my code in such a way that no "read data" happens outside recvWithStartEndMarkers().
However the problem remains, I got the exact same output as shown in post#6.
I suspect that there are other bugs in the code...
#include <Arduino.h> // required before wiring_private.h
#include "wiring_private.h" // pinPeripheral() function
Uart Serial2 (&sercom1, 11, 10, SERCOM_RX_PAD_0, UART_TX_PAD_2);
const int numChars = 5000;
char receivedChars[numChars];
boolean newData = false;
short k = 0;
void SERCOM1_Handler()
{
Serial2.IrqHandler();
}
void setup() {
// initialize serial communication at 115200 bits per second: Serial1 is pin 0 and 1;
Serial1.begin(9600);
Serial2.begin(9600);
Serial1.println("<Arduino is ready>");
// Assign pins 10 & 11 SERCOM functionality
pinPeripheral(10, PIO_SERCOM);
pinPeripheral(11, PIO_SERCOM);
}
void loop() {
for (k;k<1;k++)
{
Serial2.println("+++");
Serial2.println("rdlfind 2 -3 -1");
}
recvWithStartEndMarkers();
showNewData();
}
void recvWithStartEndMarkers() {
static boolean recvInProgress = false;
static int ndx = 0;
char startMarker = '<';
char endMarker = '>';
char rc;
// if (Serial2.available() > 0) {
while (Serial2.available() > 0 && newData == false) {
rc = Serial2.read();
if (recvInProgress == true) {
if (rc != endMarker) {
receivedChars[ndx] = rc;
ndx++;
if (ndx >= numChars) {
ndx = numChars - 1;
}
}
else {
receivedChars[ndx] = '\0'; // terminate the string
recvInProgress = false;
ndx = 0;
newData = true;
}
}
else if (rc == startMarker) {
recvInProgress = true;
}
}
}
void showNewData() {
if (newData == true) {
Serial1.print("This just in ... ");
Serial1.println(receivedChars);
newData = false;
}
}