#LyX 2.0 created this file. For more info see http://www.lyx.org/ \lyxformat 413 \begin_document \begin_header \textclass article \begin_preamble \usepackage[long]{datetime} \usepackage[toc]{multitoc} \renewcommand\tableofcontents{% \@starttoc{toc}% } \usepackage{fancyhdr} \pagestyle{fancy} \chead{Sense/Net Bus Specification} \lhead{} \rhead{} \end_preamble \use_default_options true \begin_modules customHeadersFooters \end_modules \maintain_unincluded_children false \language english \language_package default \inputencoding auto \fontencoding global \font_roman lmodern \font_sans lmss \font_typewriter lmtt \font_default_family default \use_non_tex_fonts false \font_sc false \font_osf false \font_sf_scale 100 \font_tt_scale 100 \graphics default \default_output_format default \output_sync 0 \bibtex_command default \index_command default \float_placement h \paperfontsize default \spacing single \use_hyperref true \pdf_bookmarks true \pdf_bookmarksnumbered false \pdf_bookmarksopen false \pdf_bookmarksopenlevel 1 \pdf_breaklinks false \pdf_pdfborder true \pdf_colorlinks false \pdf_backref false \pdf_pdfusetitle true \papersize default \use_geometry true \use_amsmath 1 \use_esint 1 \use_mhchem 1 \use_mathdots 1 \cite_engine basic \use_bibtopic false \use_indices false \paperorientation portrait \suppress_date false \use_refstyle 1 \index Index \shortcut idx \color #008000 \end_index \leftmargin 2cm \topmargin 2cm \rightmargin 2cm \bottommargin 2cm \secnumdepth 3 \tocdepth 3 \paragraph_separation indent \paragraph_indentation default \quotes_language english \papercolumns 1 \papersides 1 \paperpagestyle fancy \tracking_changes false \output_changes false \html_math_output 0 \html_css_as_file 0 \html_be_strict false \end_header \begin_body \begin_layout Title Sense/Net Bus Specification \end_layout \begin_layout Author Nick Ames \begin_inset Formula $\cdot$ \end_inset Revision 2 \begin_inset Newline newline \end_inset Copyright 2016 Sensiplicity Systems \end_layout \begin_layout Standard \begin_inset Box Frameless position "t" hor_pos "c" has_inner_box 1 inner_pos "t" use_parbox 0 use_makebox 0 width "100col%" special "none" height "1in" height_special "totalheight" status open \begin_layout Plain Layout \begin_inset CommandInset toc LatexCommand tableofcontents \end_inset \end_layout \end_inset \end_layout \begin_layout Section Overview \end_layout \begin_layout Standard The Sense/Net bus is an inexpensive system for retrieving data from large numbers of environment sensors. It provides power and two digital buses: RS-485 and 1-Wire. The 1-Wire bus is used over short distances (TODO) to simple 1-wire sensors, such as thermometers. The RS-485 bus is used over longer distances to connect more sophisticated sensors. Up to 100 sensors can be connected to the bus. \end_layout \begin_layout Standard An individual Sense/Net bus is composed of a single controller, many nodes (sensors), an optional terminator, and optional power injectors. The controller initiates all communication on the bus and gathers data from the nodes. \end_layout \begin_layout Section Physical Layer \end_layout \begin_layout Subsection Wiring \end_layout \begin_layout Standard \begin_inset Note Note status open \begin_layout Plain Layout Include info on new four-conductor pinout \end_layout \end_inset \end_layout \begin_layout Standard Connections are made using modular jacks (RJ-12) and six conductor cable. (If no 1-wire devices are present, RJ-11 jacks and four-conductor cable may be employed.) Cables should be wired \begin_inset Quotes eld \end_inset straight-through \begin_inset Quotes erd \end_inset , meaning they have the same connections on both ends. \end_layout \begin_layout Standard \begin_inset Float figure wide false sideways false status collapsed \begin_layout Plain Layout \begin_inset space \hfill{} \end_inset \begin_inset Box Frameless position "c" hor_pos "c" has_inner_box 1 inner_pos "t" use_parbox 0 use_makebox 0 width "3cm" special "none" height "1in" height_special "totalheight" status open \begin_layout Plain Layout \begin_inset Graphics filename images/RJ-12 Pinout.eps width 3cm \end_inset \end_layout \end_inset \begin_inset space \hspace{} \length 1cm \end_inset \family sans \size small \begin_inset Tabular \begin_inset Text \begin_layout Plain Layout \family sans \size small \emph on Signals \end_layout \end_inset \begin_inset Text \begin_layout Plain Layout \end_layout \end_inset \begin_inset Text \begin_layout Plain Layout \family sans \size small \emph on 1 \end_layout \end_inset \begin_inset Text \begin_layout Plain Layout \family sans \size small Unused \end_layout \end_inset \begin_inset Text \begin_layout Plain Layout \family sans \size small \emph on 2 \end_layout \end_inset \begin_inset Text \begin_layout Plain Layout \family sans \size small 5V Power \end_layout \end_inset \begin_inset Text \begin_layout Plain Layout \family sans \size small \emph on 3 \end_layout \end_inset \begin_inset Text \begin_layout Plain Layout \family sans \size small RS-485 B \end_layout \end_inset \begin_inset Text \begin_layout Plain Layout \family sans \size small \emph on 4 \end_layout \end_inset \begin_inset Text \begin_layout Plain Layout \family sans \size small RS-485 A \end_layout \end_inset \begin_inset Text \begin_layout Plain Layout \emph on 5 \end_layout \end_inset \begin_inset Text \begin_layout Plain Layout Gnd \end_layout \end_inset \begin_inset Text \begin_layout Plain Layout \emph on 6 \end_layout \end_inset \begin_inset Text \begin_layout Plain Layout 1-Wire I/O \end_layout \end_inset \end_inset \family default \size default \begin_inset space \hfill{} \end_inset \end_layout \begin_layout Plain Layout \begin_inset Caption \begin_layout Plain Layout Connector signals and pinout \end_layout \end_inset \end_layout \end_inset \end_layout \begin_layout Subsection Topology \end_layout \begin_layout Standard To prevent signal degradation, a Sense/Net bus should be arranged as a line, not as a tree. For longer runs, a terminator at the end of the bus opposite the controller is recommended. \end_layout \begin_layout Standard \begin_inset Note Note status open \begin_layout Plain Layout TODO: Power limitations \end_layout \end_inset \end_layout \begin_layout Subsection Power \end_layout \begin_layout Standard Power to sensors is provided by +5V and ground lines in the cable. \end_layout \begin_layout Section Protocol (RS-485) v2 \end_layout \begin_layout Standard At the lowest level, bytes are transmitted on the RS-485 bus at 19200 baud with eight data bits, one stop bit, and no parity (8N1). Data on the Sense/Net bus is exchanged in packets. A packet can be sent from the controller to a node (a request) or from a node to the controller (a reply). The node that sent or should receive a packet is determined by a nine-byte ID unique to each node. Nodes connected to the bus are discovered by the controller during enumeration. \begin_inset Note Note status open \begin_layout Plain Layout Cross-reference \end_layout \end_inset \end_layout \begin_layout Standard To request data, or perform an action, the controller sends a packet to a node. The node may reply with a single packet. While awaiting a reply, the controller should not send any other packets until the wait-reply interval has elapsed. \begin_inset Note Note status open \begin_layout Plain Layout Cross-reference \end_layout \end_inset Nodes may only send packets when requested by the controller, and may only send a single packet for each request. Enumeration is an exception to normal operation; during enumeration, a single request from the controller results in a reply from all nodes. \begin_inset Note Note status open \begin_layout Plain Layout Cross-reference \end_layout \end_inset \end_layout \begin_layout Standard Packets are delineated with two special characters: Start (0x01), End (0x03), and Escape (0x1B). Start and end characters are placed at the beginning and end of each packet to separate it from others. An escape character is inserted immediately before any verbatim 0x01, 0x03, or 0x1B bytes that must appear in a packet. \end_layout \begin_layout Standard When a node receives a start character it discards any in-progress packet and begins a new one. If the controller receives a start character in the middle of a reply, it is an error, and the reply is invalid. Nodes process a packet and perform an action only after receiving an end character. \end_layout \begin_layout Standard To protect against corruption, packets are validated with a two-byte CRC at their end. The CRC is computed over all packet data that precedes it, excluding the start byte. CRC calculation uses a polynomial of 0x1021 and an initial value of 0xFFFF. \end_layout \begin_layout Subsection Packet Structure \end_layout \begin_layout Standard \begin_inset Float table wide false sideways false status open \begin_layout Plain Layout \begin_inset space \hfill{} \end_inset \emph on (Start) \emph default \begin_inset Tabular \begin_inset Text \begin_layout Plain Layout Start Character \end_layout \end_inset \begin_inset Text \begin_layout Plain Layout Header \end_layout \end_inset \begin_inset Text \begin_layout Plain Layout Node ID \end_layout \end_inset \begin_inset Text \begin_layout Plain Layout Data Length \end_layout \end_inset \begin_inset Text \begin_layout Plain Layout Data \end_layout \end_inset \begin_inset Text \begin_layout Plain Layout CRC \end_layout \end_inset \begin_inset Text \begin_layout Plain Layout End Character \end_layout \end_inset \begin_inset Text \begin_layout Plain Layout 0x01 \end_layout \end_inset \begin_inset Text \begin_layout Plain Layout 1 byte \end_layout \end_inset \begin_inset Text \begin_layout Plain Layout 9 bytes \end_layout \end_inset \begin_inset Text \begin_layout Plain Layout 1 byte \end_layout \end_inset \begin_inset Text \begin_layout Plain Layout 0-128 bytes \end_layout \end_inset \begin_inset Text \begin_layout Plain Layout 2 bytes \end_layout \end_inset \begin_inset Text \begin_layout Plain Layout 0x03 \end_layout \end_inset \end_inset \emph on (End) \emph default \begin_inset space \hfill{} \end_inset \end_layout \begin_layout Plain Layout \begin_inset Caption \begin_layout Plain Layout Packet structure. \end_layout \end_inset \end_layout \end_inset \end_layout \begin_layout Subsubsection Header \end_layout \begin_layout Standard The header describes the direction of data transfer and contains commands common to all node types (nodes may implement additional commands in the data field). Packets do not contain any data for standard commands except enumeration, but nodes may implement additional commands that require data. \end_layout \begin_layout Standard \begin_inset Float table wide false sideways false status open \begin_layout Plain Layout \begin_inset space \hfill{} \end_inset \emph on Controller to Node: \emph default \begin_inset Tabular \begin_inset Text \begin_layout Plain Layout \emph on Bit \end_layout \end_inset \begin_inset Text \begin_layout Plain Layout \emph on 7 \end_layout \end_inset \begin_inset Text \begin_layout Plain Layout \emph on 6 \end_layout \end_inset \begin_inset Text \begin_layout Plain Layout \emph on 5 \end_layout \end_inset \begin_inset Text \begin_layout Plain Layout \emph on 4 \end_layout \end_inset \begin_inset Text \begin_layout Plain Layout \emph on 3 \end_layout \end_inset \begin_inset Text \begin_layout Plain Layout \emph on 2 \end_layout \end_inset \begin_inset Text \begin_layout Plain Layout \emph on 1 \end_layout \end_inset \begin_inset Text \begin_layout Plain Layout \emph on 0 \end_layout \end_inset \begin_inset Text \begin_layout Plain Layout \emph on Value \end_layout \end_inset \begin_inset Text \begin_layout Plain Layout 1 \end_layout \end_inset \begin_inset Text \begin_layout Plain Layout 0 \end_layout \end_inset \begin_inset Text \begin_layout Plain Layout 1 \end_layout \end_inset \begin_inset Text \begin_layout Plain Layout 0 \end_layout \end_inset \begin_inset Text \begin_layout Plain Layout 0 \end_layout \end_inset \begin_inset Text \begin_layout Plain Layout Command \end_layout \end_inset \begin_inset Text \begin_layout Plain Layout \end_layout \end_inset \begin_inset Text \begin_layout Plain Layout \end_layout \end_inset \end_inset \begin_inset space \hfill{} \end_inset \end_layout \begin_layout Plain Layout \begin_inset space \hfill{} \end_inset \emph on Node to Controller: \emph default \begin_inset Tabular \begin_inset Text \begin_layout Plain Layout \emph on Bit \end_layout \end_inset \begin_inset Text \begin_layout Plain Layout \emph on 7 \end_layout \end_inset \begin_inset Text \begin_layout Plain Layout \emph on 6 \end_layout \end_inset \begin_inset Text \begin_layout Plain Layout \emph on 5 \end_layout \end_inset \begin_inset Text \begin_layout Plain Layout \emph on 4 \end_layout \end_inset \begin_inset Text \begin_layout Plain Layout \emph on 3 \end_layout \end_inset \begin_inset Text \begin_layout Plain Layout \emph on 2 \end_layout \end_inset \begin_inset Text \begin_layout Plain Layout \emph on 1 \end_layout \end_inset \begin_inset Text \begin_layout Plain Layout \emph on 0 \end_layout \end_inset \begin_inset Text \begin_layout Plain Layout \emph on Value \end_layout \end_inset \begin_inset Text \begin_layout Plain Layout 1 \end_layout \end_inset \begin_inset Text \begin_layout Plain Layout 1 \end_layout \end_inset \begin_inset Text \begin_layout Plain Layout 0 \end_layout \end_inset \begin_inset Text \begin_layout Plain Layout 1 \end_layout \end_inset \begin_inset Text \begin_layout Plain Layout 0 \end_layout \end_inset \begin_inset Text \begin_layout Plain Layout Status \end_layout \end_inset \begin_inset Text \begin_layout Plain Layout \end_layout \end_inset \begin_inset Text \begin_layout Plain Layout \end_layout \end_inset \end_inset \begin_inset space \hfill{} \end_inset \end_layout \begin_layout Plain Layout \begin_inset Caption \begin_layout Plain Layout Header structure. \end_layout \end_inset \end_layout \end_inset \end_layout \begin_layout Subsubsection* Command Codes \end_layout \begin_layout Subsubsection* \begin_inset Formula $000_{2}$ \end_inset -- Get Data \end_layout \begin_layout Standard Tells the node to send a sensor data packet. The format of the data packets is defined by the node. \end_layout \begin_layout Subsubsection* \begin_inset Formula $001_{2}$ \end_inset -- Enumerate \end_layout \begin_layout Standard Tells all nodes to reply in a wired-AND manner to determine the next significant bit in their address. See the enumeration section. \begin_inset Note Note status open \begin_layout Plain Layout Cross-reference \end_layout \end_inset \end_layout \begin_layout Subsubsection* \begin_inset Formula $010{}_{2}$ \end_inset -- Fast Enumerate \end_layout \begin_layout Standard Tells the node to immediately send an enumeration reply. All nodes respond to this command, regardless of the node ID in the packet. (Although the node ID is not checked, the CRC must match the contents of the packet.) \end_layout \begin_layout Standard This command is for testing purposes, and must only be used on a bus containing a single node. \end_layout \begin_layout Subsubsection* \begin_inset Formula $011{}_{2}$ \end_inset -- Blink \end_layout \begin_layout Standard Tells the node to blink its status LED, if it has one. No reply will be returned. \end_layout \begin_layout Subsubsection* \begin_inset Formula $100{}_{2}-111_{2}$ \end_inset -- Node Defined \end_layout \begin_layout Standard Nodes may define additional commands. \end_layout \begin_layout Subsubsection* Status Codes \end_layout \begin_layout Subsubsection* \begin_inset Formula $000_{2}$ \end_inset -- Data \end_layout \begin_layout Standard This packet contains data requested by the controller. \end_layout \begin_layout Subsubsection* \begin_inset Formula $001_{2}$ \end_inset -- Typecode Enumeration Reply \end_layout \begin_layout Standard This packet is a reply to an enumeration command where the address is fully specified. \end_layout \begin_layout Subsubsection* \begin_inset Formula $010{}_{2}$ \end_inset -- Invalid Command Error \end_layout \begin_layout Standard The node received an invalid command from the controller. \end_layout \begin_layout Subsubsection* \begin_inset Formula $011_{2}$ \end_inset -- Internal Error \end_layout \begin_layout Standard The node encountered an internal error that prevents it from returning data. \end_layout \begin_layout Subsubsection* \begin_inset Formula $100{}_{2}-111_{2}$ \end_inset -- Node Defined \end_layout \begin_layout Standard Nodes may define additional responses. \end_layout \begin_layout Subsubsection Node ID \end_layout \begin_layout Standard The node ID is the unique ID burned into the microcontroller of the node. \end_layout \begin_layout Subsubsection Data Length \end_layout \begin_layout Standard The length of the data field. Valid values are 0--128. \end_layout \begin_layout Subsubsection Data \end_layout \begin_layout Standard Packet data. The structure and meaning of this data is defined by the particular type of node being addressed. Multi-byte values within packet data are transmitted least-significant byte first (little-endian). For enumeration reply packets, this field contains the two-byte type code of the node replying. \end_layout \begin_layout Subsubsection CRC \end_layout \begin_layout Standard Data corruption during transmission is detected by computing a CRC (16-bit, polynomial 0x1021, initial value 0xFFFF) of all the bytes in the packet up to the CRC (excluding the start byte), and comparing it with the CRC at the end. If they do not match, the packet has been corrupted, and is discarded without a response. The following C code can be used to calculate the CRC: \end_layout \begin_layout Standard \begin_inset listings inline false status open \begin_layout Plain Layout #include \end_layout \begin_layout Plain Layout \end_layout \begin_layout Plain Layout /* Calculate CRC of a Sense/Net packet. packet[0] is the header. \end_layout \begin_layout Plain Layout * If this function is computed over a whole packet, including the \end_layout \begin_layout Plain Layout * CRC at the end, a return value of 0 indicates a valid packet. */ \end_layout \begin_layout Plain Layout uint16_t calc_crc(uint8_t *packet, int packet_length){ \end_layout \begin_layout Plain Layout uint16_t remainder = 0xFFFF; \end_layout \begin_layout Plain Layout for (int i = 0; i < packet_length; i++){ \end_layout \begin_layout Plain Layout remainder ^= packet[i] << 8; \end_layout \begin_layout Plain Layout for (int bit = 8; bit > 0; bit--){ \end_layout \begin_layout Plain Layout if (remainder & 0x8000){ \end_layout \begin_layout Plain Layout remainder = (remainder << 1) ^ 0x1021; \end_layout \begin_layout Plain Layout } else { \end_layout \begin_layout Plain Layout remainder = (remainder << 1); \end_layout \begin_layout Plain Layout } \end_layout \begin_layout Plain Layout } \end_layout \begin_layout Plain Layout } \end_layout \begin_layout Plain Layout return remainder; \end_layout \begin_layout Plain Layout } \end_layout \end_inset \end_layout \begin_layout Subsection Enumeration v2 \end_layout \begin_layout Standard Enumeration is a process that allows the controller to discover all nodes attached to the bus. The method is similar to that of the 1-wire protocol. The process recursively discovers the value of each bit in each node's ID. \end_layout \begin_layout Standard At each step in the process, the controller sends an enumeration packet giving bit values for zero or more bits in the header, working from LSB to MSB and first to last. If a node's corresponding ID bits match, it replies with a byte containing the value of the next bit in its ID, as well as the complement of that bit. By using the RS-485 transceiver in an unusual way, the bus can be placed in a wired-AND state when the bit values are being sent. This allows for conflicts (two nodes having different values of the bit) to be detected. Based on the bit and complement values from each query, the controller builds a binary tree of ID bit possibilities. \end_layout \begin_layout Standard While the receiver is listening for an enumeration reply, the bus is put into wired-AND state during the portion of the reply packet containing the next bit and complement values. This wired-AND state is created using the failsafe feature of the RS-485 receiver. When the bus is open or shorted, the receiver outputs a 1. Therefore, each node should transmit a 0 if it intends to send a 0 and disable its transmitter if it intends to send a 1. When a conflict occurs, the node(s) transmitting a 0 will win out without short-circuiting or placing the bus in an indeterminate state. \end_layout \begin_layout Standard \begin_inset Float table wide false sideways false status open \begin_layout Plain Layout \align center \begin_inset Tabular \begin_inset Text \begin_layout Plain Layout Situation \end_layout \end_inset \begin_inset Text \begin_layout Plain Layout Bit Value \end_layout \end_inset \begin_inset Text \begin_layout Plain Layout Complement \end_layout \end_inset \begin_inset Text \begin_layout Plain Layout Bit = 1 \end_layout \end_inset \begin_inset Text \begin_layout Plain Layout 1 \end_layout \end_inset \begin_inset Text \begin_layout Plain Layout 0 \end_layout \end_inset \begin_inset Text \begin_layout Plain Layout Bit = 0 \end_layout \end_inset \begin_inset Text \begin_layout Plain Layout 0 \end_layout \end_inset \begin_inset Text \begin_layout Plain Layout 1 \end_layout \end_inset \begin_inset Text \begin_layout Plain Layout Conflict \end_layout \end_inset \begin_inset Text \begin_layout Plain Layout 0 \end_layout \end_inset \begin_inset Text \begin_layout Plain Layout 0 \end_layout \end_inset \begin_inset Text \begin_layout Plain Layout No Match \end_layout \end_inset \begin_inset Text \begin_layout Plain Layout \emph on (No reply) \end_layout \end_inset \begin_inset Text \begin_layout Plain Layout \end_layout \end_inset \end_inset \end_layout \begin_layout Plain Layout \begin_inset Caption \begin_layout Plain Layout Values of bit and complement in different scenarios. \end_layout \end_inset \begin_inset CommandInset label LatexCommand label name "bit table" \end_inset \end_layout \begin_layout Plain Layout \end_layout \end_inset \end_layout \begin_layout Standard Enumeration command packets contain a single byte of data containing the number of significant bits in the packet address. If a node's address matches the packet address within those significant bits, it replies to the enumeration packet with an enumeration reply. If all 72 bits are significant, the (single) node replies with a fast enumerati on reply, giving its type code. The significant bits are counted from the least-significant bit of the first byte of the node address. If the number of significant bits is 0, all nodes will reply with an enumeratio n reply containing the LSB of the first byte of their address. \end_layout \begin_layout Standard Enumeration replies consist of a single byte, transmitted 2048us after the start bit of the end byte of the enumeration command. Unlike standard packets, there are no start bytes or end bytes with enumeration replies. Bit 0 in the reply byte is 0. Bit 2 in the reply byte is the value of the next significant address bit. Bit 5 is its complement (see table \begin_inset CommandInset ref LatexCommand ref reference "bit table" \end_inset ). Bit 7 is 0. See table \begin_inset CommandInset ref LatexCommand ref reference "enum-reply" \end_inset . \end_layout \begin_layout Standard \begin_inset Float table wide false sideways false status open \begin_layout Plain Layout \align center \begin_inset Tabular \begin_inset Text \begin_layout Plain Layout \emph on Bit Number \end_layout \end_inset \begin_inset Text \begin_layout Plain Layout \emph on 7 \end_layout \end_inset \begin_inset Text \begin_layout Plain Layout \emph on 6 \end_layout \end_inset \begin_inset Text \begin_layout Plain Layout \emph on 5 \end_layout \end_inset \begin_inset Text \begin_layout Plain Layout \emph on 4 \end_layout \end_inset \begin_inset Text \begin_layout Plain Layout \emph on 3 \end_layout \end_inset \begin_inset Text \begin_layout Plain Layout \emph on 2 \end_layout \end_inset \begin_inset Text \begin_layout Plain Layout \emph on 1 \end_layout \end_inset \begin_inset Text \begin_layout Plain Layout \emph on 0 \end_layout \end_inset \begin_inset Text \begin_layout Plain Layout \emph on Value \end_layout \end_inset \begin_inset Text \begin_layout Plain Layout 0 \end_layout \end_inset \begin_inset Text \begin_layout Plain Layout X \end_layout \end_inset \begin_inset Text \begin_layout Plain Layout ~B \end_layout \end_inset \begin_inset Text \begin_layout Plain Layout X \end_layout \end_inset \begin_inset Text \begin_layout Plain Layout X \end_layout \end_inset \begin_inset Text \begin_layout Plain Layout B \end_layout \end_inset \begin_inset Text \begin_layout Plain Layout X \end_layout \end_inset \begin_inset Text \begin_layout Plain Layout 0 \end_layout \end_inset \end_inset \end_layout \begin_layout Plain Layout \begin_inset Caption \begin_layout Plain Layout Enumeration reply byte. X=Don't Care. B=Bit Value. ~B=Complement of Bit Value. \end_layout \end_inset \end_layout \begin_layout Plain Layout \begin_inset CommandInset label LatexCommand label name "enum-reply" \end_inset \end_layout \end_inset \end_layout \end_body \end_document