RX/TX hold registers: 64-bytes FIFOs for send/receive
RX/TX level registers: FIFO status
Track/Train Interface
USEFUL: turn on the headlights! (verify communication and direction)
train speed: 0-14; 15 for reverse (add 16 to turn on lights)
model trains simulate real-world stopping by gradually slowing down
we want to preserve this important characteristic
⇒ do not directly reverse rolling train!
turnout commands: straight (0x21), curved (0x22)
NOTE: the middle turnouts should always be set to S/C or C/S → avoid C/C, S/S
special command: turn off (last) solenoid 0x020
IMPORTANT: After sending a turnout command, you must wait at least 100ms and at most 500ms. Then, either switch another turnout (which automatically turns off the previous solenoid) or explicitly turn off the last solenoid!
sensors: query some/all; tracks have 5x16 sensors
set reset mode (single command byte 0xC0)
read reports after query
IMPORTANT: track communication is half-duplex, i.e., no contro
can use extra serial cable to connect gtkterm to RPi Channel 2 for debugging
Software Design
polling loop
for (;;) {
if (c1) a1();
if (c2) a2();
...
}
vs. busy wait
for (;;) {
while (!c1);
a1();
while (!c2);
a2();
...
}