RS-bus feedback

Introduction

The decoders described at this site can communicate to a LENZ master station via the RS feedback bus. A piggy-back print (see picture below, left) for RS-bus slaves has therefore been designed that can easily be mounted on all decoder prints (the picture below at the right shows a switch decoder with an AVR32A processor and a RS-feedback print, as well as a switch decoder with an AVR8535 processor without feedback print). These feedback prints are used for normal feed-back information (such as the position of switches or track occupancy), similar to prints from other manufacturers, but can also transmit the values of the decoders internal Configuration Variables (CVs) during CV programming.

RS-Bus basics

A detailed description of the RS-bus is provided by the der-moba website (in German); below is just a summary of that info.

Physical layer: The RS-bus is a master-slave bus. The master is implemented in the command station (like a Lenz LZ100) and the slaves are implemented in the decoders. The master is connected to the slaves via a bus consisting of two-wires, which are twisted to reduce possible interference. Data over the bus is transferred as current pulses, instead of voltage levels. The advantage of using current pulses instead of voltage levels, is the better protection against interference. The current sources are implemented in the slaves; a 20mA current source for sending and a 3 mA source for reception. Since the duty cycle of the pulses is roughly 50% (a complete pulse takes 200µs; thigh=93µs and tlow=107µs), the average load per slave is roughly 1,5 mA.

Access control: The RS-bus is one directional: data bytes can be send from a slave (decoder) to the master, but the master can not send data bytes to the slaves. A maximum of 128 slaves can be connected to the same master station. To determine which slave is allowed to send next (multiple access), the master sends sequences of 130 pulses. To allow slaves to detect the start of the pulse sequence, the master is silent for a period of 7ms. Each slave counts the number of pulses after the period of silence, and when this count corresponds to the RS-bus address of the slave, the slave starts sending a start bit followed by eight data bits (sending all bits takes 1,875 ms, which corresponds to 4800 baud). The master detects that the slave is sending, and transmission of the subsequent access control pulses is postponed till the slave is ready.

Data format: Although RS-bus slaves can send eight bits of user data, only four of these bits can be used for the actual feedback data. Such collection of four feedback bits is called a nibble. A track occupancy decoder that wants to send feedback information regarding eight tracks, should therefore send such information in two nibbles. The remaining four bits of each data byte are used for control purposes: the first bit determines the parity, the second and third bit determines the type of feedback decoder and the fourth bit determines whether the first or second nibble is being transmitted.

The fact that four feedback bits are included per data byte, may have unexpected side effects, particularly in case of switches. For details, see the page on feedback problems.

Software

The recommended software for new designs is the Arduino RS-Bus Library, which can be found on GitHub. That library can be used for standard MEGA328 (UNO, Nano) and MEGA2560 Arduino boards, as well "Mighty Core" processor based boards (MEGA 8535, 16A, 32A, 164A, 324A and 644A). It uses:

  • INTx (any interrupt pin) to receive RS-bus polling pulses from the command station,

  • TXD/TXDx (the/an USART) to send RS-bus messages to the command station,

  • the Arduino micros() function.

Earlier software

For the "pre-Arduino" decoders described on this site, the RS-Bus software is already included in the decoder software. That software can be retrieved from my GitHub homepage, as well as the switch decoder's download section.

Note that this "early" software runs only on MEGA8535, 16A, 32A, 164A, 324A, 644A and pin compatible AVRs, and uses the following pins and timers:

  • PD2=INT0: used to receive RS-bus information from the command station

  • PD1=TXD/TXD0: used to send RS-bus information to the command station (UART / UART2)

  • 8-bit Timer/Counter2