Difference between revisions of "Controller v2"

From 3D printer from scratch
Jump to: navigation, search
(Created page with "= UART-based Controller = Command Format Framing * 1 byte frame length * n byte frame data * 2 byte crc16 (CCITT) of frame data")
 
(SET_ROUTING)
 
(4 intermediate revisions by the same user not shown)
Line 1: Line 1:
 
= UART-based Controller =
 
= UART-based Controller =
  
Command Format
+
The controller has two UARTs, one for control and one for motion data. The motion-UART can use hardware flow control.
  
Framing
+
== Framing ==
  
* 1 byte frame length
+
The framing is self synchronizing. Each frame ends with an EOF marker. Everywhere else the EOF marker is escaped.
 +
 
 +
=== Frame Format ===
 +
 
 +
* 1 byte sequence number
 
* n byte frame data
 
* n byte frame data
 
* 2 byte crc16 (CCITT) of frame data
 
* 2 byte crc16 (CCITT) of frame data
 +
* 0x7e as EOF marker
 +
 +
=== Escaping ===
 +
 +
Escaping is done by byte stuffing. Escape character is 0x7d. Bytes to be escaped are 0x7d and 0x7e. The escape character is following by the byte to by escaped XOR 0x20.
 +
 +
=== Sequence Number ===
 +
 +
The sequence number is echoed by the controller. The controller expects sequence numbers in ascending order. The sequence number has 7 bits. The special sequence nuber 0x80 resets the expected number in the controller to 0, so that the next frame has to be sent with the number 0x01. This is needed to achieve a resynchronization.
 +
The controller signals a receive error by setting the MSB in the response sequence number, echoing the received number.
 +
 +
== Control Commands ==
 +
 +
<vardata> is an 8-120 bit unsigned integer. If less than 120 bit are sent, the date is 0-extended to 120 bit.
 +
 +
=== SPI ===
 +
 +
Format: 0x8X <vardata>
 +
 +
Sends <vardata> to SPI, asserting CS X. The read data are sent in a response packet of full length.
 +
 +
=== GPOUT_HI ===
 +
 +
Format: 0x70 <X>
 +
 +
Sets GPIO X to HI.
 +
 +
=== GPOUT_LO ===
 +
 +
Format: 0x71 <X>
 +
 +
sets GPIO X to LO.
 +
 +
=== GPIN ===
 +
 +
Format: 0x78
 +
 +
Sends the value of all GPIN-pins as a bitmask in a response packet.
 +
 +
== Motion Commands ==
 +
 +
<vardata> is an 8-64 bit signed integer. If less than 64 bit are sent, the date is sign extended to 64 bit.
 +
 +
=== SET_ROUTING ===
 +
 +
Format: 0x60 <output channel> <controller source>
 +
 +
Controllers are numbered here starting from 1. Setting the controller to 0 means disabling the output.
 +
 +
=== NOTIFY ===
 +
 +
Format: 0x61 <vardata>
 +
 +
Echoes <vardata> to host as full 64 bit value.
 +
 +
=== LOADALLREGS ===
 +
 +
Format: 0x70 <vardata>
 +
 +
Load all preload registers to vardata.
 +
 +
=== LOADCNT ===
 +
 +
Format: 0x71 <vardata>
 +
 +
Load the count register to vardata and latch all registers with the preload registers.
 +
 +
=== LOADREG ===
 +
 +
Format: 0x8X <vardata>
 +
 +
Load the preload register belonging to controller X with vardata.

Latest revision as of 15:29, 29 July 2018

UART-based Controller

The controller has two UARTs, one for control and one for motion data. The motion-UART can use hardware flow control.

Framing

The framing is self synchronizing. Each frame ends with an EOF marker. Everywhere else the EOF marker is escaped.

Frame Format

  • 1 byte sequence number
  • n byte frame data
  • 2 byte crc16 (CCITT) of frame data
  • 0x7e as EOF marker

Escaping

Escaping is done by byte stuffing. Escape character is 0x7d. Bytes to be escaped are 0x7d and 0x7e. The escape character is following by the byte to by escaped XOR 0x20.

Sequence Number

The sequence number is echoed by the controller. The controller expects sequence numbers in ascending order. The sequence number has 7 bits. The special sequence nuber 0x80 resets the expected number in the controller to 0, so that the next frame has to be sent with the number 0x01. This is needed to achieve a resynchronization. The controller signals a receive error by setting the MSB in the response sequence number, echoing the received number.

Control Commands

<vardata> is an 8-120 bit unsigned integer. If less than 120 bit are sent, the date is 0-extended to 120 bit.

SPI

Format: 0x8X <vardata>

Sends <vardata> to SPI, asserting CS X. The read data are sent in a response packet of full length.

GPOUT_HI

Format: 0x70 <X>

Sets GPIO X to HI.

GPOUT_LO

Format: 0x71 <X>

sets GPIO X to LO.

GPIN

Format: 0x78

Sends the value of all GPIN-pins as a bitmask in a response packet.

Motion Commands

<vardata> is an 8-64 bit signed integer. If less than 64 bit are sent, the date is sign extended to 64 bit.

SET_ROUTING

Format: 0x60 <output channel> <controller source>

Controllers are numbered here starting from 1. Setting the controller to 0 means disabling the output.

NOTIFY

Format: 0x61 <vardata>

Echoes <vardata> to host as full 64 bit value.

LOADALLREGS

Format: 0x70 <vardata>

Load all preload registers to vardata.

LOADCNT

Format: 0x71 <vardata>

Load the count register to vardata and latch all registers with the preload registers.

LOADREG

Format: 0x8X <vardata>

Load the preload register belonging to controller X with vardata.