The RS-485 network protocol layer defines the structure of the packets used in communication between the µControllers.
The 'idle' state of an RS485 network is deemed to be a logic 1 (HIGH). This is when all modules are in receive mode.
The protocol is packet based where a packet can be directed to either all receivers or addressed to a group. The protocol does not require acknowledgement of receipt of a packet at this level.
The message packet is defined as:
S M {} T
Where:
S | : | the Low [0] start bit |
M | : | the packet type indicator bit |
T | : | the High [1] stop bit |
The message in the {} part of the packet and can be an Addressed or a Broadcast message depending on the value of M:
When M = 0, this is an Addressed message and takes the form:
{ Adr Len Dat [ Dat ... ] Err }
When M = 1 this is a Broadcast message and takes the form:
{ Len Dat [ Dat ... ] Err }
Where:
Adr | : | the 4 address bits of the destination (allows 16 addressable destinations) |
Len | : | the 4 bits representing the number of data nibbles that follow (allows 1-16 data nibbles) |
Dat | : | the 4 data bits of the nibble. The number of nibbles is defined by the Len. |
Err | : | the 4 error bits. |
The implied maximum buffer size is 10 bytes.
The Stop bit is not checked. It is there to frame the packet and it is not used or parsed.
The error detection scheme is very simple. Each message consists of a sequence of nibbles. Each nibble is X-ORed with the previous result and the resulting nibble rotated by a bit. The initial result value is 1101. The result is compared with Err and if they do NOT match, the packet is discarded.
Layered onto the protocol is Bit Stuffing. What this means is that a sequence of 5 like bits (including any stuffing) causes an opposite bit to be 'stuffed', e.g.
'De-stuffing' occurs before the packet is processed and the message is parsed.
A sequence of 6 or more like bits indicates an error. The packet is discarded and the error condition remains until 6 consecutive 1 (High) bits is subsequently detected indicating an idle line.