Support » Qik 2s15v9 User’s Guide » 4. Serial Interface »
4.c. Command Protocols
Once the Qik has entered the normal operation phase, you can control it by issuing serial commands. If your Qik is set to automatically detect the baud, you must first send it the byte 0xAA (170 in decimal) in order to exit autodetect mode and enter normal operation.
The Qik serial command protocol is fairly simple. 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. they range from 128 – 255, or 0x80 – 0xFF in hex) while data bytes always have their most significant bits cleared (i.e. they range from 0 – 127, or 0x00 – 0x7F in hex). This means that each data byte can only transmit seven bits of information.
One significant improvement over earlier Pololu serial controllers is the Qik’s error handling, which allows the user to specify responses to serial errors (including unknown commands, incorrectly formatted commands, and hardware-level serial errors), motor fault errors, and motor over-current errors. The Qik has a configuration parameter that determines if the motors shut down when various errors occur, but the Qik itself continues running and accepting commands.
The Qik responds to two sub-protocols:
This is the simpler and more compact of the two protocols; it is the protocol you should use if your Qik is the only device connected to your serial line. The Qik compact protocol command packet is simply:
command byte (with MSB set), any necessary data bytes
For example, if we want to set motor M1 to full speed forward using the compact protocol, we could send the following byte sequence:
in hex: 0x8D, 0x7F
in decimal: 141, 127
The byte 0x8D is a command for M1 forward, and the data byte contains the motor speed. Note that every Qik command byte starts with 0x8_ or 0x9_ when using the compact protocol.
This protocol is compatible with the serial protocol used by our other serial motor and servo controllers. As such, you can daisy-chain a Qik on a single serial line along with our other serial controllers (including additional Qiks) and, using this protocol, send commands specifically to the desired Qik without confusing the other devices on the line.
The Pololu protocol is to transmit 0xAA (170 in decimal) as the first (command) byte, followed by a device-number data byte. The default device number for the Qik is 10, but this is a configuration parameter you can change. Any Qik on the line whose device number matches the specified device number accepts the command that follows; all other Pololu devices ignore the command. The remaining bytes in the command packet are the same as the compact protocol command packet you would send, with one key difference: Therefore, the command packet is:
0xAA, device # byte, command byte , any necessary data bytes
For example, if we want to set motor M1 to full speed forward for a Qik with device number 10, we could send the following byte sequence:
in hex: 0xAA, 0x0A, 0x0D, 0x7F
in decimal: 170, 10, 13, 127
Note that 0x0D is the command 0x8D with its most significant bit cleared. Since all compact-protocol command bytes start with 0x8n or 0x9n, these bytes all turn into data bytes 0x0n or 0x1n, respectively.
The Qik responds to both the Pololu and Compact protocols on the fly; you do not need to use a jumper or configuration parameter to identify which protocol you are using.
Procedure for Daisy-Chaining
Daisy-chaining multiple Qiks together on the same serial line is simple. Individually assign each Qik a different device ID using the set configuration parameter command (see Section 5.d), and then connect your TTL serial transmit line to each Qik’s RX line or your RS-232 serial transmit line to each Qik’s SIN line. If you wish, you can connect all of the Qiks’ ERR lines to a single input on your controlling module. When you issue your first Pololu-protocol command, the Qiks all automatically detect the baud from the initial 0xAA byte.
Connecting multiple serial outputs to one serial input is more complicated. Each device only transmits when requested, so if each unit is addressed separately, multiple units will not transmit simultaneously. However, the outputs are driven, so they cannot simply be wired together. Instead, you can use an AND gate (since the idle state is high).
If you want to daisy-chain a Qik with other Pololu devices that use 0x80 as an initial command byte, the procedure becomes slightly more complicated. You should first transmit the byte 0x80 so that these devices can automatically detect the baud rate, and only then should you send the byte 0xAA so that the Qik can detect the baud rate. Once all devices have detected the baud rate, Pololu devices that expect a leading command byte of 0x80 should ignore command packets that start with 0xAA, and Qiks will ignore command packets that start with 0x80.