Modbus Exception Code 04 (Slave Failure) on Valid Request
DodaTech
Updated 2026-06-26
2 min read
In this tutorial, you'll learn about Modbus Exception Code 04 (Slave Failure) on Valid Request. We cover key concepts, practical examples, and best practices.
The Problem
Modbus slave returns Exception Code 04 (Server/Device Failure) for a seemingly valid request.
Quick Fix
Wrong
// Valid request but slave returns exception 04
mb.readHoldingRegisters(1, 0, 10, data);
// Returns: 0x84 (128 | 0x04 = exception 04)```
Exception 04: Server/Device Failure. Slave encountered internal error.
### Right
```cpp
#include <ModbusRtu.h>
Modbus master(1, Serial, 2);
void handleModbusError(int errCode, int fc, int addr) {
switch (errCode) {
case 1:
Serial.println("Exception 01: Illegal Function (FC not supported)");
break;
case 2:
Serial.println("Exception 02: Illegal Data Address");
break;
case 3:
Serial.println("Exception 03: Illegal Data Value");
break;
case 4:
Serial.println("Exception 04: Slave Device Failure");
Serial.println(" - Power cycle the slave");
Serial.println(" - Check for hardware faults");
Serial.println(" - Verify bus wiring (reflections, noise)");
// Retry with retry count
break;
case 5:
Serial.println("Exception 05: Acknowledge (processing, retry later)");
break;
case 6:
Serial.println("Exception 06: Slave Device Busy (retry later)");
break;
case 8:
Serial.println("Exception 08: Memory Parity Error");
break;
case 10:
Serial.println("Exception 10: Gateway Path Unavailable");
break;
case 11:
Serial.println("Exception 11: Gateway Target No Response");
break;
}
}
void loop() {
uint16_t data[10];
int result = mb.readHoldingRegisters(1, 0, 10, data);
if (result > 0) {
handleModbusError(result, 3, 0);
// Retry with delay
delay(100);
result = mb.readHoldingRegisters(1, 0, 10, data);
}
delay(2000);
}```
Exception 04: Slave Device Failure
- Power cycle the slave
- Check for hardware faults
- Verify bus wiring [Retry after 100ms] Request succeeded on retry.
## Prevention
Modbus exception codes: 01=Illegal Function, 02=Illegal Data Address, 03=Illegal Data Value, 04=Slave Device Failure, 05=Acknowledge (processing), 06=Slave Device Busy, 08=Memory Parity Error, 10=Gateway Path Unavailable, 11=Gateway Target No Response. Exception 04 indicates a hardware or firmware fault. Power cycle the device, check connections, and verify power supply. Exception 05/06 can be retried with delay.
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">### Exception 01 vs 02 vs 03?</summary><div style="padding:14px 18px;color:#475569;line-height:1.7;background:#fff"><p>01 = Function code not supported by this slave. 02 = The address doesn't exist. 03 = The data value/quantity is out of range. Common: 02 for wrong register address.</p>
<h3 id="what-causes-exception-04">What causes exception 04?</h3><p>Hardware failure, EEPROM write error, sensor fault, power supply brownout, or firmware crash. Check device status via diagnostic commands.</p>
<h3 id="how-to-handle-exception-06">How to handle exception 06?</h3><p>Slave is busy (e.g., writing to EEPROM). Retry after 50-100ms. If persistent, the slave may be in a fault state.</p>
</div></details>
← Previous
Modbus Diagnostic Restart Causes Slave Lockup
Next →
Modbus Read Holding Registers Returns Exception Code 02
Built by the developers of DodaTech
Doda Browser, DodaZIP & Durga Antivirus Pro