Modbus RTU FC04 Read Input Registers Frame & CRC-16 Builder

Assemble Function Code 0x04 Read Input Registers Modbus RTU hex packets for energy meters and sensors with CRC-16 and RS-485 timing.

Jump to results

Inputs

Frame mode & addressing
1–247 unicast, 0 broadcast.
Zero-based protocol PDU address (0–65535).
Count for reads, 0 or 1 for FC05, or a 16-bit value for FC06.
Raw validation & RS-485 bus

Results

Estimates
Modbus RTU Frame (Hex)01 04 00 10 00 02 70 0E
Computed CRC-16
0x0E70
Wire CRC order (Lo Hi)
70 0E
Slave ID & Function
ID 1 · Read Input Registers (0x04)
Frame length / air time
8 bytes · 9.17 ms
Inter-char timeout (t1.5)
1,719 µs
Frame silent gap (t3.5)
4,010 µs
RTU frame byte map · 8 bytes
B0 01 B1 04 B2 00 B3 10 B4 00 B5 02 B6 70 B7 0E CRC-16/MODBUS: 0x0E70 · Wire order: 70 0E (Lo → Hi)
  • Slave ID
  • Function Code
  • Address / Payload
  • CRC-16 Lo / Hi
Frame field breakdown
FieldBytes (Hex)Byte count
Slave ID011
Func 0x04041
Address00 102
Quantity00 022
CRC Lo701
CRC Hi0E1
Copyable C99 & Python 3 CRC-16/MODBUS functions
#include <stddef.h>
#include <stdint.h>

/* CRC-16/MODBUS: init 0xFFFF, reflected polynomial 0xA001, wire order Lo then Hi */
uint16_t modbus_crc16(const uint8_t *buf, size_t len) {
  uint16_t crc = 0xFFFFU;
  for (size_t i = 0; i < len; ++i) {
    crc ^= (uint16_t)buf[i];
    for (int bit = 0; bit < 8; ++bit) {
      if (crc & 0x0001U) crc = (uint16_t)((crc >> 1) ^ 0xA001U);
      else crc >>= 1;
    }
  }
  return crc;
}

/* Test vector: 01 04 00 10 00 02 70 0E (CRC=0x0E70, wire: 0x70 0x0E) */
static const uint8_t frame_pdu[6] = { 0x01, 0x04, 0x00, 0x10, 0x00, 0x02 };
def modbus_crc16(data: bytes) -> int:
    crc = 0xFFFF
    for b in data:
        crc ^= b
        for _ in range(8):
            crc = ((crc >> 1) ^ 0xA001) if (crc & 1) else (crc >> 1)
    return crc & 0xFFFF

pdu = bytes.fromhex("01 04 00 10 00 02")
crc = modbus_crc16(pdu)
rtu_frame = pdu + crc.to_bytes(2, "little")
assert rtu_frame.hex(" ").upper() == "01 04 00 10 00 02 70 0E"
print(rtu_frame.hex(" ").upper())

Modbus RTU transmits the CRC low byte first, followed by the high byte, whereas multi-byte register addresses and values are big-endian.

Poll read-only telemetry with Modbus FC04 Input Registers

Smart AC energy meters (such as SDM120/SDM630), temperature transmitters and flow sensors expose live read-only measurements in the 3xxxx Input Register bank accessed via Function Code 0x04.

Many sensors pack IEEE-754 32-bit floats across two consecutive 16-bit registers (quantity = 2). Generate the exact 8-byte hex poll packet and CRC-16 here.

Formulas

  • FC04 PDU = [ID, 0x04, Addr_Hi, Addr_Lo, Qty_Hi, Qty_Lo]
  • 32-bit float telemetry = 2 contiguous input registers (4 payload bytes)
  • CRC wire order: CRC_Lo followed by CRC_Hi

Worked example

Reading 2 input registers at address 0x0010 (16) from Slave 1 builds `01 04 00 10 00 02 70 0E` (CRC = 0x0E70).

Frequently asked questions

What is the difference between FC03 Holding Registers and FC04 Input Registers?

FC03 reads read/write configuration and status registers (4xxxx space), while FC04 reads read-only sensor/measurement registers (3xxxx space).

Why do I get Exception Code 0x02 (Illegal Data Address) on FC04?

Either the register belongs to FC03 instead of FC04, or your quantity crosses an unmapped register gap or splits a 32-bit register pair.

How long should a master wait for an FC04 slave reply?

Typical RS-485 field devices respond within 10–100 ms; set a conservative 300–500 ms response timeout before retrying.