Skip to content

Kinen SPI Specification

Alden Hart edited this page May 27, 2013 · 7 revisions

This page describes the SPI electrical and low-level settings and the stream data transfer protocol used over SPI. For info on higher-level communications see Kinen RESTful Hardware

SPI Electrical Specification

SPI Configuration:

  • Kinen assumes the motherboard is always the SPI master and the fins (daughterboards) are always SPI slaves.
  • SPI connectivity is simple point-to-point only - daisy chaining is not supported.
  • Data is delivered MSB first (big-endian)

Kinen SPI uses standard SPI lines:

  • SCK Serial clock - Output from master, shared by all slaves
  • MOSI Master Out / Slave In data line - Output from master, shared by all slaves
  • MISO Master In / Slave Out data line - Input to master, output from slaves. Slaves must tri-state MISO when deselected (i.e. ~SS is high)
  • ~SS Slave Select (active low) - Output from master. An independent ~SS line is required for each slave

SPI Clocking:

  • Default/Startup clocking frequency: 1 Mhz
  • Maximum clocking frequency: No limit. Can be negotiated between master and slaves - slowest slave rules.
  • Clock polarities and edges work in SPI Mode 3
    • CPOL - clock polarity (inactive HI)
    • CPHA - clock phase (data taken on trailing edge, i.e. transition from lo to hi)

SPI Data Transfer Specification

The SPI master/slave protocol is designed to be as simple as possible. The SPI channel is used simply as a bi-directional stream transfer channel, with minimal protocol intelligence of its own.

In summary, the master transmits whenever it wants to and the slave returns the next character in its output buffer whenever there's an SPI transfer. No flow control is needed as the master initiates and drives all transfers.

More details:

  • A "message" is a line of text. Examples of messages are requests from the master to a slave, responses to these requests, and asynchronous messages (from a slave) that are not tied to a request.

  • Messages are terminated with a newline (aka NL, LF, line-feed). The terminating NL is considered part of the message and should be transmitted.

  • If multiple NLs are transmitted each trailing NL is interpreted as a blank message. This is generally not good practice - so watch it.

  • Carriage return (CR) is not recognized as a newline. A CR in a message is treated as any other non-special ASCII character.

  • NULs (0x00) are not transmitted in either direction (e.g. string terminations). Depending on the master or slave internals, it may convert internal string terminating NULs to NLs for transmission.

  • A slave is always in RX state - it must always be able to receive message data (MOSI).

  • All SPI transmissions are initiated by the master and are 8 bits long. As the slave is receiving the byte on MOSI it should be returning the next character in its output buffer on MISO. Note that there is no inherent correlation between the char (or message) being received from the master and transmitted from the slave. It's just IO.

  • If the slave has no data to send it should return ETX (0x03) on MISO. This is useful to distinguish between an "empty" slave and a non-responsive SPI slave or unpopulated Kinen socket - which would return NULs or possibly 0xFFs. Note: This effect can be used to poll SPI channels (sockets) to determine if they are empty or if there is a device attached.

  • The master may poll for message data from the slave by sending STX (0x02) chars to the slave. The slave discards all STXs and simply returns output data on these transfers. Presumably the master would stop polling once it receives an ETX from the slave.