Modbus TCP Server Not Responding to Requests
DodaTech
Updated 2026-06-26
1 min read
In this tutorial, you'll learn about Modbus TCP Server Not Responding to Requests. We cover key concepts, practical examples, and best practices.
The Problem
Modbus TCP server is running but does not respond to client requests.
Quick Fix
Wrong
#include <ModbusIP.h>
ModbusIP mb;
// Server not configured to provide register data```
Server accepts TCP connections but returns exception responses to all requests.
### Right
```cpp
#include <Ethernet.h>
#include <ModbusIP.h>
ModbusIP mb;
// Holding register array
uint16_t holdingRegs[100];
void setup() {
Serial.begin(9600);
Ethernet.begin(mac, ip);
// Configure holding registers (Function Code 03)
for (int i = 0; i < 10; i++) {
holdingRegs[i] = i * 100; // Initial values
}
// Add register areas
mb.addHreg(0, holdingRegs, 100); // Starting address 0, 100 registers
mb.addIreg(0, 10); // Input registers (FC 04)
mb.addCoil(0, 16); // Coils (FC 01/05/15)
// Start Modbus TCP server
mb.server();
Serial.println("Modbus TCP server on port 502");
}
void loop() {
mb.task();
}```
Client reads Holding Register 0 → 0, Register 1 → 100, ... Register 9 → 900
## Prevention
Modbus TCP server must register its data areas (holding registers, input registers, coils) before serving. Use addHreg() for holding registers (FC 03/06/16), addIreg() for input registers (FC 04), addCoil() for coils (FC 01/05/15). The server processes requests via mb.task() in the main loop. Register count and starting addresses must match client expectations.
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">### AddHreg vs AddIreg?</summary><div style="padding:14px 18px;color:#475569;line-height:1.7;background:#fff"><p>addHreg() is for holding registers (read/write, FC 03/06/16). addIreg() is for input registers (read-only, FC 04). Both store uint16_t values.</p>
<h3 id="how-many-registers-can-i-add">How many registers can I add?</h3><p>Depends on RAM. Typical limit: ~1000 holding registers on <a href="/iot/arduino/">Arduino</a> Mega (8 KB RAM). ESP32 can handle 10000+.</p>
<h3 id="do-i-need-mbtask-in-the-loop">Do I need mb.task() in the loop?</h3><p>Yes. mb.task() processes incoming requests and sends responses. Without it, the server never responds.</p>
</div></details>
← Previous
Modbus Slave Not Responding to Master
Next →
Modbus TCP Connection Refused — Complete Guide
Built by the developers of DodaTech
Doda Browser, DodaZIP & Durga Antivirus Pro