micro_man
Joined: 05 Jun 2013 Posts: 14
|
CRC and Parity error indication |
Posted: Sat Aug 17, 2013 6:49 am |
|
|
Hi,
I am working on modbus 485 (RTU mode). I want to monitor the CRC and Parity Errors, how many times these error comes.
Is there any function in modbus driver file though which i come to know and then display these error counts?
thanks |
|
RF_Developer
Joined: 07 Feb 2011 Posts: 839
|
Re: CRC and Parity error indication |
Posted: Mon Aug 19, 2013 5:15 am |
|
|
micro_man wrote: |
I am working on modbus 485 (RTU mode). I want to monitor the CRC and Parity Errors, how many times these error comes.
Is there any function in modbus driver file though which i come to know and then display these error counts?
|
modbus.c works without parity and does no parity checks. Technically it doesn't meet the requirements of the Modbus spec, http://www.modbus.org/docs/Modbus_over_serial_line_V1_02.pdf . The spec requires 11 bit character frames, one start bit, eight data bits and two stop bits if parity is not used, or one parity and one stop bit if it is. modbus.c uses the more common 10 bit frame of one start, eight data, no parity bit and one stop bit, this though appears to be common practice. Its compatible with "no parity, two stop bits" provided the inter-character gap is at least one bit period. However, modbus.c will NOT work, without modifications, with modbus implementations that used parity. Parity is rare and essentially pointless with a message based CRC such as modbus uses. The "8-N-1" format is now so common and near-universal that its almost perverse not to support it. Modbus RTU should be "8-N-2" or "8-E-1" or even "8-O-1" as either parity is acceptable.
As for the CRC, my inspection of the modbus.c code shows it doesn't seem to explicitly check the CRC in the message decoding state machine as we might expect. In RTU mode, the end of a message frame is determined not by the structure of the message as would be the case with more recent protocols, but rather by the inter-message timeout of at least 3.5 character periods. So the place it detects CRC error is in modbus_timeout_now() which declares a received message as valid, or not, and set up for the next message. As it stands if there's a CRC error in a received message, then the message is simply ignored and no record of the error is made.
By the way, this is a classic situation when being able to see the pre-processed code, with all macros and conditionals resolved, would be an advantage. Instead I had to make use of the collapsing of conditionals feature of the CCS IDE's editor to hide modbus-ascii related code. |
|