TWiki > RisePrivate Web>StickyBotForceController? >CommProtocolCommands (21 Apr 2007, MarkCutkosky)

PC to PIC communication commands

ALERT! This page is a working page and thus the details will frequently change

The following table holds the commands (in case of ambiguity, the hexidecimal number has priority over the decimal number.):

Command Name Hex Dec Description Implemented?
Start of upload 0x01 1 Signals the start of an upload. Yes
Block upload 0x02 2 Signals the start of a block. Yes
Block finish 0x03 3 Signals the end of a block. Yes
Block download 0x04 4 Requests a download of a block. Yes
Ping 0x05 5 Determines if the PIC is listening. Yes
Reset 0x10 16 Instructs Stickybot to reset. Yes
Escape 0x1B 27 Used to send data that matches commands. (see below) Yes
Servo Home 0x20 32 Returns all servos to home position. Yes
Disable Servos 0x21 33 Stops all servos. Yes
Enable Servos 0x22 34 Enables the servos. Yes
Single Servo Command 0x23 35 Moves one servo to desired location. Yes
All Servos Command 0x24 36 Moves all servos to their desired locations. Needs Testing
Start Controller 0x30 48 Starts or unpauses the controller. Needs Testing
Pause Controller 0x31 49 Pauses the controller. Needs Testing
Resets Controller 0x32 50 Returns the controller to the state at start-up. Needs Testing
Report Servo Positions 0x40 64 Requests a packet of servo positions. Needs Testing
Report Force Readings 0x41 65 Requests a packet of force readings. Needs Testing
Report Raw Servo Positions 0x42 66 Requests a packet of raw servo commands. Needs Testing
Report Raw Sensor Readings 0x43 67 Requests a packet of raw I2C? sensor readings. No
Tare Sensor Readings 0x44 68 Commands the sensors to tare to the current value Needs Testing

PIC to PC communication

Command Name Hex Dec Description Implemented?
ACK 0x06 6 Acknowledge. Yes
NAK 0x15 21 Negative acknowledge. Yes
Ping echo 0x07 7 The response to a ping command. Yes
Power on 0x0F 15 All resets will generate this command. Yes
Escape 0x1B 27 Used to send data that matches commands. Yes
Servo Packet 0x48 72 Used to send servo positions. Needs Testing
Force Packet 0x49 73 Used to send force readings. Needs Testing
Raw Servo Packet 0x4A 74 Used to send raw servo commands. Needs Testing
Raw Sensor Packet 0x4B 75 Used to send raw I2C? sensor readings. No

Command Details

Escape

Description
Escape allows the PC and PIC to send data that would normally be considered a command. The byte following an escape is interpreted as a data byte XOR'd with 0x80.
Parameters
Data byte XOR'd with 0x80
Response
None

Escape example
In order for the PC to send 0x01 as a data byte, which would normally be interpreted as a Start of Upload command, an escape character must be used. So the PC sends out:
0x1b 0x81
The PIC takes the single augment of 0x1b and XORs it with 0x81 to get 0x01.

Start of upload

Description
This command will stop the motors and prepare for data reception
Parameters
None
Response
Once the memory is erased, the PIC will response with an ACK

Block upload

Description
This command signals a block of memory will be sent. The first byte is the block id. The next 128 bytes is data. The final byte is the checksum. The sum of the block id, all 128 data bytes and the checksum must be divisible by 256. (That is, the sum is zero once cast to an unsigned 8-bit number). Note: the checksum applies to the data bytes and not the raw communciation bytes. Therefore, a data byte of 0x05, needs to be escaped, but the checksum should only count it as 0x05 and not as 0x1b 0x85
Parameters
Block id, 128 data bytes, checksum
Response
There is no response, the PIC waits for a block finish byte.

Block finish

Description
This command is expected after a full and complete block upload command. If the block upload was too long, too short or contained an invalid checksum, the block finish command receives a negative acknowledge. Upon a successful block upload, the PIC will save the block to EEPROM and return an acknowledge.
Parameters
None.
Response
ACK upon a successful upload. A NAK otherwise.

Ping

Description
Upon receiving this command, the PIC response immediately with a ping echo.
Parameters
None.
Response
Ping echo.

Reset

Description
Upon receiving this command, the PIC waits for a confirmation byte: 0xFF. Upon receiving a reset and confirmation, the PIC executes a software reset.
Parameters
Confirmation byte = 0xFF.
Response
A power on command will be generated due to the reset.

Servo Home

Description
This command will move all servos to their home positions.
Parameters
None.
Response
ACK.

Kill Servos

Description
This command disables all servos by holding their PWM lines low.
Parameters
None.
Response
ACK.

Single Servo Command

Description
This commands a single servo to a desired position. Note: this command cannot handle a servo index of 255, this is a reserved value used internally to indicate the null servo channel.
Parameters
  • First byte: index of servo to command.
  • Second byte: servo position.
Response
ACK.

All Servos Command

Description
This commands all servos to respective desired positions. This command will update the servo settings after the entire command has been received.
Parameters
  • The command consists of multiple consectutive entries, each with the following format:
    • Single byte: desired position of servo.
  • The PIC relies on the internal settings to regulate the number of servos and their order.
Response
Single ACK. Since the number of servo may change between different builds, the software should always check for an ACK. If any additional bytes are received, a single NAK is generated.

ACK

Description
General purpose acknowledgement. Used by the PIC to respond to commands.
Parameters
None
Response
None

NAK

Description
General purpose negative acknowledgement. Used by the PIC to indicate an error.
Parameters
None
Response
None

Ping echo

Description
The response to a ping command from the PIC.
Parameters
None
Response
None

Power on

Description
This message is generated each time the PIC is reset. It is followed by the contents of the lower 5 bits of the RCON register on the PIC. The higher 3 bits are set high. The RCON contains the reason for the reset.
Parameters
Reset status byte.
Response
None
RCON Byte details (via pic18f4520 datasheet 7/14/06)
  • bit 7-5: Set to 1 due to firmware.
  • bit 4 RI: RESET Instruction Flag bit
    • 1 = The RESET instruction was not executed.
    • 0 = The RESET instruction was executed causing a device Reset.
  • bit 3 TO: Watchdog Time-out Flag bit
    • 1 = Set by power-up, CLRWDT instruction or SLEEP instruction.
    • 0 = A WDT time-out occurred.
  • bit 2 PD: Power-down Detection Flag bit
    • 1 = Set by power-up or by the CLRWDT instruction.
    • 0 = Set by execution of the SLEEP instruction.
  • bit 1 POR: Power-on Reset Status bit
    • 1 = A Power-on Reset has not occurred.
    • 0 = A Power-on Reset occurred.
  • bit 0 BOR: Brown-out Reset Status bit
    • 1 = A Brown-out Reset has not occurred.
    • 0 = A Brown-out Reset occurred.

-- SalomonTrujillo - 18 Jul 2006

 
This site is powered by the TWiki collaboration platformCopyright &© by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback