Reset a UART connection on a Due I have a system that involves an Arduino Due connected to a Raspi 4 through UART in which the Due sends a heartbeat signal over UART for the pi to receive and send back as confirmation. One of the events that I need to handle is re-establishing the UART connection between the two devices if the program receiving UART on the pi (or the pi itself) fails for any reason and reboots. At the moment, I have the initial heartbeat working (as long as the pi program starts first) but when I stop the pi program to simulate a fatal error and restart it, the Due doesn't seem to receive heartbeat confirmation until it's reset as well.
Is there a clean way to reset just the one Serial connection from the Arduino script? I thought of using Serial.end() and Serial.begin() but that's really ugly and I'd prefer to avoid it. None of the other Serial library methods seem to provide the ability to reset the connection.
I'm using Serial2 at 115200 baud.
Edit: Including relevant heartbeat code:
#include &lt;DueTimer.h&gt;

bool heartbeat = true;

void rx_heartbeat() {
  int received_data;

  if (Serial2.available() &gt; 0) {
    received_data = Serial2.read();
    heartbeat = true;
    Serial.println(&quot;beat&quot;);
  }
}

void setup() {
  Serial2.begin(115200);
  Timer1.attachInterrupt(heartbeat_ISR).setFrequency(1).start();
}

void loop() {
  rx_heartbeat();
}

void heartbeat_ISR() {
  if (heartbeat) {
    heartbeat = false;
  } else {
    // no heartbeat returned - stop normal operation
  }
  Serial.println(&quot;heart&quot;);
  Serial2.write(255);
}
Silly me forgot to actually upload the code that fixed my issue. The code shown in the question is correct and works as intended.