5. The Serial Interface
- 5.a. Serial Communication Settings
- 5.b. Serial Command Protocols
- 5.c. Serial Command List and Documentation
- 5.d. Configuration Parameter List and Documentation
- 5.e. Cyclic Redundancy Check (CRC) Error Detection
- 5.f. CRC-Generation Algorithm in C
- 5.g. Resetting the Serial Communication Parameters
You can use the serial interface for four general purposes: querying the TReX for information (any mode), setting its configuration parameters (serial mode only), sending it motor commands (any mode), and upgrading its firmware (must be in firmware-upgrade mode). Firmware upgrading is addressed in Section 6.
Serial motor commands are accepted in any mode, but they will only immediately affect the motors if the TReX is in serial mode or channel 5 has serial override active. When the TReX is in RC or analog mode and serial override is not active, the most recently received serial motor command for each motor is buffered. These buffered motor commands take effect if serial override becomes active.
Note that when you are using the serial interface, it is crucial that you do not transmit to the TReX while it is transmitting to you. Because of the way the RS-232 circuit is tied to the logic-level serial lines, the TReX can sometimes get its transmissions echoed back to itself. It deals with this by ignoring its receive line while it is transmitting, so anything you send it during this time will be lost. As a consequence, the TReX will never transmit anything over the serial line without your first explicitly asking it to. The high-level protocol for sending commands that cause the TReX to transmit data back to you should be as follows:
- Transmit command packet that causes the TReX to send data back to you
- Wait for all the expected data to be received or for a reasonable timeout period
- Transmit your next command packet
Motor commands are strictly one-way; the TReX will not send data back in response to these. All other commands result in two-way data transfer.
An additional consequence of the RS-232 circuit is everything you send to the TReX using the RS-232 connection will be echoed back to you as you’re transmitting it (RS-232 transmit and receive lines are physically tied together by a resistor). If you are connecting your TReX to a COM port, you can either disable your receiver while you transmit or you can simply discard the echoed bytes you know to expect. The command packet echo will always arrive before any data the TReX sends to you. Note that you will receive no echo if you use the logic level (TTL) serial lines to communicate with the TReX.