PIC µController RS485 Network Protocol

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.

Packets

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.

Error Checking

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.

Bit Stuffing

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.

  1. a binary sequence of 11111 produces 111110
  2. a binary sequence of 00000 produces 000001
  3. a binary sequence of 11111111 produces 11111 0 111
  4. a binary sequence of 1111100000 produces 11111 0 0000 1 0

'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.

RS-485 Network - PIC µController - Home
Last updated - 29th July 2008
1