RS485 Modbus Relay PRO (64, 12V, CN, None, A)
Contents
- 1 Overview
- 2 Wiring Instructions
- 3 Common Function Codes
- 4 Communication Parameters
- 5 Coil and Register Addresses
- 6 Frame Format
- 7 CRC Reference Implementation (C)
- 8 Online CRC Calculation
- 9 Communication Example Frames
- 9.1 01: Read Coil Status (Master Request)
- 9.2 01: Read Coil Status (Slave Response)
- 9.3 03: Read Holding Registers (Master Request)
- 9.4 03: Read Holding Registers (Slave Response)
- 9.5 05: Write Single Coil (Master Request / Slave Echo)
- 9.6 06: Write Single Register (Master Request / Slave Echo)
- 9.7 0F: Write Multiple Coils (Master Request / Slave Response)
- 9.8 10: Write Multiple Holding Registers (Master Request / Slave Response)
- 10 Batch Bit Control
- 11 Channel Work Mode Settings
- 12 Device Management and System Registers
- 13 Common Troubleshooting
- 14 Related Downloads
Overview
This device communicates over an RS‑485 half‑duplex bus using the Modbus RTU protocol. It supports common function codes for reading/writing coils and holding registers, and provides configuration for channel work modes, batch switching, timing/pulse functions, etc.
Wiring Instructions
- Connect the A terminal to the master/gateway's A (DI+). - Connect the B terminal to the master/gateway's B (DI-). - If there are many devices on the bus, it is recommended to add a 120 Ω termination resistor at the end of the bus. - When multiple devices are paralleled, keep the topology bus‑type as much as possible, avoid star topology. - Ground the shielding at one end only, and use twisted‑pair cables for communication lines.
Common Function Codes
Function Code | Function | Address Range | Bit/Word Operation | Quantity |
---|---|---|---|---|
01 | Read Coil Status | 0000H–0040H | Bit operation | Single or multiple |
03 | Read Holding Registers | 0000H–008FH | Word operation | Single or multiple |
05 | Write Single Coil | 0000H–0040H | Bit operation | Single |
06 | Write Single Holding Register | 0000H–008FH | Word operation | Single |
0F | Write Multiple Coils | 0000H–0040H | Bit operation | Multiple |
10 | Write Multiple Holding Registers | 0000H–008FH | Word operation | Multiple |
Communication Parameters
- Baud rate: default 38400, configurable (see register 0043H). Supported examples: 4800/9600/14400/19200/38400/56000/57600/115200. - Data bits: 8 - Parity: configurable (see register 0044H), 0=None, 1=Odd, 2=Even. - Stop bits: typically 2 when no parity, typically 1 with odd/even parity (depends on master and field). - Slave address range: 1–255 (see register 0042H).
Coil and Register Addresses
Coils (Coils, bit operation, function codes 01/05/0F)
- Range: 0000H–0040H (example). - 0000H…0007H: corresponds to relay channels 1…8. - Higher channels follow sequentially; for batch bit writes, the LSB corresponds to the starting address.
Holding Registers (Holding Registers, word operation, function codes 03 read / 06 write single / 10 write multiple)
Address (HEX) | Name / Function | Value / Description |
---|---|---|
0000H | Channel 1 control register (work mode and action) |
1) work_mode_normal: Normal mode, 1/0 = ON/OFF; 2) work_mode_flip: Toggle (flip) mode, "write 1 to toggle ON/OFF"; 3) work_mode_delay: Delay mode, delay N×0.01 s per operation; 4) work_mode_loop: Switch loop mode, period/count determined by holding time (see 0040H/0041H); 5) work_mode_auto_reset: Auto‑reset mode, automatically turns OFF after N×0.01 s, retains state after power loss. (The actual enumeration follows the definitions in channel mode registers starting at 0050H.) |
003FH | Channel 64 control register | same as above (channel index increments) |
0040H | Communication watchdog time setting | Watchdog time N × 0.1 s. 0: no watchdog; >1: when communication is lost, after N × 0.1 s all outputs are turned off; state is retained after power loss and takes effect after power‑on. |
0041H | Input report / action count setting | 0: no proactive reporting; 1: report immediately when any input window state changes; >1: accumulate and report/action after (N‑1)×0.01 s; retains after power loss, effective after power‑on. |
0042H | Slave address | 1–255; example read = 1; retained after power loss, effective after restart. |
0043H | RS‑485 baud rate | 0:4800, 1:9600, 2:14400, 3:19200, 4:38400, 5:56000, 6:57600, 7:115200; retained after power loss, effective after restart. |
0044H | Parity | 0: None, 1: Odd, 2: Even; retained after power loss, effective after restart. |
0045H | Relay batch control | 1: all ON; 0: all OFF. |
0046H | Bit control channels 1–16 | bit=1 output ON, bit=0 OFF. |
0046H | Bit control channels 17–32 | bit=1 output ON, bit=0 OFF. |
0048H | Bit control channels 33–48 | bit=1 output ON, bit=0 OFF. |
0049H | Bit control channels 49–64 | bit=1 output ON, bit=0 OFF. |
004AH | Software reset | Write 1 to execute reset; after reset this bit automatically returns to 0. |
004BH–004FH | Reserved | — |
0050H | Channel 1 work mode | 0: normal; 1: toggle; 2: timed; 3: switch loop; 4: auto reset. |
… | … | … |
008FH | Channel 64 work mode | same as above, 0: normal; 1: toggle; 2: timed; 3: switch loop; 4: auto reset. |
Frame Format
- Frame format: Address (1 B) + Function Code (1 B) + Data (N B) + CRC16 (low byte first, high byte second). - Inter‑frame interval: ≥3.5 character times (RTU specification). - CRC: polynomial 0xA001, initial value 0xFFFF (see code below).
CRC Reference Implementation (C)
uint16_t factory_crc16(uint8_t* bufData, uint16_t buflen)
{
uint16_t TCPCRC = 0xFFFF;
uint16_t POLYNOMIAL = 0xA001;
uint8_t i, j;
for (i = 0; i < buflen; i++)
{
TCPCRC ^= bufData[i];
for (j = 0; j < 8; j++)
{
if ((TCPCRC & 0x0001) != 0)
{
TCPCRC >>= 1;
TCPCRC ^= POLYNOMIAL;
}
else
{
TCPCRC >>= 1;
}
}
}
return TCPCRC;
}
Online CRC Calculation
Communication Example Frames
01: Read Coil Status (Master Request)
Read start address 000AH, quantity 000AH (example)
01 01 00 0A 00 0A 9C 0F
01: Read Coil Status (Slave Response)
Returns 2‑byte bitmap: 000AH–0011H, 0012H–0019H (example)
01 01 02 F0 03 BD FD
03: Read Holding Registers (Master Request)
Read 2 registers starting from 0002H (example)
01 03 00 02 00 02 C4 0B
03: Read Holding Registers (Slave Response)
Returns 4‑byte data: registers 0000H/0001H (example values)
01 03 04 F0 C3 A0 4F 00 FB
05: Write Single Coil (Master Request / Slave Echo)
Set coil 000AH ON (FF00 = ON)
01 05 00 0A FF 00 AC 38
01 05 00 0A FF 00 AC 38
06: Write Single Register (Master Request / Slave Echo)
Write register 0013H = 0x15C2 (example)
01 06 00 13 15 C2 F7 0E
01 06 00 13 15 C2 F7 0E
0F: Write Multiple Coils (Master Request / Slave Response)
Write 10 coils starting at 000AH, total 2 bytes (example)
01 0F 00 0A 00 0A 02 AA 0A 1A F3
01 0F 00 0A 00 0A 1A F3
10: Write Multiple Holding Registers (Master Request / Slave Response)
Write 2 registers starting at 0013H, total 4 bytes (example values 0x1253, 0x3C1F)
01 10 00 13 00 02 04 12 53 3C 1F 17 17
01 10 00 13 00 02 B0 0D
Batch Bit Control
- 0046H–004FH: control channels 1–16 (bit=1 turns output ON). - 0048H: control 33–48; 0049H: control 49–64. - 0045H: batch all‑ON/all‑OFF (1=ON, 0=OFF).
Channel Work Mode Settings
- Starting at 0050H, each channel occupies 1 word; example enumeration:
- 0: normal mode (direct ON/OFF). - 1: toggle mode (write 1 to toggle). - 2: timed mode (configured with 0040H/0041H). - 3: switch loop mode. - 4: auto‑reset mode (automatically turns OFF after timeout).
- 008FH: channel 64 work mode.
Device Management and System Registers
- 0042H: slave address (1–255), retained after power loss, effective after restart.
- 0043H: baud rate (enumeration as above), retained after power loss, effective after restart.
- 0044H: parity (0/1/2), retained after power loss, effective after restart.
- 004AH: software reset (write 1 to execute, bit returns to 0 after reset).
Common Troubleshooting
- No response:
- Verify that slave address, baud rate, and parity match the master. - Check that A/B lines are not reversed; ensure termination resistor on the bus. - Increase master timeout and retry count.
- CRC error:
- Ensure CRC low byte is first; confirm no extra spaces/separators in the frame. - Try lowering baud rate, check shielding and grounding.
- Intermittent frame loss:
- Extend inter‑frame interval, optimize transmit/receive switching timing. - Investigate power supply and common‑ground issues.
Related Downloads
1. DIUSTOU serial Modbus relay debugging software
This software requires a USB‑to‑RS485 module.
2. pymodbus example files, requires Python 3.7+ and the pymodbus package:
pip install pymodbus