beautypg.com

The serial interface, A. serial communication settings, B. serial command protocols – Pololu TReX Jr User Manual

Page 16

background image

5. The Serial Interface

You can use the serial interface for four general purposes: querying the TReX Jr 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 Jr is
in serial mode or channel 5 has serial override active. When the TReX Jr 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 Jr while it is
transmitting to you. Because of the way the RS-232 circuit is tied to the logic-level serial lines, the TReX Jr 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 Jr 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 Jr to transmit data back to you should be as follows:

1. Transmit command packet that causes the TReX Jr to send data back to you

2. Wait for all the expected data to be received or for a reasonable timeout period

3. Transmit your next command packet

Motor commands are strictly one-way; the TReX Jr 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 Jr 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 Jr 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 Jr sends to you. Note that you will receive no echo if you use the logic level
(TTL) serial lines to communicate with the TReX Jr.

5.a. Serial Communication Settings
Unlike our other Pololu serial controllers, the TReX Jr does not support automatic baud detection. Instead, you can
configure the TReX Jr to run at one of 11 common baud rates ranging from 1200 to 115,200 bits per second. The
TReX Jr ships with a default baud rate of 19,200 bps.

The TReX Jr allows you to optionally select one of three different kinds of error detection to help you ensure the
integrity of your communications: even parity, odd parity, or 7-bit cyclic redundancy checking (CRC-7). Cyclic
redundancy checking is explained in more detail in Section 5.e. The default setting is no error detection.

Lastly, you can specify whether serial communication with the TReX Jr will use one or two stop bits. The default
setting is one stop bit.

These serial settings are controlled by a single “serial-settings” configuration parameter (see Section 5.d for more
information).

5.b. Serial Command Protocols
The TReX Jr serial command protocol is fairly straightforward. Communication is achieved by sending command
packets consisting of a single command byte followed by any data bytes that command requires. Command bytes
always have their most significant bits set (i.e. range from 128 – 255) while data bytes always have their most

Pololu TReX Jr User's Guide

© 2001–2009 Pololu Corporation

5. The Serial Interface

Page 16 of 23