Modbus RTU protocol questions

J

Thread Starter

Jesper

Hi

I'm reading them modbus over serial line - Specification and implementation guide. It says

"The format ( 11 bits ) for each byte in RTU mode is:

Coding system:
8-bit binary
Bits per byte:
1 start bit
8 data bits, least significant bit sent first
1 bit for parity completion
1 stop bit"

My 1st question is:
Do I need to send 11 bits for each 8 bit byte, including the slave address, functioncode and CRC, or is it only the data part that needs start, stop and parity bits (wich would be my guess)?

My 2nd question is:
When calculating the CRC cheksum I discard the start, stop and parity bits correct?

My 3rd question is:
How does the start and stop bits work? Are they always high or always low, or are they calculated somehow?

My 4th question is:
The guide says that the data part can be up to 252bytes maximum, does that include the start, stop and parity bits?

As you can see, I am a little confused.
Hope that you can help me.

 
Start, stop, and parity bits are added to your data words by the UART. Your program will never see them. You just have to setup the UART with the stop, start, and parity settings you want. The UART will generate an error code for bad parity or framing that will let you know that the message got garbled.

You do not <b>have</b> to use 11 bit words for Modbus. There are a lot of DCEs that will only support 10 bit words. 9600, 8, N, 1 will work fine.

 
>My 1st question:

ANS: For RTU mode there is No Parity. RTU mode uses CRC error checking. An example poll, polling Address 17, register 40123 for 4 registers:
HEX POLL: 11 03 00 7a 00 40 67 40.
The 0x67 and 0x40 are the crc bytes.

>My 2nd question:

ANS: The crc calc is at the end of a poll or response inclusive of all bytes in the poll/response, each byte is 8 bits. The start and stop bits are not included in the crc calculation.

>My 3rd question:

ANS: The UART takes charge of the start bit, stop bit and baud rate. In RS232 signals the start bit is always HIGH and the stop bit is always LOW which is the inverted UART signal accomplished by the RS232 interface drivers and receivers. UART stands for "Universal Async Receiver Transmitter". The UART is a hardware chip.

>My 4th question:

ANS: They mean 252 bytes where the first 8 bit byte would be the slave address, the second byte is the function code, the third byte is the number of data bytes to follow (247 in your example) and the last two bytes are the crc for the previous 250 bytes.

You are confusing the 8 bit bytes which your program sends to or receives from the UART and the 10 bytes which the UART sends to or receives from the wires.....
 
Thank's for your replies.

This makes things a lot clearer. I now get the start, stop and parity bits, and that I don't need to be concerned with them.

I'm sure that I'm going to have a lot more questions, and I know now where to ask :)
 
The guide actually says "The maximum size of a modbus frame is 256 bytes". This refers to the slave address (1 byte), the function code (1 byte), the data (0-252 bytes) and the CRC (low and hi, 2 bytes)
 
Top