sfc6000d-20slm Manual
sfc6000d-20slm Manual
SHDLC Interface
Document Summary
This document describes the SHDLC RS485 communication interface of the Sensirion SFC6xxx mass
flow controller and SFM6xxx mass flow meter.
The intention of defining the SHDLC protocol was to have a single protocol for different Sensirion
devices such as mass flow controllers, meters, and other microcontroller devices. The protocol is
based on serial communication and is easy to implement. It allows communication between a single
master and several connected slave devices.
In the following, there are some of the SHDLC protocol key features:
• Single Master/Multiple Slaves protocol without the need for bus arbitration
Contents
1 Hardware ...............................................................................................................................................................4
2 Frame Definition..................................................................................................................................................5
2.5 Command.................................................................................................................................... 6
5.2 Boolean...................................................................................................................................... 12
www.sensirion.com 2 / 26
SFC6xxx and SFM6xxx RS485 SHDLC Interface
6 Commands ..........................................................................................................................................................14
6.3.1 Set Setpoint And Read Measured Value ................................ Error! Bookmark not defined.
7 Appendix..............................................................................................................................................................30
7.1.2 Unit............................................................................................................................................. 31
www.sensirion.com 4 / 26
SFC6xxx and SFM6xxx RS485 SHDLC Interface
1 Hardware
1.1 RS485/RS422
As shown in the picture above, the RS485/422 setup combined with the SHLDC addressing allows to
connect several SHDLC devices on the same bus. Due to the differential signals, the communication is
robust against disturbances and allows long distance data transmission. For long distance data lines a
termination resistor of 120 Ohm is recommended on both ends of the bus. The logic behind the
protocol is based on a UART hardware, using the following settings:
• No Parity
• 1 Stop Bit
www.sensirion.com 4 / 26
SFC6xxx and SFM6xxx RS485 SHDLC Interface
2 Frame Definition
Every transfer in SHDLC is based on MOSI (Master Out Slave In) and MISO (Master In Slave Out)
frames. In the following chapter, the composition of the frames and the meaning of the different
frame parts is shown.
2.1.1.1 Note
In the following, the order of the bytes in frames is defined. The order of the bits inside
a byte (MSb/LSb) is defined by the used hardware.
The MOSI frame is the message sent from master to slave as a request. Communication on the SHDLC
bus is always initiated by the master. Therefore, this frame is always the begin of communication on the
bus:
The begin and end of the frame is marked by start and stop bytes, which are unique bytes (0x7E) in the
frame (guaran- teed by byte suffing, see Section 5.2). After the start byte, the address field defines the
receiver of the frame, followed by the command which tells the slave what to do with the data. Before
the payload data is sent, there is a length information (L) and after the data a checksum to guarantee
the validity of the data.
The MISO frame is the response from a slave device after reception of the MOSI frame. The SHDLC
protocol guarantees an answer on any master request (except broadcast commands). This allows
the master to ensure his request was correctly transferred and processed. The MISO frame looks
as follows:
It is similar to the MOSI frame, except the additional state byte. In this field, the slave reports any
problem during command execution and additional general health information. In the address field,
the slave fills in his own address and in the command field the command which was received and
executed.
www.sensirion.com 5 / 26
SFC6xxx and SFM6xxx RS485 SHDLC Interface
Since SHDLC does not use hardware handshaking, we are using special bytes in the data stream to
mark the begin and end of a frame:
To make this work properly, we have to avoid this byte (0x7E) inside the frame. For this reason, byte
stuffing is used, which means we are replacing 0x7E anywhere inside the frame with a sequence of
two other bytes. This will also be done for Escape (0x7D), XON (0x11) and XOFF (0x13) bytes. The
following table shows how the original data bytes are replaced in the sent data. All other data bytes
are sent 1:1.
The address field in the MOSI frame (1 Byte) defines the receiver of the frame (slave device
address). The address range is divided as follows:
• 0. . . 254: Slave addresses (All device addresses are initially set to 0x0, and can be changed with the
get/set slave address command)
In a MISO frame the address field contains the slave address (address of the slave which has sent the
MISO frame).
2.5 Command
Typically (in a MOSI frame), this field contains the application command which defines for the specific
application what to do with the given data. There are some reserved commands which are used for
special frame transfers. In a MISO frame the slave will return the received and processed command in
the CMD field.
The following table shows the organization of the available command space:
www.sensirion.com 6 / 26
SFC6xxx and SFM6xxx RS485 SHDLC Interface
The MISO frame contains a state byte, which allows the master to detect errors on slave side. There
are two kinds of errors signalized in the state byte:
• Execution Errors
b7 b6 b5 b4 b3 b2 b1 b0
Device
Error Execution error
Flag code
2.7 Length
The length byte defines the number of transferred bytes in the data field (Rx or Tx). It is the length
of the data field before byte stuffing, not the number of bytes which are transferred (because they
contain stuffed bytes).
Example: The sender wants to transmit data [0xA7, 0xB4, 0x7E, 0x24]. Because of byte stuffing, it
needs to transmit the stream [0xA7, 0xB4, 0x7D, 0x5E, 0x24]. The transmitted length information
in this case is 0x04.
The execution error code signalizes all errors which occured while processing the frame or executing
the command. The errors are binary encoded in 7 bits with the following meaning:
Device Error Flag is not used in SFx6xxx, this flag is always zero.
2.8 Data
The data has a usable size of [0. . . 255] bytes (original data, before byte stuffing). The meaning of
the data content is defined in the command section.
www.sensirion.com 7 / 26
SFC6xxx and SFM6xxx RS485 SHDLC Interface
2.9 Checksum
The checksum is built before byte stuffing and checked after removing stuffed bytes from the frame.
It is calculated as follows:
1. Sum all bytes between start and stop (without start and stop bytes)
2. Take the LSB of the result and invert it. This will be the checksum.
2.9.1.1 Length
Consider this MOSI frame (without start/stop and without byte stuffing):
ADR 0x02
CMD 0x43
L 0x04
Data 0 0x64
Data 1 0xA0
Data 2 0x22
Data 3 0xFC
Sum of all Bytes 0x26B
LSB of the Sum 0x6B
Inverted (=Checksum) 0x94
www.sensirion.com 8 / 26
SFC6xxx and SFM6xxx RS485 SHDLC Interface
3 Protocol Definition
This chapter describes the frame communication protocol in a SHDLC system. There are some basic
rules:
1. On every master request (MOSI frame), the slave will respond with a slave response (MISO
frame). There are two exclusions where the slave will not send a response:
2. Between receiving a MOSI frame and sending slave response, the slave will not accept any
other frame from master. In case of a broadcast, the master must wait for the specified
command execution time.
By default, the master sends a standard frame which contains up to 255 bytes Tx data. This is called a
standard frame transfer. Additionally, there are some special frame transfers defined. They are marked
with a special frame identifier in the CMD field of the frame. The following chapters describe the
different transfer types.
In this transfer, the master initiates a transfer with a MOSI frame containing command ID and up to 255
bytes of Tx data. After executing the command, the slave will respond with a MISO frame containing
state and up to 255 bytes of Rx data. The command field of the frame is used for an application
command.
The transfer looks as follows:
After sending a broadcast command (ADR = 0xFF), the slave executes the command but does not send
the generated response. The “Get Broadcast Response” frame allows the master to get the slave
response on a previously sent broadcast command.
The following shows an example with two slaves:
www.sensirion.com 9 / 26
SFC6xxx and SFM6xxx RS485 SHDLC Interface
If the broadcast transfer is followed by a “Get Broadcast Response” frame, the slave will send the
buffered answer. If any other frame is sent, the buffered response is discarded.
The frame to get the broadcast response (MOSI) looks as follows and has to be addressed to a
specific slave device:
In case of a command execution error, the device will return an error response. This response is
transmitted without data (L=0). That means that a simple error response looks alike for any transfer
type:
www.sensirion.com 10 /
26
SFC6xxx and SFM6xxx RS485 SHDLC Interface
4 Protocol Timings
The interbyte time defines the time between two bytes in the same frame. After reception of a frame
byte, the receiver waits for the next frame byte. This time is limited by the interbyte timeout. See the
following timing diagram which defines the interbyte time:
The interbyte timeout is set to 200ms. If a timeout occurs on slave side, the received data is discarded, and
no response frame will be sent to the master.
The slave response time is the time between the MOSI frame has left the master port and the begin of
the reception of the MISO frame. This time is defined in the command reference.
The timeout should be at least twice the specified maximum response time of the corresponding
command and in non real time systems it should not be smaller than 200ms due to possible system
side delays.
www.sensirion.com 11 /
26
SFC6xxx and SFM6xxx RS485 SHDLC Interface
5.1 Integer
Integers can be transmitted as signed or unsigned integers. If signed, use the two’s complement. The
following types of integers are known:
5.2 Boolean
• False = 0
• True = 1. . . 255
For floating-point representation, the IEEE 754 format is used which has the following structure:
Use the following coding to signal invalid float, positive or negative infinity:
www.sensirion.com 12 /
26
SFC6xxx and SFM6xxx RS485 SHDLC Interface
5.4 String
Strings are transferred as C-strings. This means in ASCII coding, one byte per character and
terminated with a final null-character (0x00). The first letter will be sent first.
To make string handling as safe and robust as possible, it’s highly recommended to follow these rules
when implementing an SHDLC master:
• When sending strings to the slave (MOSI data), always terminate the string with exactly one null-
character (0x00). In case a fixed data length is specified for a particular string (e.g. if more MOSI
parameters are following that string), fill all unused data bytes after the null-termination with 0x00
as well. But usually, string parameters are specified with a variable data length, i.e. no such padding
is needed.
• When receiving strings from the slave (MISO data), parse the string up to the first null-character
(0x00) in the received data and discard all the following data bytes (if any). In case no null-
character is contained in the whole frame data, take the received data length into account to
determine the string length, i.e. abort string parsing after the last data byte to accept strings which
are not null-terminated.
www.sensirion.com 13 /
26
SFC6xxx and SFM6xxx RS485 SHDLC Interface
6 Commands
Get Setpoint
Description Get the current flow setpoint as a physical value.
Command ID 0x00
Max. Response Time 10 ms
Post Processing Time 0 ms
MOSI Data Byte # Description
0 Subcommand: uint8
Must be set to 0x01.
MISO Data Byte # Description
0 ... Setpoint: float
3 The current setpoint.
Set Setpoint
Description Set the flow setpoint as a physical value which is used by the flow
controller as
reference input.
Note
the setpoint is set to 0 if calibration is changed
0
Command ID 0x00
Max. Response Time 10 ms
Post Processing Time 0 ms
MOSI Data Byte # Description
0 Subcommand: uint8
Must be set to 0x01.
1 ... Setpoint: float
4 The new setpoint
MISO Data None
www.sensirion.com 14 /
26
SFC6xxx and SFM6xxx RS485 SHDLC Interface
The command returns the average of given numbers of flow measurement as a physical value. A
single measurement has a duration of 1ms, so the command response time depends on the given
number of measurements to average.
www.sensirion.com 15 /
26
SFC6xxx and SFM6xxx RS485 SHDLC Interface
This command is a combination of the two commands "Set Setpoint (0x00)" and "Read Measured
Value (0x08)". It is intended for process data exchange (setpoint and flow) and saves a lot of protocol
overhead compared to separate command usage.
www.sensirion.com 16 /
26
SFC6xxx and SFM6xxx RS485 SHDLC Interface
Note
This configuration is not stored in non-volatile memory
of the device and this not persists after a device reset.
Command ID 0x22
Max. Response Time 10 ms
Post Processing Time 0 ms
MOSI Data Byte # Description
0 Subcommand: uint8
Must be set to 0x00.
1 ... Gain: float
4 The user controller gain to set.
MISO Data None
www.sensirion.com 17 /
26
SFC6xxx and SFM6xxx RS485 SHDLC Interface
Note
This configuration is not stored in non-volatile memory
of the device, and this does not persist after a device
reset.
Command ID 0x22
Max. Response Time 10 ms
Post Processing Time 0 ms
MOSI Data Byte # Description
0 Subcommand: uint8
Must be set to 0x03.
1 ... Init Step: float
4 the user init step to set.
MISO Data None
www.sensirion.com 18 /
26
SFC6xxx and SFM6xxx RS485 SHDLC Interface
Perform a thermal conductivity measurement and return the measured raw tick value. The valve is
automatically closed during the measurement.
Measure Temperature
Command ID 0x30
Max. Response Time 10 ms
Post Processing Time 0 ms
MOSI Data Byte # Description
0 Subcommand: uint8
Must be set to 0x10.
MISO Data Byte # Description
0 ... Temperature: float
3 Measured temperature [°C].
This command allows to read information about all available gas calibrations on the device.
www.sensirion.com 19 /
26
SFC6xxx and SFM6xxx RS485 SHDLC Interface
Get the number of calibrations, i.e. how many calibration the device memory is able to hold.
6.6.1.1 Note
Not all calibrations actually contain a valid gas calibration. Use the command Get
0 Calibration Validity to check which calibrations are valid and thus can be activated.
www.sensirion.com 20 /
26
SFC6xxx and SFM6xxx RS485 SHDLC Interface
www.sensirion.com 21 /
26
SFC6xxx and SFM6xxx RS485 SHDLC Interface
www.sensirion.com 22 /
26
SFC6xxx and SFM6xxx RS485 SHDLC Interface
www.sensirion.com 23 /
26
SFC6xxx and SFM6xxx RS485 SHDLC Interface
Get Calibration
Description This command returns the actual set calibration number of Flow
controller.
Command ID 0x45
Max. Response Time 10 ms
Post Processing Time 0 ms
MOSI Data None
MISO Data Byte # Description
0 ... 3 Calibration Number: uint32
The current activated calibration number.
Set Calibration
Description This command stops the controller, changes the used calibration of
the flow controller and starts the controller. The selected calibration is
stored and also used after a power-on or reset.
Note
Because of the limited write cycles of the flash, this
command should not be called periodically with new
calibration (max. 50’000 times). If calibration is already
0 selected the function will not do a write cycle to flash.
Command ID 0x45
Max. Response Time 50 ms
Post Processing Time 0 ms
MOSI Data Byte # Description
0 ... 3 Calibration Number: uint32
The calibration number to activate.
MISO Data None
This command stops the controller, changes the used calibration of the flow controller and starts
the controller. The selected calibration is not stored to non volatile memory.
www.sensirion.com 24 /
26
SFC6xxx and SFM6xxx RS485 SHDLC Interface
Note
The slave address is stored in non-volatile memory of
the device and thus persists after a device reset. So the
next time connecting to the device, you have to use
the new address. When changing the address of a
slave, make sure there isn’t already a slave with that
address on the same bus! In that case you would get
communication issues which can only be fixed by
disconnecting one of the slaves.
Command ID 0x90
Max. Response Time 50 ms
Post Processing Time 0 ms
MOSI Data Byte # Description
0 Slave Address: uint8
The new slave address to set.
Allowed range: 0 . . . 254
MISO Data None
www.sensirion.com 25 /
26
SFC6xxx and SFM6xxx RS485 SHDLC Interface
Get Baudrate
Description Gets the SHDLC baudrate of the device.
Command ID 0x91
Max. Response Time 10 ms
Post Processing Time 0 ms
MOSI Data None
MISO Data Byte # Description
0 ... 3 Baudrate: uint32
Current baudrate in bit/s.
Set Baudrate
Description Sets the SHDLC baudrate of the device.
Note
The baudrate is stored in non-volatile memory of the
device and thus persists after a device reset. The next
time you connect to the device, you have to use the
new baudrate.
Command ID 0x91
Max. Response Time 50 ms
Post Processing Time 0 ms
MOSI Data Byte # Description
0 ... 3 Baudrate: uint32
The new baudrate in bit/s. Allowed values are 9600,
19200,
38400, 57600 and 115200 (default)
MISO Data None
www.sensirion.com 26 /
26
SFC6xxx and SFM6xxx RS485 SHDLC Interface
6.12 [0xD0] Device Information
Gets the version information for the hardware, firmware and SHDLC protocol.
Get Version
Command ID 0xD1
Max. Response Time 10 ms
Post Processing Time 0 ms
MOSI Data None
MISO Data Byte # Description
0 Firmware Major: uint8
Firmware major version number.
1 Firmware Minor: uint8
Firmware minor version number.
2 Firmware Debug: bool
Firmware debug state. If the debug state is set, the
firmware is
in development.
3 Hardware Major: uint8
Hardware major version number.
4 Hardware Minor: uint8
Hardware minor version number.
5 Protocol Major: uint8
Protocol major version number.
6 Protocol Minor: uint8
Protocol minor version number.
Executes a reset on the device. This has the same effect as a power cycle.
1.1.1.1 Note
The device will reply before executing the reset.
Device Reset
Command ID 0xD3
Max. Response Time 100 ms
© Copyright Sensirion AG, Switzerland 28/33
SFC6xxx and SFM6xxx RS485 SHDLC Interface
Post Processing Time 300 ms
MOSI Data None
MISO Data None
7 Appendix
7.1.1 Prefix
7.1.2 Unit
The state response error codes describe the meaning of the lower 7 bits of the ’state’ byte which is
returned in each MISO frame. See Section 5.6.1 for details.
8 Revision History