Software/RRController |
Note: This page describes work I did some time ago, resulting in an assembly language program that implements the described functionality. Time and technology has marched on, and there are better chips (PIC, AVR, etc.) for the purpose. Therefore, I have not posted the code for download; I maintain the page simply to describe the approach.
RRController is a specially programmed Motorola MC68HC705C8 microcontroller designed to be used as a building block in model railroad control applications. RRController is designed to function in a RS-422 network at a user-selected address, performing tasks specified by messages sent from a master controller. The message protocol used is the SYNC-SYNC-STX...ETX protocol specified in Dr. Bruce Chubb's book, "Build Your Own Universal Computer Interface." In response to master controller messages, RRControllers can provide dumps of selected portions of memory, execute microprocessor instructions, or load and execute "personality programs" that define processing to take place on the RRController. The RRController can continue to respond to master controller messages while a personality program is executing. This allows for RRControllers to be used in a wide variety of model railroad control applications with minimal development effort.
This section describes features of the MC68HC705C8 microcontroller specific to its use as a RRController. Please refer to the Motorola publications MC68HC705C8/D, "Technical Data," and M68HC05AG/AD "M68HC05 Applications Guide," for information on the basic microcontroller.
The RRController firmware makes special use of the following MC68HC705C8 pins:
| Pin Designations | Pin Numbers | Description | Usage |
| PD2-PD5,PD7 | 31-34,36 | Device Address | Provide DIP switch-settable device addresses from 0-31. |
| PC0 | 28 | Transmit Enable | Enable RS-422 transmitter. User must ensure that use of Port C does not interfere with operation of Transmit Enable. |
| RDI,TDO | 29,30 | Network Interface | Interfaces RRController to the master controller. The MC68HC705C8's Serial Communications Inteface (SCI) is not available for application use. |
The timer, IRQ, and SWI interrupts are available for use by personality programs. When the RRController is reset, the EPROM vectors for these interrupts are set to jump instructions located in the MC68HC705's high RAM. These jump instructions are initially set to jump to a NOP-RTI routine located in EPROM; the addresses can be changed by a personality program ('I' message) or an Exec message subroutine to point to a user interrupt handler loaded anywhere in RAM. The RAM addresses for these jump vectors are:
| Interrupt | Address | Description |
| TIMER | $0109 $010A |
TIMER JMP high-order byte TIMER JMP low-order byte |
| IRQ | $010C $010D |
IRQ JMP high-order byte IRQ JMP low-order byte |
| SWI | $010F $0110 |
SWI JMP high-order byte SWI JMP low-order byte |
The Serial Communications Interface (SCI) of the MC68HC705C8 is configured by the RRController firmware at RESET for 4800 baud, 8 data bits, 1 stop bit, and no parity. The Receive Interrupt Enable (RIE) bit is set, and the interrupt handler software tests for Receive Data Register Full (RDRF).
The RRController firmware implements the slave side of a master-slave message protocol based on Dr. Bruce Chubb's Universal Serial Interface Card (USIC) described in "Build Your Own Universal Computer Interface." The general format of messages is:
| Name | Range of Values | Description |
| SYNC | $FF | Syncronization byte. |
| SYNC | $FF | Syncronization byte. |
| STX | $02 | Start of message text. |
| DA (UA) | Dev Addr + $41 | RRController device address. (0-31) |
| MSGTYPE | 'I', 'P', 'R', 'E', 'U' | Message type |
| DATA... | 0-$FF | Bytes required by message type. |
| ETX | $03 | End of message. |
The firmware routines for message handling are interrupt driven; the interrupt architecture of the MC68HC705C8 saves the A and X registers on the stack before the routines are invoked, and returns their original values upon interrupt exit. Messages are stored in RAM starting with byte DA at $0111, except for 'I' messages; starting with DATA, they are stored in the low RAM starting at $30. RRController implements Data Link Escape (DLE) processing for DATA bytes as described in Dr. Chubb's book. Receipt of the ETX byte triggers processing based on the message type.
RRControllers implement the following message types:
| Message Type | Send/Receive | Message Name | Description |
| I | Receive | Initialization | DATA contains a personality program to which the RRController transfers execution based on the jump address. The personality program must fit within the available RAM between $30 and $FF, leaving room for the maximum anticipated stack size. |
| E | Receive | Execution | DATA contains a subroutine to be executed starting at $0113 of the message buffer. The last data byte must be an RTS instruction. RRController calls the subroutine; when the subroutine returns control, the firmware returns control to the personality program at the point where the interrupt occurred. |
| P | Receive | Poll | DATA contains a start byte and a stop byte corresponding to the section of memory to be returned in an 'R' message. Only memory from $00 to $FF can be returned this way. |
| R | Send | Receive | DATA contains the contents of memory from the start byte to the stop byte, inclusive, specified in a 'P' message. |
| U | Receive | User Command | No DATA, triggers the software interrupt (SWI). The software interrupt must be previously installed and its vector loaded into $010F. |
Using the message protocol described in section 2, RRControllers can be configured to perform almost any control activity required on a model railroad layout. Simple bit I/O applications do not require a personality program; 'E' messages are used to transmit subroutines to set and clear I/O port bits and bytes, and 'P' - 'R' message exchanges are used to retrieve I/O port input. Personality programs allow the RRController to handle logic based on local inputs, freeing the master controller from having to service the logic requirements of each individual port and/or bit.
RRController application development usually requires the following steps:
As of: 10:30 pm, 9 December 1998.
Questions? glenn_butcher@pcisys.net