qihaoxu / arduino-modbus-slave

Automatically exported from code.google.com/p/arduino-modbus-slave
0 stars 0 forks source link

Uncommon serial setup #1

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
When using your library on a Arduino DUE with a RS485 sheelt I had the 
following problems:

Message framing detection did not work. The MODBUS I connect to runs at 57600 
bps. This results in modbusSlave::_frameDelay being set to 0. For all MODBUS 
messages I received the first byte was detected as a frame of only one byte 
length. All messages were then rejected as having invalid CRC.

I think the calculation is even broken for slower MODBUS buses. The current 
code calculates the time considered as a frame gap as 24000/baud (milli 
seconds). This seems to be calculated as 3 characters of 8 bit length each. But 
on the one hand a character has a length of 11 bit and on the other hand the 
spec defines the frame to be at least 3.5 characters in length. Therefore I 
think the correct division would be 38500/baud (milli seconds).

I also think, that it is incorrect to setup the serial port as 8N1. The 
required to implement mode is 8E1 (having an even parity bit). No-parity is 
allowed, but is a MAY in the specification and you need an extra stop bit in 
that case resulting in 8N2.

Original issue reported on code.google.com by m...@tthias.eu on 23 Oct 2013 at 11:15