HyKim CommsProtocol v1

From Tribotix Wiki
Jump to: navigation, search

Protocol

HyInt communicates with the Data Acquisition Modules using a 2-wire asynchronous serial channel, the parameters for this serial channel are as follows:

  • Baud Rate: 115200Kb/s,
  • Number of Data bits: 8,
  • Parity: NO,
  • Stop Bits: 1.


The network established between HyInt and the Data Acquisition Modules is a MASTER - SLAVE topology, i.e. all commands are initiated by the MASTER, HyInt, whilst the SLAVE simply responds to these commands. For all commands issued by the MASTER, the Data Acquisition Modules will respond with an ID that is equal to the OPCODE. Please note that the Data Acquisition Modules will not respond to any illegal or corrupt packets.


The packet structure used for commands and responses is shown in the tables below:


Command Packet Structure

Length Value Description
1 <SOH> Packet Start byte
1 <ID> Device ID
2 <LEN> Data length (Not including <OPCODE>, <CRC> and <LEN>)
1 <OPCODE> Operation code
0-1024 <DATA> Data
2 <CRC16 > Two bytes CRC16 checksum


Response Packet Structure

Length Value Description
1 <SOH> Packet Start byte
1 <ID> Device ID (reserved for future usage)
2 <LEN> Data length
1 <Answer ID> Operation code
0-1024 <DATA> Data
2 <CRC16 > Two bytes CRC16 checksum


Definitions:


  • <SOH> = Start byte. (0xFF)
  • <CRC16> is the same which is used by Xmodem/Ymodem, Formula: CRC16 = x^16 + x^12 + x^5 + 1


Example:


Here is an example of the data flow, e.g. sending a ‘Get Distance’ command to head board:

SENDER: <soh> 0x02 0x01 0x00 0x00 – CRC(High) – CRC(Low)
RECEIVER: <soh> 0x02 0x01 0x00 0x04 - data(4bytes)- CRC(High) - CRC(Low)

Commands

Read Distance

This command will read the IR Distance Sensor

Command format
Field Size (byte) Value Description
OPCODE 1 0x01 Operation code
Answer Command
Field Size (byte) Value Description
Answer ID 1 0x01 Answer ID
Distance 2 Distance value(cm)
ADC value 2 Original ADC value from distance sensor

Read Accelerometer

This command will read the Accelerometer sensor

Command format
Field Size (byte) Value Description
OPCODE 1 0x02 Operation code
ACCM Channel 1 0-2 Accelerometer channel number
Answer Command
Field Size (byte) Value Description
Answer ID 1 0x02 Answer ID
ACCM value 2 Accelerometer value (g*113.7)


Read Digital Compass

This command will read the Digital Compass

Command format
Field Size (byte) Value Description
OPCODE 1 0x03 Operation code
Answer Command
Field Size (byte) Value Description
Answer ID 1 0x03 Answer ID
Compass value1 2 0-360 Compass value without tilt compensation
Compass value2 2 0-360 Compass value with tilt compensation

Read ADC value

This command will read the 8 channel internal or external ADC

Command format
Field Size (byte) Value Description
OPCODE 1 0x04 Operation code
ADC Channel 1 0-15(body board)
0-7(head board)
ADC channel number
0-7: internal ADC
8-15: External ADC
Answer Command
Field Size (byte) Value Description
Answer ID 1 0x04 Answer ID
ADC value 2 ADC value

Read All ADC Values

This command will read the 8 channel internal or external ADC channels

Command format
Field Size (byte) Value Description
OPCODE 1 0x05 Operation code
Answer Command
Field Size (byte) Value Description
Answer ID 1 0x05 Answer ID
ADC value 16 Internal 10 bits 8 channel ADC value
ADC value 16 External 12 bits 8 channel ADC value

Set Led Status

This command will set the onboard LED status

Command format
Field Size (byte) Value Description
OPCODE 1 0x06 Operation code
LED Status 1 0x00-0x08 Bit0 : LED0
Bit1: LED1
Bit2: LED2
Bit3: Auto controlled by sensor
See details in the table below
Description of byte ‘LED Status’
:Bit :Description
:0 :0: LED0 off, 1: LED0 on
:1 :0: LED1 off, 1: LED1 on
:2 :0: LED2 off, 1: LED2 on
:3 :0: LED0-LED2 controlled by bit0-bit2
:1: then bit0-bit2 disabled,
i.e. the 3 LEDS will be controlled by sensor board
Answer Command
Field Size (byte) Value Description
Answer ID 1 0x06 Answer ID

Calibrate Compass

This command will start/stop calibration of the digital compass

Command format
Field Size (byte) Value Description
OPCODE 1 0x07 Operation code
Axis 1 1: Start XY axis calibration
2: Z Axis calibration
3: Stop calibration
Answer Command
Field Size (byte) Value Description
Answer ID 1 0x07 Answer ID


Calibration procedure:
  • Put the Body Data Acquisition module parallel to the ground.
  • Send Calibration XY axis command to Body Data Acquisition module.
  • Turn the robot 720 degrees, must be kept parallel to the ground.
  • Send stop calibration command.
  • Send Calibration Z axis command to Body Data Acquisition module.
  • Turn the dog in three dimensions, try all possible directions.
  • Send stop calibration command.

Set/Rest Compass

This command will set/reset the digital compass’s offset strap to minimize the soft ion effect. Better to set/reset compass if the device is moved into a new place without restarting the power.

Command format
Field Size (byte) Value Description
OPCODE 1 0x08 Operation code
Answer Command
Field Size (byte) Value Description
Answer ID 1 0x08 Answer ID

Read Gyro

This command will read the gyro value

Command format
Field Size (byte) Value Description
OPCODE 1 0x09 Operation code
Answer Command
Field Size (byte) Value Description
Answer ID 1 0x09 Answer ID
Value 2 Gyro value ((Value*5)/4096 °/s/Value)
Clockwise rotation is positive output*

NB. *Only available in Body Data Acquisition module, dummy data will be returned by Head Data Acquisition module

Read All Value

This command will read all peripherals

Command format
Field Size (byte) Value Description
OPCODE 1 0x10 Operation code
Answer Command
Field Size (byte) Value Description
Answer ID 1 0x10 Answer ID
Value 1 2 Distance
Value 2 2 Accelerometer X(g*113.7)
Value 3 2 Accelerometer Y(g*113.7)
Value 4 2 Accelerometer Z(g*113.7)
Value 5 2 Compass (without tilt compensation) *
Value 6 2 Compass (with tilt compensation) *
Value 7 2 Gyro((Value*5)/4096 °/s/Value) *
Value 8 2 Battery Voltage Monitor*
Value 9 2 Battery Current Monitor*
Value 10 2 Temperature (C°=25+((Value*5000)/(4096*8.4)))*
Value 12 1 Touch pad value*
0x00: No pad is pressed
0x01: Pad 1 is pressed
0x02: Pad 2 is pressed

NB. *Only available in Body Data Acquisition module, dummy data will be returned by Head Data Acquisition module

Update Main

This command will start the main flash update function of Atmega128. The host should run this command first then followed by YModem protocol to send the binary file within 10 seconds. After updating, the Atmega will reboot.


The firmware image file must be a plain binary image and the file name must start with “main”, for example “main_1_0_0_1_28_06_2007_Head.bin”

Command format
Field Size (byte) Value Description
OPCODE 1 0x20 Operation code
Note: this command has no answer command


Update Bootloader

This command will start the boot flash update function of Atmega128.

This command is has not been finished.

Read Main Version

This command will read the version information of the main program. Version info example: “main_1_0_0_1_04_05_2007.bin”

Command format
Field Size (byte) Value Description
OPCODE 1 0x22 Operation code
Answer Command
Field Size (byte) Value Description
Answer ID 1 0x22 Answer ID
Version 26 Version string

Read Bootloader Version

This command will read the version information of the bootloader program.

This command is has not been finished.

Shutdown

This command will do two functions:

  1. Reset Atmega
  2. Set Atmega into power down mode
Command format
Field Size (byte) Value Description
OPCODE 1 0x24 Operation code
Function 1 0: Reset Atmega 1: Set to power down mode

Switch Port

This command will switch the communication port (Uart port). This command is for debug only.

Command format
Field Size (byte) Value Description
OPCODE 1 0x25 Operation code


Read EEPROM

This command will read data from internal EEPROM (4Kbyte size)

Command format
Field Size (byte) Value Description
OPCODE 1 0x26 Operation code
Start Address 2 Read start address
Length 2 Bytes to read
Answer Command
Field Size (byte) Value Description
Answer ID 1 0x26 Answer ID
EEPROM Data 1-1024 EEPROM data

Write EEPROM

This command will write data into Atmega’s EEPROM

Command format
Field Size (byte) Value Description
OPCODE 1 0x27 Operation code
Start Address 2 Write start address
Data 0-1022 Bytes to be written
Note: The length of bytes to be written is defined in packet’s length. The number of bytes to be written = packet length -2.
Answer Command
Field Size (byte) Value Description
Answer ID 1 0x27 Answer ID


OLED Write Cmd

This command will write command set into the OLED.

There are two OLED's in the robot:

OLED ID:=
0: choose left eye
1: choose right eye
2: choose both eyes
Command format
Field Size (byte) Value Description
OPCODE 1 0x31 Operation code
Device No 1 0-2 OLED device number
OLED CMD 1 OLED command
OLED data 1-n Data to be written
Answer Command
Field Size (byte) Value Description
Answer ID 1 0x31 Answer ID

OLED Set Display mode

This command will set OLED display mode.

Command format
Field Size (byte) Value Description
OPCODE 1 0x27 Operation code
Device No 1 OLED device number
Display Mode 1 0-3 Display mode 0: All off 1: All on 3: Inverse display
Answer Command
Field Size (byte) Value Description
Answer ID 1 0x32 Answer ID


OLED Initialize (Default Mode)

Command format
Field Size (byte) Value Description
OPCODE 1 0x32 Operation code
Device No 1 OLED device number
Answer Command
Field Size (byte) Value Description
Answer ID 1 0x32 Answer ID

OLED Set Column

This command will set column address

Command format
Field Size (byte) Value Description
OPCODE 1 0x33 Operation code
OLED ID 1 0-2 OLED device number
Column 1 Column address(0-131)
Answer Command
Field Size (byte) Value Description
Answer ID 1 0x33 Answer ID

OLED Set Row

This command will set row address

Field Size (byte) Value Description
OPCODE 1 0x34 Operation code
OLED ID 1 0-2 OLED device number
Row 1 Row address(0-131)
Answer Command
Field Size (byte) Value Description
Answer ID 1 0x34 Answer ID

OLED Set Position

This command will set column and row address

Field Size (byte) Value Description
OPCODE 1 0x35 Operation code
OLED ID 1 0-2 OLED device number
Column 1 Column address(0-131)
Row 1 Row address(0-131)
Answer Command
Field Size (byte) Value Description
Answer ID 1 0x35 Answer ID


OLED Draw Pixel

This command will draw a pixel on screen

Field Size (byte) Value Description
OPCODE 1 0x38 Operation code
OLED ID 1 0-2 OLED device number
Blue 1 (0-255) Blue value
Green 1 (0-255) Green value
Red 1 (0-255) Red value
Answer Command
Field Size (byte) Value Description
Answer ID 1 0x38 Answer ID

OLED Power Saving Mode

This command will set LCD into power saving mode

Field Size (byte) Value Description
OPCODE 1 0x39 Operation code
Power saving Mode 1 0-1 0: Power saving mode off 1: Power saving mode on
Answer Command
Field Size (byte) Value Description
Answer ID 1 0x39 Answer ID


OLED Draw Line

This command will draw line in screen

Field Size (byte) Value Description
OPCODE 1 0x42 Operation code
OLED ID 1 0-2 OLED device number
Col start 1 0-127
Row start 1 0-127
Col end 1 0-127
Row end 1 0-127
Colour 2 0-0xffff RRRRRGGGGGGBBBBB
Answer Command
Field Size (byte) Value Description
Answer ID 1 0x42 Answer ID

OLED Draw Rectangle

This command will draw rectangle

Field Size (byte) Value Description
OPCODE 1 0x43 Operation code
OLED ID 1 0-2 OLED device number
Col start 1 0-127
Row start 1 0-127
Col end 1 0-127
Row end 1 0-127
Line Colour 2 0-0xFFFF RRRRRGGGGGGBBBBB
Fill Colour 2 0-0xFFFF RRRRRGGGGGGBBBBB
Answer Command
Field Size (byte) Value Description
Answer ID 1 0x43 Answer ID


OLED Draw Circle

This command will draw circle

Field Size (byte) Value Description
OPCODE 1 0x44 Operation code
OLED ID 1 0-2 OLED device number
Col of centre 1 0-127
Row of centre 1 0-127
Radius 1 0-127
Line Colour 2 0-0xFFFF RRRRRGGGGGGBBBBB
Fill Colour 2 0-0xFFFF RRRRRGGGGGGBBBBB
Answer Command
Field Size (byte) Value Description
Answer ID 1 0x44 Answer ID

OLED Copy

This command will Copy the rectangular region defined by the starting point and the ending point to location. If the new coordinates are smaller than the ending points, the new image will overlap the original one.


Field Size (byte) Value Description
OPCODE 1 0x45 Operation code
OLED ID 1 0-2 OLED device number
Col start 1 0-127
Row start 1 0-127
Col end 1 0-127
Row end 1 0-127
Col new start 1 0-127
Row new start 1 0-127
Answer Command
Field Size (byte) Value Description
Answer ID 1 0x45 Answer ID


OLED Clear

This command will sets the window area specify by starting point and the ending point to clear the window display.


Field Size (byte) Value Description
OPCODE 1 0x47 Operation code
OLED ID 1 0-2 OLED device number
Col start 1 0-127
Row start 1 0-127
Col end 1 0-127
Row end 1 0-127
Answer Command
Field Size (byte) Value Description
Answer ID 1 0x47 Answer ID


OLED Set Fill Mode

This command will enable or disable filling of colour into rectangle in draw rectangle command.

Field Size (byte) Value Description
OPCODE 1 0x48 Operation code
OLED ID 1 0-2 OLED device number
Fill mode 1 0-1 0: Fill mode off 1: Fill mode on
Answer Command
Field Size (byte) Value Description
Answer ID 1 0x48 Answer ID


OLED Text Box

This command will set text box size for command “Print String”.


Field Size (byte) Value Description
OPCODE 1 0x53 Operation code
OLED ID 1 0-2 OLED device number
Col start 1 0-127
Row start 1 0-127
Col end 1 0-127
Row end 1 0-127
Answer Command
Field Size (byte) Value Description
Answer ID 1 0x53 Answer ID


OLED Print string

This command will print string in the area set by command OLED TEXTBOX(0x53).

Field Size (byte) Value Description
OPCODE 1 0x56 Operation code
OLED ID 1 0-2 OLED device number
String 1-1023 ASCII String to be printed
Answer Command
Field Size (byte) Value Description
Answer ID 1 0x56 Answer ID


OLED Draw Picture

This command will draw a bitmap picture.

Field Size (byte) Value Description
OPCODE 1 0x60 Operation code
OLED ID 1 0-2 OLED device number
Col start 1 0-127 Column start address
Row start 1 0-127 Row start address
Picture ID 1 0-3 0: Uni Logo 1: Dog’s left eye 2: Dog’s right eye
Answer Command
Field Size (byte) Value Description
Answer ID 1 0x60 Answer ID


OLED Draw Battery Bar

This command will draw the battery bar on right screen.

Field Size (byte) Value Description
OPCODE 1 0x64 Operation code
Battery Value 1 0-100 Battery value(total 5 bars) 0: empty 100: full
Answer Command
Field Size (byte) Value Description
Answer ID 1 0x64 Answer ID


OLED Move Eyes

This command will move dog’s eyes.

Field Size (byte) Value Description
OPCODE 1 0x66 Operation code
Left OLED Posn 1 0-13 There are total 13 positions. 0: 0 o’clock while 11: 11 o’clock,

12: is the centre of the eye, and 13: is Random positions

Right OLED Posn 1 0-13 There are total 13 positions. 0: 0 o’clock while 11: 11 o’clock,

12: is the centre of the eye, and 13: is Random positions

Answer Command
Field Size (byte) Value Description
Answer ID 1 0x66 Answer ID


OLED Draw Eyes

This command will clear the old eyes and draw dog’s eyes in the new address.

Field Size (byte) Value Description
OPCODE 1 0x67 Operation code
Col (left) 1 0-127 Left eye centre column address
Row (left) 1 0-127 Left eye centre row address
Col (right) 1 0-127 Right eye centre column address
Row(right) 1 0-127 Right eye centre row address
Answer Command
Field Size (byte) Value Description
Answer ID 1 0x67 Answer ID

Debugging Tips

There is a second Uart port which is used for debug. In normal mode, you can only to see debug information through this Uart. You can also switch it to communication port, by simply type “PC” then Enter in Hyper Terminal. After that you can send command listed in ‘section 6’ to the board and even update the firmware image.

Personal tools