SPI Communication Protocol

From Wikitia
Jump to navigation Jump to search

The SPI Communication Protocol or SPI, as it is known in the plastics industry, was developed by the Society of the Plastics Industry, Machinery Division, Committee on Communication Protocol (CCP) to provide for centralized monitoring and control of plastics processing equipment. This protocol was introduced in 1989[1] as a replacement for the many proprietary protocols, as well as loosely defined general-purpose protocols such as Modbus. This protocol would later be referred to by the Machinery Division as CCP Phase I[2][3], but that name is all but unknown today. The popular moniker "SPI" has become increasingly unfortunate as it is an acronym shared with another communication protocol, the Serial Peripheral Interface, with widespread use in all industries.

The SPI Communication Protocol defines a relationship where a Host-Controller, also known as a Control-Station, may Poll or Select each Tributary. A Poll is a query for a setting or state from a piece of equipment known as a Tributary and a Select changes the same. The Host-Controller may be a standalone computer but is most often a function of the injection molding machine. The plastics processing equipment, referred to as tributaries by the standard, are generally taken as the auxiliary equipment, such as the Dryer, Chiller, Loader, Blender, Additive feeder, Hot-runner temperature controller, Mold temperature controller, etcetera.

Configuration of protocol-compliant equipment is fairly straight forward in most cases. The tributaries are plugged into the host-controller and their interfaces enabled. All of the devices are set to the same baud and the host-controller is set to interact with them by enabling the device type in a GUI. There are no discrete wires to connect, no "coils" or commands to define, no programming of any sort. Only in rare cases, with duplicate equipment in a molding cell, must an address be modified. File:SpiInUse.png|thumb|SPI Tributary port while in use


Details

It is an asynchronous serial, half-duplex, multi-drop, bus network protocol. Included in the protocol standard are the physical, data Link and application layers of the OSI model, in addition to a number of comprehensive Commands Sets to suit common tributaries. The intent of the rigorous definition was to ensure simple, rapid configuration and interchangeability of equipment. The protocol standard documents directly reference ANSI X3.28, subcatagories D1 and 2.4, with which it bears a strong resemblance. Procedures for Abort, Termination Interrupt, Reverse Interrupt, Recovery, Synchronization, Establishment, Message Transfer and Termination are included. Other references used in protocol development were EIA485, EIA404, ANSI X3.4-1977, ANSI X3.16-1976, ANSI X3.15-1976, IEEE 830-1984, IEEE 754-1985 and MIL-C-24308.

Hardware

The physical layer begins with a MIL-C-24308 DE-9 D-Sub Connector[4]. All equipment's connector contacts are female while the interconnecting cables are male. The cable used is a shielded, with two twisted pair having a 100 ohm characteristic impedance, per subsection 3.2.3.5 of the standard, as well a common and a drain. One twisted pair leads from the host and the other pair continues the bus, allowing a central hub. A fail-safe bias, per EIA485, is provided by the Host Controller to ensure the bus is held high when not driven. The bus is terminated at both ends: at the host-controller and after the all of the tributaries. This last termination is to be provided by the SPI hub[5].

On all of the host controller's tributary-receptacles the EIA485 Common is on contact 1 and the drain is on contact 3. The differential pair from the non-inverting (+) of the host's transceiver is on contact 4, while the inverting (-) is on contact 5. Each receptacle also has an outgoing pair leading to the next tributary receptacle. For that, the non-inverting (+) of the host's transceiver is on contact 8, while the inverting (-) is on contact 9.

On the tributary receptacle, the EIA485 Common is on contact 1 and the drain is not connected. The differential-pair from the non-inverting (+) of the transceiver is on contact 4, while the inverting (-) is on contact 5. Each receptacle also has an outgoing pair leading to the next tributary. For that, the non-inverting (+) of the host's transceiver is on contact 8, while the inverting (-) is on contact 9. Electrically, 4 is connected to 8 and 5 to 9, but this should be done as close as is reasonable to the transceiver to minimize stub length.

Serial

By definition, each byte over SPI Protocol has 8 data bits, no parity bits and one stop bit. All tributaries' UARTs must run at the same baud as the host-controller. At a minimum, support for 1200 baud is required by the protocol but 2400, 4800, 9600 and 19200 are specifically recommended by the standard.

Control Characters

The SPI Communication Protocol shares many of the Link Control Characters, as well as the alternating acknowledgment scheme, with IBM's Bisync.

These are the Control Characters used in the Protocol.

<SOH>
0x01 START OF HEADING
The header contains a two byte address and a two byte command.
Always preceded with <DLE>
<STX>
0x02 START OF TEXT
Marks beginning of Transparent Text.
Always preceded with <DLE>
<ETX>
0x03 END OF TEXT
Marks end of Transparent Text and the last block.
Always preceded with <DLE>
<EOT>
0x04 END OF TRANSMISSION
Often used to indicate that there are no more Message blocks.
Also used to reset the bus.
<ENQ>
0x05 ENQUIRY
Mostly used at the end of a Polling Supervisory Sequence. A lone <ENQ> from a tributary is requesting a retry. A block abort is a <DLE><ENQ> byte pair.
<DLE>
0x10 DATALINK ESCAPE
Used with <STX>, <SOH>, <ETX>, <ENQ> and <ETB>.
Used with 0x30, 0x31 as an Acknowledge (see bellow).
Used to escape byte 0x10 within transparent data.
<NAK>
0x15 NEGATIVE ACKNOWLEDGE
Often preceded by an error byte (ERR)
<SYN>
0x16 SYNCHRONOUS IDLE
This is preceded with <DLE> if inside transparent text.
<SYN> may not immediately precede the CRC bytes.
<ETB>
0x17 END OF TRANSMISSION BLOCK (preceded with <DLE>)
Signals the end of transparent text but not the last block; the last block would use an <ETX>.
<ACKn>
<ACK> is not used in the SPI protocol so, instead, <DLE>0x30 and <DLE>0x31 byte pairs are used. These are sometimes referred to as ACK0 and ACK1. The value alternates with each successful message.
<3C>
REVERSE INTERRUPT (preceded with <DLE>)
Sent by a receiving station, after it receives a valid CRC, to end a multi-block message. The sending station must accept the <DLE><3C> sequence as a valid acknowledgement and respond with an <EOT> as a reset.

Other Characters

SPI Reserved Byte, or [RES], which has a value of 0x20 in version 3.01 of the protocol.

Error Byte, or [ERR], precceds a <NAK> and carries the following bits, LSb first: "Communication Error", "Invalid Preamble", "Command Not Executed", "Command Not Supported", "Reserved by SPI", "Set to 1", "Reserved by SPI" and "Invalid Data".

Timers

Some timers are a means to detect when a message transaction has failed. Recovery Procedures are actions that are performed by both the Host Controller and Tributary in response to such a failure. The procedure may attempt to continue the exchange, as with timer A, or immediately restore the state of the bus as with timers B & D.

Timer A

ANSI X3.28 1000 ms (1 second) non-retriggerable sending station response timer and it may run up to three times. It starts after sending an end character like <DLE><ETB>, <DLE><ETX> or, when not part of a supervisory sequence an <ENQ>, i.e. not expecting a simple <ACKn>, [ERR]<NAK> or an [EOT] as a termination interrupt. Cleared on receipt of a valid response. Upon timeout the sending station should send a lone <ENQ> and timer A would be reset. A timeout after a second <ENQ> should reset the sending station.

Timer B

ANSI X3.28 100 ms receiving station block timer that protects against missing incoming <DLE><ETB> or <DLE><ETX> sequences. It starts on receipt of start sequences <DLE><SOH> or <DLE><STX>. Resets on all characters except the <DLE><SYN> sequences. Clears on <ENQ>, <DLE><ETB> or <DLE><ETX>. Result of timeout is a full reset to normal state.

Timer C

Gross Timer. It is not used in the SPI Communication Protocol.

Timer D

ANSI X3.28 1200 ms inactivity timer. It starts on receipt of any character and resets on all characters. Clears on <EOT>. Result of timeout is a full reset to normal state.

Timer E

Delay before transmission. Hold off sending any data for 2 ms after other traffic to allow slow nodes to disable there drivers.

Addressing

DEVID

The addressing on a tributary is through the first two bytes within the message header; the first byte being the device-identifier or DEVID. This DEVID establishes what sort of device the tributary is, The SPI publishes specific identifiers for each general type of tributary, from 0x20 to 0xff so 224 DEVID values are possible, though only 11 have been defined. As an example, a self-tuning a hot-runner controller must have the DEVID of 0x26. The DEVID value is generally hardcoded into the tributaries software by its manufacturer.

Published DEVIDs[6]
  • 0x20, Mold Temperature Controller
  • 0x21, Chiller
  • 0x22, Dryer
  • 0x23, Loader
  • 0x24, Melt Pump
  • 0x25, Additive Feeder
  • 0x26, Self Tuning General Purpose Temperature
  • 0x27, General Purpose Temperature Controls
  • 0x28, Blender, Volumetric
  • 0x28, Injection Molding Machine (Draft)
  • 0x29, Blender, Continuous Weigh
  • 0x2A, Blender, Batch Weigh

ADD

The second of these two bytes is the address within that [DEVID] or the [ADD]. Device addresses start at decimal 32 or 0x20 and are user assignable. The protocol provides for 223 addresses for each [DEVID] or device type, allowing many of any given sort of tributary to be on the same network. Address 0xFF, what would be the 224th device, is "Reserved by SPI".

Commands

Tributary commands are the last two bytes within the message header, [CMD1] and [CMD2]. The full set of commands possible for any [DEVID] are defined in the I/O List, published by SPI, but the subset implemented in the actual hardware is provided by the tributary's manufacturer. As a rule, [CMD1] is 0x20 unless the command applies to specific zone or channel within the tributary. For a zone specific Poll or Select its value will be 0x30 plus the channel. For example, if applied to zone 11, CMD1 = (0x30 + 11) = 0x3B. In some cases a command may be applicable to all zones, in which case [CMD1] will be 0x30. The value of [CMD2] for a Poll is even and Select's is odd. For commands that support both Poll and Select, Select's [CMD2] will be Poll's [CMD2] + 1.

Message Text

The payload or Text of a message is within a Transparent Text region, just as in Bisync. This region begins after the <DLE><STX> byte pair and ends at the <DLE><ETX> pair. All characters are fair in this variable-length region but both decimal 16 (0x10) and <SYN> must be escaped with a <DLE>s. In practice, the actual data in this text region is usually either two or four bytes. If two, this is a Status Word as a bitfield. If four bytes it is usually a 32 bit, single-precision IEEE 754-1985 floating point value but, in the case of the Echo and Version commands, is four ASCII characters in the Open Message format. The Open Message format supports data that does not conform to the other two types and may be any length. In all cases, data is transferred most significant byte first or network byte order.

Error Detection

Error detection is applied to value-containing messages through CRC-16-IBM. This particular CRC is of exactly the same form as used by Modbus except that the initial value of the CRC is zero and not 65535 (0xFFFF). Processing of bytes begins immediately after the first instance of either an <SOH> (Start of Heading) or <STX>, stopping after the <ETX> (End of Text), inclusive. <DLE>s and <SYN>s are never included in the CRC. The two computed CRC bytes are placed immediately after the <ETX>, most significant byte first.

Connection Establishment

The host-controller initiates all connections with the tributaries. A tributary will only respond to messages containing its DEVID and ADD bytes. If the command is invalid the tributary will respond with an <EOT>.

Polling

The host requests a state or value from a tributary by sending a seven byte Polling Supervisory Sequence containing the [DEVID], [ADD], [CMD1], [CMD2] and [RES]. This sequence begins with an <EOT> and finishes with an <ENQ>. With a Poll the tributary temporarily assumes the role of master and may either fill the request or send an <EOT>. In the case where the tributary replies with an <EOT>, it will resume the role of slave. The host should try two more times before giving up on the tributary and reporting a communication failure to the hosts application.

To Poll a Mold Temperature Controller:

Character Value Description
<EOT> 0x04 Reset
[DEVID] 0x20 A mold temperature controller for water
[ADD] 0x20 The first controller of the type in the production cell
[CMD1] 0x20 First byte of command to poll temperature of water to the process
[CMD2] 0x70 Second byte of command
[RES] 0x20 SPI Reserved Byte
<ENQ> 0x05 The end of the sequence

A possible valid response is:

Character Value Description Include in CRC
<DLE> 0x10 Escape for <SOH> No
<SOH> 0x01 The header comes next No
[DEVID] 0x20 A mold temperature controller Yes
[ADD] 0x20 The first temperature controller Yes
[CMD1] 0x20 First byte of command Yes
[CMD2] 0x70 Second byte of command Yes
[RES] 0x20 SPI Reserved Byte Yes
[20] 0x20 Just a hex 20 Yes
<DLE> 0x10 Escape for <STX> No
<STX> 0x02 Transparent Text is next Yes
[Data1] 0x42 MSB of floating point value Yes
[Data2] 0x9E Yes
[Data3] 0xDC Yes
[Data4] 0x29 LSB of floating point value Yes
<DLE> 0x10 Escape for <ETX> No
<ETX> 0x03 Transparent text has ended Yes
[CRC] 0x63 MSB of the 16 bit CRC
[CRC] 0xA5 LSB of the 16 bit CRC

If the CRC byte check the Host Controller should respond with <ACK1>

Character Value Description
<DLE> 0x10 Escape for <ACK1>
<ACK1> 0x31 Acknowledge 1

In this case the temperature of the water going to the mold is 79.43 °F.

If the CRC fails, then

Character Value Description
<NAK> 0x15 Not Acknowledged

And the Tributary will repeat the message up to twice.

Selecting

The host changes a state or value from a tributary by first sending a seven byte Select Supervisory Sequence containing the [DEVID], [ADD], [CMD1], [CMD2] and [RES]. This sequence begins with an <EOT> and finishes with an <ENQ>.

To Poll a Mold Temperature Controller:

Character Value Description
<EOT> 0x04 Reset
[DEVID] 0x26 A hot runner temperature controller
[ADD] 0x20 The first controller of the type in the production cell
[CMD1] 0xAB Zone 123 of the controller
[CMD2] 0x21 Select command for Setpoint
[RES] 0x20 SPI Reserved Byte
<ENQ> 0x05 The end of the sequence

If the select of the zone is allowed, the Tributary will respond:

Character Value Description
[DEVID] 0x26 Hot runner controller
[ADD] 0x20 The first controller of the type
[CMD1] 0xAB Zone 123
[CMD2] 0x21 Select for setpoint
[RES] 0x20 SPI Reserved Byte
<DLE> 0x10 Escape for <ACK0>
<ACK0> 0x30 Acknowledge 0

With that, the Host Controller sends a message containing the new setpoint. In this case it is for processing a PEEK resin at 740.25 °F. Note that this particular floating point value has a 0x10 byte that must be escaped:

Character Value Description Include in CRC
<DLE> 0x10 Escape for <STX> No
<STX> 0x02 Transparent Text is next No
[Data1] 0x44 MSB of floating point value Yes
[Data2] 0x39 Yes
<DLE> 0x10 Escape for Data value of 0x10 No
[Data3] 0x10 Yes
[Data4] 0x00 LSB of floating point value Yes
<DLE> 0x10 Escape for <ETX> No
<ETX> 0x03 Transparent text has ended Yes
[CRC] 0x57 MSB of the 16 bit CRC
[CRC] 0xBD LSB of the 16 bit CRC

To that, if all went well, the Tributary would respond:

Character Value Description
<DLE> 0x10 Escape for <ACK1>
<ACK1> 0x31 Acknowledge 1

And the Host would indicate that there are no more messages with:

Character Value Description
<EOT> 0x04 End of transmission

Or, if there was a failure:

Character Value Description
(ERR) 0xnn Error byte indicating the reason
<NAK> 0x15 Not Acknowledged

Successors

The SPI Communication Protocol is no longer maintained but is still used on much equipment by several makers. There have been a few attempts to replace it over the years and the first was HostNet, released August 1995[2]. HostNet, also referred to as CCP Phase II, was a joint IBM/SPI project with Jim O'neil, IBM's segment manger for the plastics industry, and Donald Rainville, Universal Dynamics Corp., as the committee lead.

References

  1. Rosato, D.V. and Rosato, D.V. and Rosato, M.G. (2000). Injection Molding Handbook. Kluwer Academic Publishers. ISBN 9780792386193. LCCN 99049946.{{cite book}}: CS1 maint: multiple names: authors list (link)
  2. 2.0 2.1 Kirkland, Carl (September 1995). "The on-ramp to the plantwide information superhighway is complete". Injection Molding Magazine. p. 19.
  3. "Literature", SPI Machinery Division, 2008
  4. Machinery Division (October 1990). "The SPI Communication Protocol, Version 3.01". Society of Plastics Industries.
  5. Machinery Division (October 1990). "Version 3.01 Machine Connections". Society of Plastics Industries.
  6. Machinery Division (October 1990). "The SPI Communication Protocol, I/O List". Society of Plastics Industries.

This article "SPI Communication Protocol" is from Wikipedia. The list of its authors can be seen in its historical. Articles taken from Draft Namespace on Wikipedia could be accessed on Wikipedia's Draft Namespace.