LK3U/ZK3U RS485 Communication port Description

Functional description

You can change the value of D8400/D8420 to select MODBUS-RTU protocol, RS free port protocol (RS485-1), RS2 free port protocol (RS485-2), and select the corresponding communication parameters. (When the PLC stops running, switch to the programming port protocol)

RS485-1/RS485-2 communication port default programming port protocol, communication parameters: 19200, 7, E, 1.

RS485 Communication Parameter Setting Table

You can calculate it yourself through the following table, or automatically calculate it through auxiliary software

LK Assist Tool

D8400 (RS485-1) / D8420 (RS485-2) Parameter Settings Table

Bit PositionDescription0 (bit=0FF)1 (bit=ON)Notes
bit0Data Length7 bits8 bits
bit1Parity ModeNo parityParity enabled0 – No parity, 1 – Parity
bit2Parity TypeOdd (ODD)Even (EVEN)0 – Odd, 1 – Even
bit3Stop Bits1 stop bit2 stop bits
bit4Baud Rate (low bits)3009600
bit5Baud Rate (middle bits)60019200
bit6Baud Rate (high bits)120038400
bit7Baud Rate (highest bits)240057600
bit8~bit11DisabledSet to 0
bit12FX Programming Port ProtocolDisabledFX Protocol0 – No protocol, 1 – Protocol
bit13RS Communication (RS485-1 specific)DisabledEnabled RS485-1
bit14MODBUS-RTU ProtocolDisabledEnabled
bit15DisabledSet to 0

Additional Notes:

  1. When the data length is set to 7 bits, parity cannot be set to “No parity”, otherwise error code 6304 will occur.
  2. For Programming Port Protocol, the fixed parameters are: data length is 7 bits, 1 stop bit, and even parity. Baud rate can be configured.
  3. For MODBUS-RTU protocol, RS free port protocol, and RS2 free port protocol, all parameters (data length, stop bits, parity, baud rate) can be configured.
  4. If D8400 or D8420 does not have MODBUS-RTU master functionality enabled and the ADPRW instruction is used, error code 6706 will occur.
  5. D8401/D8421 set to H0 selects the MODBUS master protocol.
  6. D8401/D8421 set to H10 selects the MODBUS slave protocol.

RS485 MODBUS RTU Commands Special M and D Register Function Description

MODBUS-RTU Master/Slave Protocol Supported Function Codes

FunctionCommandSupported Soft Element TypesBit ElementsWord Elements
Bit Read Command1 (H1), 2 (H2)X, Y, M, S, T, C, Special MX, Y, M, S, T, C, Special M
Bit Write Command5 (H5)Y, M, S, T, C, Special MY, M, S, T, C, Special M
Register Read Command3 (H3), 4 (H4)X, Y, M, S, T, C, Special MX, Y, M, S, T, C, Special MD, T, C, Special D
Register Write Command6 (H6)Y, M, S, T, C, Special MY, M, S, T, C, Special MD, T, C, Special D
Register Batch Write Command16 (H10)Y, M, S, T, C, Special MY, M, S, T, C, Special MD, T, C, Special D

RS485-1 / RS485-2 ADPRW Instruction (MODBUS-RTU Protocol) Special M Relay Function Description

RS485-1RS485-2NameActive StationDetailed DescriptionAttribute
M8410RS485-1/2 ADPRW Instruction SwitchingMaster StationOFF: RS485-1 uses the ADPRW instruction.
ON: RS485-2 uses the ADPRW instruction.
R/W
M8029Instruction Execution CompleteMaster StationOFF: The instruction is not being executed or is not yet completed.
ON: The instruction has been completed.
R
M8401M8421MODBUS Communication ActiveMaster StationON: MODBUS communication is active.R
M8402M8422MODBUS Communication Error OccurredMaster/SlaveON: MODBUS communication error occurred.R
M8403M8423MODBUS Communication Error LatchedMaster/SlaveON: MODBUS communication error latched when an error occurs.R
M8408M8428Retry OccurredMaster StationON: Set when the slave station does not respond in time and the master station sends a retry.R
M8409M8429Timeout OccurredMaster StationON: Set when a response timeout occurs.R

RS485-1 / RS485-2 ADPRW Instruction (MODBUS-RTU Protocol) Special D Register Functions

RS485-1RS485-2NameActive StationDetailed DescriptionAttribute
D8400D8420Protocol Selection and Communication ParametersMaster/SlaveSets the communication format.
R/W: Value H0 selects MODBUS master protocol.
R/W
D8401D8421MODBUS Protocol SelectionMaster/SlaveR/W: Value H10 (K16) selects MODBUS slave protocol.R/W
D8402D8422Communication Error CodeMaster/SlaveStores the latest error code encountered during MODBUS communication.R
D8403D8423Error DetailsMaster/SlaveStores detailed information about the most recent error.R
D8404D8424Step Number of Communication ErrorMaster StationStores the step number of the first ADPRW instruction where an error occurred.R
D8407D8427Step Number during CommunicationMaster StationStores the step number of the ADPRW instruction during communication.
If not executed, stores 0.
R
D8408D8428Current Retry CountMaster StationStores the current retry count when communication retries are triggered due to slave response timeout.R
D8409D8429Slave Response TimeoutMaster StationIf the slave does not respond within the set time, it retries the request or considers it a timeout.R/W
Setting range: 0–32767, 1=10ms.
Timeout is 3 seconds if set to 0.
D8410D8431Send DelayMaster/SlaveDelay before sending data back after receiving it.
Setting range: 0–16382, 1=1ms. Default: 10ms.
R/W
D8412D8432Retry CountMaster StationNumber of retries if the slave fails to respond in the specified timeout period.
Range: 0–20 times.
R/W
D8414D8434Slave Station NumberSlave StationStores the slave station number.
Range: 1–247.
R/W
D8063D8438Serial Communication Error CodeMaster/SlaveStores the error code corresponding to the serial communication error that occurred.R
D8419D8439Operation Mode DisplayMaster/Slave0: FX programming port communication
4: RS command
5: RS2 command
19: MODBUS master
29: MODBUS slave
R

MODSBU RTU Description (Master)

MODBUS RTU Master Program Download

Preparation

  1. Prepare the equipment:
    • A USB-to-RS485 communication cable to connect the computer to the slave device.
    • A serial debugging tool (such as a serial assistant or any similar software).
  2. Install drivers:
    • Connect the USB-to-RS485 cable to the computer and install the corresponding USB driver to ensure the communication port (COM port) is recognized by the computer in the device manager.
  3. Check hardware connections:
    • Ensure that the wiring of the USB-to-RS485 cable is correct, with the A and B terminals properly connected to the RS485 interface of the slave device.

Procedure

Open the serial assistant:

Open the serial assistant software on the computer and select the COM port corresponding to the USB-to-RS485 cable.

Set the communication parameters (baud rate, data bits, stop bits, parity, etc.) to match the slave device. Common MODBUS RTU parameters are:

Baud rate: 9600 or 19200

Data bits: 8 bits

Stop bits: 1 stop bit

Parity: None or Even

Send MODBUS RTU messages:

Use the serial assistant to send the required MODBUS RTU messages to the slave device. You can start by sending a simple query (like reading a register) to test the communication.

Ensure the format of the message is correct. For example, to read a register, the function code is 0x03, and the message structure should include the slave address, function code, data length, CRC checksum, etc.

Monitor the returned messages:

After sending the message, the serial assistant should display the response message from the slave device. This allows you to verify whether the returned data matches your expectations (e.g., whether the slave has successfully responded or if the message format is correct).

If there is no response or an error message is returned, the issue may be with the communication parameters or wiring.

Verify communication parameters and wiring:

If no expected response is received, use the serial assistant to send simple messages step by step to monitor the communication on the RS485 bus and troubleshoot issues with communication parameters or wiring.

Connect to PLC:

Use the USB-to-RS485 cable to connect the PC to the PLC. If an additional 232 port is required, prepare a USB-to-RS232 cable.

Download the appropriate PLC test program (e.g., 485-1 master or 485-2 master case) and load the corresponding PLC program based on the required communication port.

Modify PLC communication parameters:

Set the communication parameters in the PLC program to match those of the slave device.

Use the PLC’s read/write instruction (e.g., ADPRW) to communicate with the slave device by sending read and write commands.

Monitor the messages from the PLC:

After downloading the PLC program to the PLC, power off, and power it back on to ensure the PLC has fully initialized.

When you enable the M0 bit in the PLC, the serial assistant should show the MODBUS RTU messages sent from the PLC, allowing you to verify whether the messages are as expected.

Adjust and confirm successful communication:

If the communication messages between the PLC and the slave device are correct, and the data can be successfully read and written, the communication parameters and wiring are confirmed to be correct.

If the messages are not as expected, continue monitoring with the serial assistant and adjust the communication parameters until successful communication is achieved.

MODSBU RTU Description (Slave)

3U Series MODBUS RTU Slave Case Download

Selecting the Appropriate Communication Port

  1. Using Port 2 as the PLC Slave:
    • Choose the 485-2 MODBUS RTU slave program.
    • Download the sample program directly without modifications.
  2. Using Port 1 as the PLC Slave:
    • Choose the 485-1 MODBUS RTU slave program.
    • Similarly, download the sample program directly without modifications.

Debugging Process

1. Check Communication Parameters and Wiring:
  • If no response is received in the receive area after sending a message, first check whether the communication parameters (baud rate, data bits, stop bits, parity, etc.) between the master and slave are consistent.
  • Ensure that the wiring is correct, particularly the A and B lines of the RS485 connection.
2. Download the PLC Program:
  • After downloading the PLC program to the PLC, power off the PLC and wait for all indicator lights to turn off completely. Then power it back on to ensure the PLC has been reset properly.
3. Check the PLC’s Running Status:
  • When the PLC’s RUN light starts flashing, it indicates the PLC is in RUN mode. If the Y0 light is illuminated, this indicates communication has been successful. You can reset the PLC, and if the Y0 light turns off, it confirms that the MODBUS RTU slave configuration is successful.
4. Use the LK Auxiliary Tool for Communication Testing:
  • If no response is received after sending a message, use the serial assistant to debug and ensure the message format is correct, and the communication parameters match.
5. Example Communication Messages:
  • Reading Data from the PLC:
    • Serial send: 01 03 00 00 00 01 84 0A
    • PLC response: 01 03 81 80 42 6E F0
  • Writing Data to the PLC (Write 8 to D0 register):
    • Serial send: 01 06 00 00 00 08 88 0C
    • PLC response: 01 06 00 00 00 08 88 0C
  • Setting Y0 to 1:
    • Serial send: 01 05 33 00 FF 00 83 7E
    • PLC response: 01 05 33 00 FF 00 83 7E

Debugging the PLC Slave Communication Using a Serial Assistant

Configure the Serial Assistant:

Open the serial assistant and select the COM port that corresponds to the communication port used by the PLC.

Set the communication parameters (baud rate, data bits, stop bits, parity, etc.) to match those of the PLC slave.

Send MODBUS RTU Messages:

Use the serial assistant to send messages formatted according to the MODBUS RTU protocol. For example, you can send a read or write message to test the response from the PLC slave.

Check the Returned Messages:

If the PLC correctly receives the message from the master, it will return a corresponding response message. You can then debug and confirm whether the response is as expected based on the data returned.

MODBUS RTU (slave address correspondence table)

  1. Address Representation:
    • In PLCs, addresses are often represented in hexadecimal, while SCADA systems (such as Kingview) or HMIs typically display addresses in decimal.
    • Example:
      • Y0 in PLC has a hexadecimal address of 0x3300, which equals 13056 in decimal.
  2. Address Offset (+1 Adjustment):
    • In some communication protocols (e.g., MODBUS), the starting address is 1-based, meaning the first register starts from 1, not 0.
    • As a result, when configuring the upper-level system (SCADA/HMI), you need to add 1 to the PLC’s internal address.
    • Example:
      • Y0 in PLC: 13056 (decimal).
      • In SCADA: the address would be 13057 (after adding 1).
Bit vs. Word Elements and Address Mapping
  1. Bit Elements (M Area):
    • Bit elements are stored individually, with each address representing 1 bit.
    • Example:
      • M0-M7679 corresponds to hexadecimal addresses 0x0000-0x1DFF.
      • A total of 7,679 bits are stored, with each address occupying 1 bit.
  2. Word Elements (D Area):
    • Word elements are stored as 16-bit registers. Each address in the word element refers to a block of 16 bits (or 2 bytes).
    • Example:
      • D0 has an address of 0x0000 (decimal 0).
      • D10 has an address of 0x000A (decimal 10).
  3. Address Overlap:
    • Bit and word elements may appear to overlap in address ranges, but they are stored differently:
      • Bit elements are accessed individually by bit.
      • Word elements are accessed in blocks of 16 bits.
    • Different function codes are used for reading and writing bit elements versus word elements, even if their addresses seem similar.
Register Address Calculation
  1. Example Address Range:
    • If the register address range is from 0xA478 to 0xA657, there are 481 registers in total.
    • Since each register holds 16 bits, the total number of bits is:
      • 481 * 16 = 7679 bits, which corresponds to the M0-M7679 bit elements range.
RS485-1/RS485-2 MODBUS-RTU slave protocol soft component addresses:
Component TypePLC Component AddressMODBUS-RTU Address (Hex)Address RangeRead/Write
Bit ComponentsM0~M76790x0000~0x1DFF0~7679Read-Only
M8000~M85110x1E00~0x1FFF8000~8511Read/Write
S0~S40950x2000~0x2FFF0~4095Read/Write
TS0~TS5110x3000~0x31FF0~511Read/Write
CS0~CS2550x3200~0x32FF0~255Read/Write
Y0~Y3770x3300~0x33FF0~377Read/Write
X0~X3770x3400~0x34FF0~377Read/Write
Word ComponentsD0~D79990x0000~0x1F3F0~7999Read-Only
D8000~D85110x1F40~0x213F8000~8511Read/Write
TN0~TN5110xA140~0xA33F0~511Read/Write
CN0~CN1990xA340~0xA4070~199Read/Write
CN200~CN255 (32-bit)0xA408~0xA477200~255Read/Write
M0~M76790xA478~0xA6570~7679Read/Write
M8000~M85110xA658~0xA6778000~8511Read/Write
S0~S40950xA678~0xA7770~4095Read/Write
TS0~TS5110xA778~0xA7970~511Read/Write
CS0~CS2550xA798~0xA7A70~255Read/Write
Y0~Y3770xA7A8~0xA7B70~377Read/Write
X0~X3770xA7B8~0xA7C70~377Read/Write

RS program

Program includes 485-1RS 485-2RS

RS Freeport Program Download

RS485-1 (RS Command) Special M Relays and D Registers

Relay/RegisterFunction
M8401RS command sending in progress indicator
M8402RS command sending request indicator
M8403RS command receiving completion indicator
M8409Communication timeout indicator
M81618/16-bit processing mode (ON = 8-bit, OFF = 16-bit)
D8400Protocol selection and communication parameter setting
D8402RS command sent data remainder
D8403Number of RS command received data
D8409RS command reception timeout setting (1 = 10ms)
D8419Indicator of protocol currently executing on port

RS485-2 (RS2 Command) Special M Relays and D Registers

Relay/RegisterFunction
M8421RS2 command sending in progress indicator
M8422RS2 command sending request indicator
M8423RS2 command receiving completion indicator
M8429Communication timeout indicator
D8420Protocol selection and communication parameter setting
D8422RS2 command sent data remainder
D8423Number of RS2 command received data
D8429RS2 command reception timeout setting (1 = 10ms)
D8439Indicator of protocol currently executing on port

MODBURTU Application Reference Program

Leave a Comment