Sensor board and mote communication protocol (draft 8)


Introduction

 

The following document provides the necessary information for implementing a generic communication interface between the wireless board (mote) and the sensor board. Any kind of sensor board can be connected to the mote using this specification given it provides a SPI peripheral, one input pin with interrupt capability and one digital output. The sensor board must implement a special register set from which all required information can be retrieved.

(warning) Code in under construction at this repository.

Pin out

 

New sensor boards can be seamless connected to a mote if the following characteristics are available:

  • A sensor board with standard slave SPI channel SPI (MOSI, MISO, SCLK, /SS)
  • Frequency of 4MHz for communication, using 8 bits, with with least significant bit (LSB) first
  •  Polarity and Phase clock must be set in mode 0 (both zero) .

Two interrupt lines are provided for indicating critical events. One line is from sensor to mote and the other is from mote to sensor.

  • Sensor → mote interrupt line: When the mote wants to read values from the sensor it puts this line in high beforehand and waits 100ms. This signal is used to wake up the sensor from any possible energy saving mode, waiting for the communication. This line will be kept high while the mote continues to communicates with the sensor. If the sensor board does not provide any energy saving mode (always in active mode) or it can be activated quickly, this line can be ignored. In such situation, SPI chip select (/SS) will be used to detect the communication request.
  • Processor → sensor interrupt line: This line is used for urgent notifications from sensor, indicating any asynchronous event that should be handled immediately . It may be an indication of an external event that can not wait for normal read cycle or a sensor failure, for instance. The mote will read the status register to acknowledge the interrupt, detecting the type of event, like a urgent point that should be read or some sensor failure. The sensor will deactivate this line only after the status register is read and a minimum time of 500ms should be respected before making this line active again.

Power supply lines are also provided (VCC and GND). In this case, the mote should be prepared to provide energy for the sensor board or to receive energy from it. Sensor boards that are capable of providing energy will indicate such situation in their identification registry (capability field).

 

Protocol Overview

 

The proposed protocol is based on several access to a register map defined in the sensor board. All accesses are synchronous so each request must be followed by a response and a maximum timeout need to be respected. Any communication frame can not be greater than 96 bytes (TBD). The exact amount of bytes is determined after reading the device identification register and point description registers. The idea is all sensor data fits inside a unique 6LoWPAN frame.

Data types used in this documentation are described in the data types table. There is no string data type and arrays should be considered as a regular array of any basic data type. When describing a field, numbers in front of the data type indicates the array size. For instance, 4L means a sequence of four unsigned longs (16 bytes). If the quantity is omitted it must be considered as 1. All data types that are longer than one byte should be considered as little endian.

 

The generic request frame is below:

SizeDescription
BFrame Size (n+4 bytes) - CRC and size included
BRegister Address
nBFrame Data (if any)
2BCRC

 

Response frames are described below. All answers must be synchronous, with 500ms of timeout. After this timeout two retries can be done, with timeouts of 1000ms and 2000ms, respectively. If sensor board continues not responding, it should be considered in failure state and the mode should try to identify the board again at each one minute.

SizeDescription
BFrame Size (n+5 bytes) - CRC and size included
BRegister Address
B

Response Status (see response code table)

nBFrame Data 
2BCRC

CRC used is CRC16-ANSI (polynomial 0x8005, initial value 0xFFFF). This is the same algorithm used in other protocols like Modbus and a free implementation is available in FreeModbus project. CRC is calculated over header and payload (from size to last payload bye).

Sensor Board Register Map

 

The set of registers that should be implemented are listed below:

AddressAccess RightsDescription
0x00ROSensor Board Interface Version
0x01ROSensor Board Identification
0x02ROSensor Board Status
0x03WOSensor Board Command
0x04RORead Battery Status
0x05WOWrite Battery Status
0x06RORead Battery Charge
0x07WOWrite Battery Charge
0x08WOWireless network status
0x09WOWireless network Strength (RSSI, 0 to 100%)
0x0AWODisplay (when display is available)
0x0BRO Main server address (IPv6)
0x0CROSecondary server address (IPv6)
0x0D to 0x0F--Reserved (Should not be answered) 
0x10 to 0x2FROSensor Point Description (Point 0 to 31)
0x30 to 0x4FRORead Sensor Point (Point 0 to 31)
0x50 to 0x6FWOWrite Sensor Point (Point 0 to 31)
0x70 to 0xFF--Reserved

 

Command Description

Sensor Board Interface Version (0x00)

 

In this register is stored which version of the sensor interface is implemented. At this moment, only version available is 0x00 (alpha version).

 

Request

ValueSizeDescription
0x04BSize
0x00BAddress
CRCSCRC

 

Response

ValueSizeDescription
0x06BSize
0x00BAddress
StatusBResponse status
VersionBInterface version implemented
CRCSCRC

 

Sensor Board Indentication (0x01)

 

This register returns the sensor identification, like serial number, name and the amount of sensor points available. The maximum number of sensor points is 32.


Request

ValueSizeDescription
0x04BSize
0x01BAddress
CRCSCRC

Response
ValueSizeDescription
0x1CBSize
0x01BAddress
StatusBResponse status
Model8BEight bytes describing the model name. This field may be filled with (0x00)
Manufacturer8BEight bytes describing the manufacture name. This field may be filled with (0x00)
IDLSensor board ID
RevisionBHardware revision
PointsBNumber of points (maximum is 32
CapabilitiesBSensor capabilities (see capabilities table)
CRCSCRC
 

Sensor Board Status (0x02)

 

This register holds the sensor board status, following table sensor status table. Critical and asynchronous events may be flagged using this register.


Request

ValueSizeDescription
0x04BSize
0x02BAddress
CRCSCRC


Response

ValueSizeDescription
0x06BSize
0x02BAddress
StatusBResponse status
StatusBSensor Status Code
CRCSCRC


Sensor Board Command (0x03)

A command can be sent to the sensor using this register. Refer to the command table (TDB).

 

Request

ValueSizeDescription
0x05BSize
0x03BAddress
CommandBCommand
CRC2BCRC

 

Response

ValueSizeDescription
0x06BSize
0x03BAddress
StatusBResponse status
StatusBCommand execution result
CRCSCRC

Read Battery status (0x04)

 

If the power supply is provided by the sensor, it should report this information using the sensor capabilities field. In this case, this register is used to read the battery status. Please, refer to the battery status table.


Request 

ValueSizeDescription
0x01BSize
0x04BAddress
CRCSCRC


Response

ValueSizeDescription
0x03BSize
0x04BAddress
StatusBResponse status
StatusBBattery status
CRCSCRC

Write Battery status (0x05)

When the battery is attached to the mote, it can use this register to report battery information to the sensor board. A sensor board with display could show this information to the user.

 

Request

ValueSizeDescription
0x05BSize
0x05BAddress
StatusBBattery status
CRC2BCRC


Response

ValueSizeDescription
0x05BSize
0x05BAddress
StatusBResponse status
CRC2BCRC

Read Battery charge (0x06)

If the power supply is provided by sensor it should report this information using the sensor capabilities field. In this case, this register is used to read the battery charge.


Request 

ValueSizeDescription
0x01BSize
0x06BAddress
CRCSCRC

 

Response

ValueSizeDescription
0x05BSize
0x06BAddress
StatusBResponse status
ChargeBBattery charge (0 to 100%)
CRCSCRC

 

Read Battery charge (0x07)

When the battery is attached to the mote, it can use this register to report battery charge to the sensor board. A sensor board with display could show this information to the user.


Request 

ValueSizeDescription
0x05BSize
0x07BAddress
ChargeBBattery charge (0 to 100%)
CRC2BCRC

 

Response

ValueSizeDescription
0x05BSize
0x07BAddress
StatusBResponse status
CRC2BCRC

 

Wireless network status (0x08)

 

This register is used to report the wireless status to the sensor board. A sensor board with display could show this information to the user. In this case, sensor capability should indicate that wireless information is required.


Request

ValueSizeDescription
0x05BSize
0x08BAddress
ChargeBNetwork status (see table)
CRC2BCRC

 

Response

ValueSizeDescription
0x05BSize
0x08BAddress
StatusBResponse status
CRC2BCRC

Wireless network strength (0x09)

 

This register is used to report the wireless strength to the sensor board. A sensor board with display could show this information to the user. In this case, sensor capability should indicate that wireless information is required.


Request

ValueSizeDescription
0x05BSize
0x09BAddress
ChargeBNetwork signal strngth (0 to 100%)
CRC2BCRC


Response

ValueSizeDescription
0x05BSize
0x09BAddress
StatusBResponse status
CRC2BCRC

Display register (0x0A)

 

If the sensor has some display attached (reported in capabilities field),the mote can use it for bringing information to the user. The display need to have a way to map the ASCII information received for a specific display line. Character displays organized as 24x2 (24 columns and 2 lines) are a natural candidate but other displays can be used since a proper mapping is provided.


Request

ValueSizeDescription
0x1DBSize
0x0ABAddress
LineBDisplay line
Information24BDisplay information, in ASCII
CRC2BCRC

 

Response

ValueSizeDescription
0x05BSize
0x0ABAddress
StatusBResponse status
CRC2BCRC

 

Main server address (0x0B)  

 

This register holds the server address to which the sensor data should be reported.


Request

ValueSizeDescription
0x04BSize
0x0BBAddress
CRC2BCRC


Response

ValueSizeDescription
0x15BSize
0x0BBAddress
StatusBResponse status
IPv616BIPv6 server address
CRC2BCRC

Secondary server address (0x0C)  

 

When the main server is not available (register 0x09), this register holds the secondary server address to which the sensor data should be reported.


Request

ValueSizeDescription
0x04BSize
0x0CBAddress
CRC2BCRC


Response

ValueSizeDescription
0x15BSize
0x0CBAddress
StatusBResponse status
IPv616BIPv6 server address
CRC2BCRC

Sensor Point Description (0x10 to 0x2F)

 

This range of registers is used to provided information about a specific point like point name, access rights, data type, unit and sampling time. It is possible to use the interrupt line and status register to indicate that a reading is pending for this point. The sampling time is specified as a multiple of 250ms and points with sampling time equal to 0 should not be read in the cyclic readings.


Request

ValueSizeDescription
0x04BSize
PointBPoint address (0x10 to 0x2F)
CRCSCRC

 

Response

ValueSizeDescription
0x14BSize
PointBPoint address (0x10 to 0x2F)
StatusBResponse status
Name8BPoint name. This field may be filled with (0x00)
TypeBPoint type
UnitBPoint unit
RightsBAccess rights
SamplingLSampling time (x 250ms)
CRC2BCRC

Read Sensor Point (0x30 to 0x4F)

 

Read the current value for some sensor point. Point description is used to determine the access rights to the point.


Request 

ValueSizeDescription
0x04BSize
PointBPoint address (0x30 to 0x4F)
CRCSCRC

 

Response

ValueSizeDescription
SizeBSize
PointBPoint address (0x30 to 0x4F)
StatusBResponse status
TypeBPoint type (see data types table)
Value-Point value (size depends on point type)
CRC2BCRC


Read/Write Sensor Point (0x50 to 0x6F)

Write the current value for some sensor point. Point description is used to determine the access rights to the point.


Request

ValueSizeDescription
SizeBSize
PointBPoint address (0x50 to 0x6F)
TypeBPoint type (see data types table)
Value-Point value (size depends on point type)
CRC2BCRC

 

Response

ValueSizeDescription
0x05BSize
PointBPoint address (0x50 to 0x6F)
StatusBResponse status
CRC2BCRC


Appendix: Tables

Data Types

Available data types

|------+---------+--------------------------------------------|
| Type | Acronym | Representation |
|------+---------+--------------------------------------------|
| 0x00 | B | Byte, 8 bits unsigned |
| 0x01 | b | Byte, 8 bits signed |
| 0x02 | S | Short, 16 bits unsigned |
| 0x03 | s | Short, 16 bits signed |
| 0x04 | L | Long, 32 bits unsigned |
| 0x05 | l | Long, 32 bits signed |
| 0x06 | Q | Long long, 64 bits unsigned |
| 0x07 | q | Long long, 64 bits signed |
| 0x08 | F | Float, IEEE 754 single precision, 4 bytes |
| 0x09 | D | Double, IEEE 754 double precision, 8 bytes |
|------+---------+--------------------------------------------|

Sensor Status

Sensor status table

|------------+---------------------------------|
| Code | Status |
|------------+---------------------------------|
| 0 | OK (normal operation) |
| 1 | Point 1 urgent reading/writing |
| 2 | Point 2 urgent reading/writing |
| 3 | Point 3 urgent reading/writing |
| ... | ... |
| 31 | Point 31 urgent reading/writing |
| 32 | Point 32 urgent reading/writing |
| 33 to 127 | Reserved |
| 128 | General sensor failure |
| 129 to 255 | Reserved |
|------------+---------------------------------|

Commands

Sensor command table

|-------+---------+--------------------------------|
| Value | Command | Description |
|-------+---------+--------------------------------|
| 0 | Reset | Performs a reset in the sensor |
| ... | ... | ... |
|-------+---------+--------------------------------|

Units

Units table (TDB, maybe a simplified version of hart data types)

|--------+---------+-------------|
| Values | Acronym | Description |
|--------+---------+-------------|

Answer Status

Answer status table

CodeStatus
0Success
1General error
2CRC error
3Value is RO
4Value is WO
5Register not implemented

Access Rights

Access rights table

|-------+---------+---------------------|
| Value | Acronym | Description |
|-------+---------+---------------------|
| 0x01 | RO | Reading only |
| 0x02 | WO | Writing only |
| 0x03 | RW | Reading and writing |
|-------+---------+---------------------|

Sensor Capabilities

Sensor capabilities table

|-----+-------+----------------------------------------------------|
| Bit | Value | Description |
|-----+-------+----------------------------------------------------|
| 0 | 0x01 | Sensor has attached battery |
| 1 | 0x02 | Sensor has attached display |
| 2 | 0x04 | Sensor wants to receive periodic information about |
| | | the wireless network status |
| 3 | 0x08 | Sensor wants to receive periodic information about |
| | | battery status (only valid whtn attached battery |
| | | flag is not set) |
| 4-7 | - | Reserved |
|-----+-------+----------------------------------------------------|

Battery Status

Battery status table

|-------+----------------|
| Value | Description |
|-------+----------------|
| 0 | Charged (100%) |
| 1 | Charging |
| 2 | Discharging |
| 3 | Failure |
|-------+----------------|

Wireless Status

Wireless status table

|-------+-----------------------|
| Value | Description |
|-------+-----------------------|
| 0 | Network not available |
| 1 | Connecting |
| 2 | Connected |
| 3 | Invalid joining key |
| 3 | ... |
| ... | ... |
|-------+-----------------------|