Skip to content

Modbus Diagnostic Restart Causes Slave Lockup

DodaTech Updated 2026-06-26 2 min read

In this tutorial, you'll learn about Modbus Diagnostic Restart Causes Slave Lockup. We cover key concepts, practical examples, and best practices.

The Problem

Modbus FC 08 sub-function 01 (Restart) causes the slave to become unresponsive.

Quick Fix

Wrong

// Restart slave with invalid option
mb.diagnostic(1, 0x0001, 0xFF00);  // Invalid restart option```

Slave restarts but with unexpected behavior or lockup.


### Right

```cpp
#include <ModbusRtu.h>

Modbus master(1, Serial, 2);

void setup() {
  Serial.begin(9600);
  master.begin(9600, SERIAL_8N1);
}

void attemptRestart(int slaveId) {
  Serial.print("Restarting slave ");
  Serial.println(slaveId);

  // Sub-function 01: Restart Communications Option
  // Data 0x0000: Restart with all counters cleared
  // Data 0xFF00: Restart with all counters preserved

  uint16_t diag[8];

  // First, save diagnostics
  master.diagnostic(slaveId, 0x0000, 0x0000, diag);

  // Send restart (clear all counters)
  int result = master.diagnostic(slaveId, 0x0001, 0x0000, diag);

  if (result == 0) {
    Serial.println("Restart command sent");

    // Wait for slave to reboot (typically 1-5 seconds)
    Serial.println("Waiting for slave to restart...");
    delay(3000);

    // Re-establish communication
    for (int attempt = 0; attempt < 5; attempt++) {
      uint16_t test;
      int r = master.readHoldingRegisters(slaveId, 0, 1, &test);
      if (r == 0) {
        Serial.println("Slave is back online");
        return;
      }
      Serial.print("Waiting... attempt ");
      Serial.println(attempt + 1);
      delay(1000);
    }
    Serial.println("Slave did not restart properly!");
  }
}

void loop() {
  attemptRestart(1);
  delay(30000);  // Wait 30 seconds between restarts
}```

Restarting slave 1 Restart command sent Waiting for slave to restart... Slave is back online


## Prevention

Modbus FC 08 sub-function 01 restarts the slave's communication. Data 0x0000 = restart with counters cleared. Data 0xFF00 = restart with counters preserved. After restart, the slave is offline for 1-5 seconds while the UART resets. Always wait 3+ seconds before retrying. Do NOT use on slaves that are actively controlling equipment — unexpected restart could cause unsafe states.

DodaTech engineers apply these same patterns across Doda Browser, DodaZIP, and Durga Antivirus Pro for production IoT reliability.

## FAQ

<details style="margin-bottom:12px;border:1px solid #e2e8f0;border-radius:10px;overflow:hidden"><summary style="cursor:pointer;padding:14px 18px;font-weight:600;font-size:1.05rem;background:#f8fafc;border-bottom:1px solid #e2e8f0;color:#1e293b">### What is the restart delay?</summary><div style="padding:14px 18px;color:#475569;line-height:1.7;background:#fff"><p>Most slaves restart in 1-3 seconds. Some industrial devices may take 10+ seconds. Start with 3s wait, increase if needed.</p>
<h3 id="can-restart-damage-equipment">Can restart damage equipment?</h3><p>Yes. A Modbus restart only affects the communication interface — the slave's controlled outputs may enter a safe (or unsafe) default state. Use with extreme caution on PLCs and motor drives.</p>
<h3 id="does-fc-08-restart-work-on-all-slaves">Does FC 08 restart work on all slaves?</h3><p>No. FC 08 is optional. Many slaves do not implement diagnostic functions. Check the device manual before attempting.</p>
</div></details>

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro