Converts commands received on the serial interface to i2c commands. The HexTerm program in the vb_HexTerm directory is a simple client for the I2cMaster serial protocol. Default setup is for an ATMega8-16 with an 14.7456MHz crystal, serial port at 8-N-1 115200 baud.

Serial Transmission Protocol

Each message is terminiated with an 0x0a byte, 0x0a is a newline character (‘\n’, decimal 10). The backslash (‘\’) character is used as escape character. Unlike normal c-style escaping the second character needs to be the inverse of the character to be transmitted. So, if 0x0a appears in the message itself it is escaped as: 0x5c 0xf5. Here is 0x5c the backslash character (‘\’, decimal 92) and 0xf5 the bit inverse of 0x0a. The backslash character is escaped as 0x5c 0xa3, a backslash followed by the bit inverse of a backslash.

This protocol was chosen because it can be easily encoded and decoded and it allows for quick resync when a transmission got corrupted. For the sake keeping things simple and for saving processor time no error checking was included.

Serial commands

The following commands can be sent over the serial interface.

s
Perform a i2c bus scan, returns an ‘s’ message for each device found on the i2c bus.

Example: i2c bus scan
Transmit serial data to i2cMaster: 73 0A
73 is ‘s’, instructs i2cMaster do a i2c bus scan.
0A terminates the message.

Received reply from i2cMaster: 73 AC 53 65 72 76 6F 31 36 20 20 32 2E 30 30 33 0A
In ascii: 73=’s’ AC=slave-address “Servo16 1.003″ 0A=end-of-message
In words: at slave address AC is a Servo16 module with version 1.003 connected.

w <SLA> <cmd> [arg1] [arg2] [arg3] [arg4] [arg5] [arg6] [arg7] [arg8]
Write cmd and arguments to slave SLA, the arguments are optional

Example: Set servo 2 to center position
Transmit serial data to i2cMaster: 77 AC 02 80 0A
77 is ‘w’, instructs i2cMaster to write to the i2c bus.
AC is the slave address of the servo module.
02 selects servo 2.
80 sets servo 2 to position 128.
0A terminates the message.

Received reply from i2cMaster: 77 AC 02 80 0A
This is the echo of the command sent.

The actual data send over the i2c bus is “start AC 02 80 stop”.

r <SLA> <cmd> [arg1] [arg2] [arg3] [arg4] [arg5] [arg6] [arg7] [arg8] <ReadLen>
Read <ReadLen> bytes from slave SLA, the arguments are optional
Reply: r <CmdLen> <SLA> <cmd> [arg1] [arg2] .. [arg7] [read1] [read2] .. [read(ReadLen)]
The issued read command is echoed back, with the read bytes appended. CmdLen is the length of the issued read command (not counting <ReadLen>.

Example: Get the servo position of servo 3 and 4
Transmit serial data to i2cMaster: 72 AC 03 02 0A
72 is ‘r’, instructs i2cMaster to read from the i2c bus.
AC is the slave address of the servo module.
03 selects servo 3.
01 read two bytes.
0A terminates the message.

Serial data received from i2cMaster: 72 02 AC 02 40 50 0A
72 is ‘r’
02 number of bytes in the read command.
AC is the slave address of the servo module.
02 the module command sent.
40 first read byte, position of servo 3.
50 second read byte, position of servo 4
0A terminates the answer.
Also servo 3 is at position 40 hex and servo 4 is at 50 hex.

The actual data send over the i2c bus is “start AC 03 repeated-start AD 40 50 stop”.

Leave a Reply

(required)

(required)

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

CAPTCHA Image

Reload Image
© 2018 Tech Toy Hacks Suffusion theme by Sayontan Sinha