Difference between revisions of "Robotino3 IO protocol"

From RobotinoWiki
Line 23: Line 23:
 
|-
 
|-
 
|Checksum
 
|Checksum
|1
+
|2
 
|Calculated from length and payload bytes
 
|Calculated from length and payload bytes
 
|}
 
|}
 +
 +
====Head====
 +
The package header is the unique byte 0xAA.
 +
 +
====Length====
 +
The number of bytes of the payload data.
 +
<pre>
 +
package[1] = length & 0xFF;
 +
package[2] = 0xFF & ( length >> 8 );
 +
</pre>
 +
 +
====Checksum====
 +
Complement 2 of the sum of Length and Payload bytes before escaping.
 +
<pre>
 +
uint16 calculate_checksum( const uint8* data, int dataSize )
 +
{
 +
uint16 out = 0;
 +
        for( int i=0; i<dataSize; ++i )
 +
{
 +
out += *p;
 +
++data;
 +
}
 +
return 0xffff & ( (1<<16) - out );
 +
}
 +
</pre>

Revision as of 14:15, 6 July 2012

Description of the data exchange protocol between LPC2378 and COM-Express module over USB

Most of the I/Os comming with Robotino 3 are still connected to a NXP LPC2378 microcontroller (MC). In contrast to previous versions of Robotino the interface between the MC and Robotino's internal industral PC is no longer RS232 but USB. This page describes the protocol used for communication between MC and PC over USB.

Package assembly

All data send from PC to MC and vice versa has the form

Field name Bytes Description
Head 1 Start of package
Length 2 Length of package payload
Payload Payload data
Checksum 2 Calculated from length and payload bytes

Head

The package header is the unique byte 0xAA.

Length

The number of bytes of the payload data.

package[1] = length & 0xFF;
package[2] = 0xFF & ( length >> 8 );

Checksum

Complement 2 of the sum of Length and Payload bytes before escaping.

uint16 calculate_checksum( const uint8* data, int dataSize )
{
	uint16 out = 0;
        for( int i=0; i<dataSize; ++i )
	{
		out += *p;
		++data;
	}
	return 0xffff & ( (1<<16) - out );
}