/*
* SPI protocol:
*
- * A command is stored on 2 bytes. The first one has its msb to 0, and the
- * second one to 1. The first received byte contains the command number, and the
- * msb of the servo value. The second byte contains the lsb of the servo value.
+ * A command is stored on 2 bytes (except command 0). The first byte
+ * has its most significant bit to 0, and the second one to 1. The
+ * first received byte contains the command number, and the msb of the
+ * servo value. The second byte contains the lsb of the servo value.
*
- * Commands 0 to NB_SERVO are to set the value of servo.
+ * Command 0 is only one byte long, it means "I have nothing to say".
+ * Commands 1 to NB_SERVO+1 are to set the value of servo.
* Command 14 is to enable bypass mode.
* Command 15 is to disable bypass mode.
*/
if (rxidx == 0) {
byte0.u8 = c;
+
+ /* command num 0 is ignored */
+ if (byte0.cmd_num == 0)
+ return;
}
else {
uint16_t val;
/* process command */
- if (byte0.cmd_num < NB_SERVO) {
+ if (byte0.cmd_num < NB_SERVO+1) {
val = (uint16_t)byte0.val_msb << 7;
val += byte1.val_lsb;
- servo_table[byte0.cmd_num].command = val;
+ servo_table[byte0.cmd_num-1].command = val;
}
else if (byte0.cmd_num == BYPASS_ENABLE) {
bypass = 1;