RS422 Device Bus Protocol

[ introduction | generic protocol | devices ]


1. Introduction

This document describes the protocol used on the RS422 bus that connects various devices around the house. It also lists the (known) devices and their supported commands.


2. Generic Protocol

The following figure shows the general structure of a packet on the RS422 bus:

general packet structure

The first byte is the length of the packet, inclusive of itself and the checksum byte at the end of the packet. The checksum is the sum (modulo 256) of all the preceeding bytes in the packet.

The LUN is the device logical unit number (abbreviation shamelessly lifted from SCSI terminology). There are two special LUN values: 0x00 is the LUN of the bus-master for a particular bus (typically the PC via RS232/RS422 bridge); 0xff is the broadcast LUN.

Broadcast packets contain the generic protocol described here. Packets directed at a specific LUN are considered to be device-specific. Packets sent to the bus-master LUN are nearly always reply packets, from either the generic or device-specific protocols.

Generic protocol packets have the following structure:

generic protocol packet structure

The following table lists the currently supported values for cmd:

0x00device discovery, used to find new devices
0x01device soft reset, used to reset devices on the bus
0x80device address assign, used to assign LUN values
0x81device ping, used to ping devices
0x82device identity, used to retrieve the identity of a device
0x83device raw command, used to control a device without a LUN

To make device programming slightly simpler, any generic command that has the high-bit set requires a device-ID match. That device-ID is contained in the 4 bytes following the command byte.

2.1. Device Discovery

The device-discover command (0x00) is used to locate new devices (or existing devices without a LUN set). The packet sent has the following structure:

generic protocol discovery packet

Devices respond after a reasonably variable delay, based on their device-ID). The response sent by a device is similar to that of the device-identify command; in this case the response has the structure:

generic protocol discovery response packet

2.2. Device Soft-Reset

The soft-reset command (0x01) is used to reset all devices on the bus. This is only good for devices that are still responding to the system, however. The packet sent has the following structure:

generic protocol soft-reset packet

2.3. Device Address-Assign

The device-address-assign command (0x80) is used to assign LUN values to devices. The packet sent has the following structure:

generic protocol address-assignment packet

The device-ID must match the device's own ID. The response sent by a device is largely the same, except that the (first) LUN value will be 0x00 and not 0xff. The response is largely an acknowledgement to ensure that a device's LUN has indeed been changed.

2.4. Device Ping

The device-ping command (0x81) is used to test the existence of a device. The packet sent has the following structure:

generic protocol ping packet

The device-ID must match the device's own ID. The response sent by a device is largely the same, except that the LUN value will be 0x00 and not 0xff.

2.5. Device Identity

The device-identify command (0x82) is used to retrieve the device identity for a device:

generic protocol device-id packet

The response from a device has the following format:

generic protocol device-id response packet

2.6. Device Raw Command

The device-raw-command command (0x83) is used to control a device that does not have a LUN set:

generic protocol device control packet


3. Devices

Various supported devices and IDs:

0x80010000test unit
0x80020001temperature sensor (machine room)
0x80020002temperature sensor (utility room)
0x80020003temperature sensor (front room)
0x80020004temperature sensor (kitchen)
0x80020005temperature sensor (outside)
0x80030000remote IR remote
0x80040000AVR programmer
0x80050001pulse sensor (electicity and gas monitoring)
0x80060001general I/O device
0x800700014-character display
0x800800018-character display
0x80090001bus power manager
0x8010000116-character display
0x80110001transmitter test device
0x80120001train controller device
0x80130001train driver device

3.1. Test Unit Commands

CommandResponseDescription
00reset counter
01xxset counter to xx
02enable periodic messages
03disable periodic messages

3.2. Temperature Sensor Commands

CommandResponseDescription
00set normal operation
01calibrate high (30 ^C) value
02calibrate low (0 ^C) value
03nn03xxxxyyread temperature and aux counters, originating LUN in nn, temperature count in xxxx, auxillary count in yy
04nn04set normal operation and acknowledge, originating LUN in nn
05nn05calibrate high (30 ^C) value and acknowledge, originating LUN in nn
06nn06calibrate low (0 ^C) value and acknowledge, originating LUN in nn

3.3. Remote IR Remote Commands

CommandResponseDescription
00xxyytransmit RC5 codeset xx (0-31), command yy (0-63)
01xxset RC5 transmit frequency constant to xx (default is 6f)
02nn02xxget RC5 transmit frequency constant, originating LUN in nn, frequency value in xx

3.4. AVR Programmer Commands

CommandResponseDescription
00initialise programmer
01shut-down programmer
03nn03xxyyread aux counters, originating LUN in nn, aux1 count in xx, aux2 count in yy
to be completed

3.5. Pulse Sensor Commands

CommandResponseDescription
00clear counters
01nn01xxxxxxyyyyyyread and clear counters, originating LUN in nn, counter 1 value in xxxxxx and counter 2 value in yyyyyy

3.6. General I/O Device Commands

CommandResponseDescription
00xxoutput xx on the 8-bit port
01nn01xxread 8-bit port data, originating LUN in nn, data in xx
to be completed

3.7. 4-character Display Commands

CommandResponseDescription
00clear display
01aabbcc...set display text (max. 44 chars)
02enable scrolling
03disable scrolling
04xxset scroll speed to xx
05xxset display offset to xx

3.8. 8-character Display Commands

CommandResponseDescription
00clear display
01aabbcc...set display text (max. 44 chars)
02enable scrolling
03disable scrolling
04xxset scroll speed to xx
05xxset display offset to xx

3.9. Bus Power Manager Commands

CommandResponseDescription
0000ssssget device status
010101turn on socket A
010201turn off socket A
010301disable socket A cold-start
0104xx01enable socket A cold-start after (15 * xx) seconds
020102turn on socket B
020202turn off socket B
020302disable socket B cold-start
0204xx02enable socket B cold-start after (15 * xx) seconds
0301power-cycle bus
0304xx03enable bus cold-start after xx seconds

3.10. 16-character Display Commands

The ATMega8 device that this currently runs on has plenty of internal memory (1k SRAM). The maximum supported message size is around 496 bytes. To get the whole message in, it must be uploaded in 64-byte chunks, which makes the protocol handling a little odd.

CommandResponseDescription
00clear display
01nn aabbcc...set text segment nn (0-7) to text aabbcc.. (max 64 chars at a time)
02enable scrolling
03disable scrolling
04xxset scroll speed to xx
05xxset display offset to xx
06xxset high display offset to xx
07hhllroll display to offset hh ll
08xxset scroll start offset to xx (0-15)

3.11. Transmitter Test Device Commands

This device doesn't respond to any particular commands: it just transmits a general message to the host (about once per second). It will respond correctly to generic commands, to have its LUN set, etc.

3.12. Train Controller Commands

This device has (in theory) 4x 8-bit output ports and 4x 8-bit input ports, wired up to various sensors and indicators.

CommandResponseDescription
00disable input polling
01enable input polling
02 xxset polling speed to xx
03 pp vvset output port pp to vv
04 pp vv ww hhll jjkktimed port output, after hhll ms set port pp to vv, hold for jjkk ms then set to ww
05 ppppvvccread input port pp, value returned in vv, changed bits indicated in cc
06cancel any in-progress timed port output
07 pp vv ww mm hhll jjkkmasked timed port output, after hhll ms set port pp bits mm to vv, hold for jjkk ms then set to ww mask mm; unmasked bits are not affected
08aabbccdd vvwwxxyyread all input ports (reported in aabbccdd), without clearing change bits (reported in vvwwxxyy)
09clear all input port change bits
0a pp vv mmset output port pp to vv with mask mm

3.13. Train Driver Commands

This device is driven by remote RS422-over-RF (433 MHz), currently an input-only device so needs device-specific generic commands.

CommandResponseDescription
00all stop
01ahead half for 1.5s
02ahead full for 1.5s
03reverse half for 1.5s
04reverse full for 1.5s


Last modified 21st August 2007 by Fred Barnes (http://frmb.org/).