ABCDEFGHIJKLMNOPQRSTUVWXYZ
1
MODBUS Protocol
2
3
4
1. Introduction
5
MODBUS MCCB Protocol
6
7
8
2. Physical Layer
9
Communication port : RS485
10
Asynchronous format : Each character is composed of 10 bit.
11
(1 start bit + 8 data bits + 1 stop bit)
12
Baud rate : 19200 bps
13
Data Bits : 8 bits
14
Parity : No parity
15
Stop Bits : 1 bits
16
Master-Slave method: Only master is qualified for requesting,
17
while slave delivers the requested data and response to the required performance according to inquiry.
18
19
20
21
3. Data Link Layer
22
if master delivers the request frame, slave does the response frame.
23
Each frame is differenciated by dead time.
24
General form to send and receive frames is as follows:
25
26
DESCRIPTIONSIZE
27
SLAVE ADDRESS1 byte
28
FUNCTION CODE1 byte
29
DATAN byte
30
CRC2 byte
31
DEAD TIME3.5 bytes transmission time
32
33
MasterRequestResponseSlave
34
Slave addressDevice AddressDevice AddressSelf-address
35
Definition of slave action Function CodeFunction CodeEcho or MSB=1
36
Additional information to perform the requested action DataDataRequested data or
exception code
37
38
39
CRCError checkError checkCRC
40
41
SLAVE ADDRESS
42
Valid slave device address range : 0~247 decimal
43
Slave device address range in practice : 1~32 decimal
44
If the range of slave device address of the requested frame by master is 0, it means that
45
master device bradcasts to all slaves.
46
In case that master requests to slave, fill the relative slave address in address field and send it.
47
If slave responses to master, fill its own adress in address field and send it.
48
49
FUNCTION CODE
50
Valid range : 1~255
51
normal : 1~127, error : 129 ~ 255(normal + 0x80)
52
It defines slave's requested action by master.
53
Slave enters the following.
54
In case of normal response: Echo the function code requested, as it stands.
55
In case of exceptjonal response: Set to 1 as MSB of the function code requested and fill it in.
56
57
DATA
58
Register address
59
Amount of items to be handled
60
The number of byte of actual data
61
62
CRC
63
Error checking method.
64
CRC-16
65
CRC Generation Function
66
67
unsigned short CRC16(puchMsg, usDataLen)
68
unsigned char *puchMsg ; /* message to calculate CRC upon */
69
unsigned short usDataLen ; /* quantity of bytes in message */
70
{
71
unsigned char uchCRCHi = 0xFF ; /* high byte of CRC initialized */
72
unsigned char uchCRCLo = 0xFF ; /* low byte of CRC initialized */
73
unsigned uIndex ; /* will index into CRC lookup table */
74
75
while (usDataLen––) /* pass through message buffer */
76
{
77
uIndex = uchCRCHi ^ *puchMsgg++ ; /* calculate the CRC */
78
uchCRCHi = uchCRCLo ^ auchCRCHi[uIndex} ;
79
uchCRCLo = auchCRCLo[uIndex] ;
80
}
81
82
return (uchCRCHi << 8 | uchCRCLo) ;
83
}
84
85
86
DEAD TIME
87
Frame is completed only when it has silent interval more than 3.5 character time after receiving the last character.
88
1 character time is approximately 0.5ms since BPS is 19200
89
(700ms to1000ms is recommended for the interval of master's request.)
90
91
4. MODBUS Exception Codes
92
93
codeName
94
0x01ILLEGAL FUNCTION
95
0x02ILLEGAL DATA ADDRESS
96
0x03ILLEGAL DATA VALUE
97
0x04SLAVE DEVICE FAILURE
98
0x10No data for event/fault record
99
0x11SBO TIME OUT
100
0x12ILLEGAL ADU LENGTH