modbus-Register and Function code learning

Source: Internet
Author: User
Tags function definition command access

Classification

Referred

Start Address

End Address

function codes that can be used

Output logic coil/(read/write bit)/(DI/O) (e.g. relay switch control )

0x

00000

09999

0X01 read a set of logic coils

0X05 Write a single coil

0x0f Write multiple coils

Contacts/ Switch inputs /read-only bits (DI) If the key is pressed

1x

10000

19999

0X02 read a set of switch inputs

Input register (AI) real-time data such as AD capture data .

3x

30000

39999

0X04 read one or more input registers

Hold Register (AI/O)

such as the various parameters set

4x

40000

49999

0X03 read the value of one or more hold registers

0X06 Write single hold Register

0x10 Write multiple hold Registers

0x01: Read a set of logic coils, such as read 8 relay output states.

0x0F: Write a set of logic coils. If you control 8 relays simultaneously

0x05: write a single logic coil, such as setting a single relay

0x02: read the input of a set of switching volume, such as whether the Reading Display board has a button press, water flow switch state.

0x03: read one or more hold registers, such as reading one or more setting parameters

0x010: Write one or more hold registers, such as write set parameters

0x06: Write a single hold register, such as write a single set parameter

0x04: read one or more input registers, such as reading specific key values, ad-collected information, etc.

Modbus protocol function codes and FAQs

Pasted from

1 SCM Development and the similarities and differences between the development of PLC:

Modbus protocol is specifically for 485 bus equipment (Example PLC) development, the definition of register to strictly according to its address range; Function code function definition and definition of the register address and function code to be strictly in line with. Such as.

And when the microcontroller development with the serial port point to point, may not fully comply with the Modbus protocol specifically embodied in 2 aspects:

The first is the definition of the Register address range, should be combined with the size of different microcontroller RAM and the actual requirements of the project to define the starting range and size. method, such as defining an array of different functions in different areas of the Ram area:

IOX[N]: Output coil for relay operation

IX[M]: Switch input, used to identify whether the key presses the query.

Other: The use of function code is not strictly limited to the specified PLC address range.

Description of the address of the 2modbus register:

There are two sets of rules, a set called a PLC address, for a 5-bit decimal number, for example 40001,PLC address 40001 means that the parameter type is hold register. The other is the protocol address, the protocol address is 0x0000, which has a correspondence, remove the highest position of the PLC address, and then the remaining minus 1. This will be a problem, the PLC address 30002 and the PLC address 40002 of the protocol address is the same as 0x0001, when access is not a conflict at this time. Yes, of course not. 30001 for the input register, 04 command access is required, and 40001 is the hold register, which can be accessed using 03, 06, and 16 commands. Note that the defined register address is the same as the array starting from 0, that is, the address in the communication is smaller than the actual address "1"

Http://blog.sina.com.cn/s/blog_6ab9638f0100vqol.html

3 Coil Register: Bits register that can be individually bit controlled, similar to C51 's bit-band structure

Typedef struct

{

bit:0

Bit:1

..

Bit:14

Bit:15

}coil_reg

Http://blog.sina.com.cn/s/blog_598b27cd0101rphm.html

4modbus Frame structure:

ADU: Application Data unit

PUD: Protocol Data Unit

How to determine the end of a frame in Freemodbus

The Modbus protocol does not have a distinct start and Terminator, but is judged by the time interval between frames and frames T3.5. More than T3.5 is considered to have received a new frame. Next, you can

To deal with the data, the first is to judge the legitimacy of the frame. Modbus through time to determine whether the frame to accept the completion of the natural need for a single-chip timer in conjunction.

Use the serial port to send complete interrupts: Avoid losing the last byte content

Pasted from

modbus-Register and Function code learning

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.