~ 14 ~
NOVATEK-ELECTRO
PEF-
321АВР
Bytes are transmitted at speed of 2400, 4800, 9600, 14400 and 19200 bps. By default, during manufacture,
the device is configured to operate at a speed of 9600 bps.
Note
-
for
MODBUS RTU
mode, 8 data bits are transmitted, and for
MODBUS ASCII
mode, - 7 data bits are
transmitted.
6.3.2.2 Frame format
In the
MODBUS RTU
mode, the start and end of the frame are controlled using silence intervals of at least
3.5 bytes transmission time. The frame should be transmitted as a continuous stream of bytes. The correctness
of the frame acceptance is further controlled by checking the CRC checksum.
The address field takes up one byte. Addresses of the slave devices are in the range from 1 to 247.
Figure 9 shows the RTU frame format.
Silence interval
>3.5 bytes
Address
Function code
Data
CRC checksum
Silence interval
>3.5 bytes
1 byte
1 byte
Up to 50 bytes
2 bytes
Fig. 9
- RTU frame format
In the
MODBUS ASCII
mode, the start and end of the frame are controlled using special characters (symbol
(„:‟ 0x3A) – to start the frame; characters („CRLF‟ 0x0D0x0A) – to end the frame). The frame should be
transmitted as a continuous stream of bytes. The correctness of the frame acceptance is further controlled by
checking the LRC checksum.
The address field takes up two bytes. Addresses of the slave devices are in the range from 1 to 247.
Figure 10 shows the ASCII frame format.
:
1 byte
Address
Function code
Data
CRC checksum
CRLF
2 bytes
2 bytes
2 bytes
Up to 504 bytes
2 bytes
Fig. 10
- ASCII frame format
Note -
in the
MODBUS ASCII
mode, each byte of data is encoded with two bytes of ASCII code (for example:
1 byte of data 0x25 is encoded with two bytes of ASCII code 0x32 and 0x35).
6.3.3 Generation and verification of a checksum
The transmitting device generates a checksum for all bytes of the transmitted message. 321
АВР similarly
generates a checksum for all bytes of the received message and compares it with the checksum received from
the transmitting device. If the generated checksum does not match the accepted one, an error message is
generated.
6.3.3.1 CRC checksum generation
The checksum in the message is transmitted in the lower byte forward; it is a cyclic check code based on the
irreducible polynomial 0xA001.
The subroutine for generating CRC checksum is in C language:
1: uint16_t GenerateCRC(uint8_t *p
СendRecvBuf, uint16_t uCount)
2: {
3: con
с uint16_t Polynom = 0xA001;
4: uint16_t crc = 0xFFFF;
5: uint16_t i;
6: uint8_t byte;
7: for(i=0; i<(uCount-2); i++){
8: crc = crc ^ p
СendRecvBuf[i];
9: for(byte=0; byte<8; byte++){
10: if((crc& 0x0001) == 0){
11: crc = crc>> 1;
12: }el
сe{
13: crc = crc>> 1;
14: crc = crc ^ Polynom;
15: }
16: }
17: }
18: returncrc;
19: }
6.3.3.2 LRC checksum generation
The checksum in the message is transmitted in high byte forward, which is a longitudinal redundancy check.