About MODBUS 2

2014-08-25


The "About MODBUS 1" 1 is for MODBUS at OSI level 7, this part from "MODBUS over Serial Line Specification and Implementation Guide" which is for MODBUS at OSI level 1 & 2.

MODBUS Serial Line protocol is a Master-Slave protocol.

image

A MODBUS communication is always initiated by the master. The slave nodes will never transmit data without receiving a request from the master node. The slave nodes will never communicate with each other. The master node initiates only one MODBUS transaction at the same time

image.

image

CRC:

CRC Generation Function

unsigned short CRC16 ( puchMsg, usDataLen ) /* The function returns the CRC as a unsigned short type */ 
unsigned char *puchMsg ; /* message to calculate CRC upon */ 
unsigned short usDataLen ; /* quantity of bytes in message */ 
{ 
unsigned char uchCRCHi = 0xFF ; /* high byte of CRC initialized */ 
unsigned char uchCRCLo = 0xFF ; /* low byte of CRC initialized */ 
unsigned uIndex ; /* will index into CRC lookup table */ 
while (usDataLen--) /* pass through message buffer */ 
{ 
uIndex = uchCRCLo ^ *puchMsg++ ; /* calculate the CRC */ 
uchCRCLo = uchCRCHi ^ auchCRCHi[uIndex] ; 
uchCRCHi = auchCRCLo[uIndex] ; 
} 
return (uchCRCHi << 8 | uchCRCLo) ; 
}

( From MODBUS over Serial Line Specification and Implementation Guide V1.02 )

See Also

1: About Modbus 1
2: About Modbus 3