Leave Your Message
News Categories
Featured News

Application of HART Protocol in Intelligent Electromagnetic Flowmeter

2026-03-19

I.Technical Details of the HART Protocol

The HART protocol is based on the ISO OSI open system interconnection reference model, primarily utilizing the first, second, and seventh layers of the OSI model—namely the physical layer, data link layer, and application layer.

1.The physical layer

HART protocol utilizes the Bell 202 Frequency Shift Keying (FSK) standard from the American Telephone and Telegraph Company, employing a ±0.5mA sine wave on a 4-20mA analog signal for digital communication at a baud rate of 1200bps. Since the superimposed sine wave has an average value of 0 and the phase-continuous frequency shift keying technique requires continuous phase angles at the bit boundaries of 1s and 0s at 1200Hz baud rate, the digital communication signal does not interfere with the 4-20mA analog signal.

2.Data Link Layer

The data link layer defines the format of HART frames, including functions for establishing and maintaining data link communication. The HART protocol ensures error-free data transmission through redundant error-check codes, error detection mechanisms, and Automatic Repeat Request (ARQ) protocol.

Protocol-related data transmission is implemented in frame format. A frame encapsulates user control and addressing information with user data, and frame recognition occurs only after the byte count within the frame completes and error checking is successful, or upon termination of signal transmission by the physical layer (e.g., when carrier wave detection fails). The specific format of HART frames is illustrated in the following diagram:

图片1.jpg

PREAMBLE: The preamble signal.
DELIM: A delimiter, a unique or easily recognizable character.
ADDR: Address byte containing source and destination addresses, with the most significant bit indicating the address of the host device associated with the frame.
COM: Command byte, indicating the function to be executed by the field instrument. BYTE CORNT: Total data length, representing the number of bytes from the byte following BYTE CORNT to the last byte (excluding parity bytes).
DATA: Data byte.
CHK: Checksum, vertical parity check.

3.Application Layer Specifications

The document specifies three categories of commands in HART message packets: The first category consists of general commands applicable to all HART-compliant products, providing functional descriptions for compliant devices; the second category includes common operation commands suitable for most HART-compliant products; and the third category comprises device-specific commands designed for specialized HART-compliant products.

II.Software Implementation of HART Communication Protocol

1.Interrupt Program for Intelligent Electromagnetic Flowmeter Serial Port

In the serial port interrupt service routine, the system first safeguards the current execution environment before determining whether the trigger is a receive interrupt or a send interrupt. If it is a receive interrupt, the corresponding receive service subroutine is executed; if it is a send interrupt, the send service subroutine is executed. Upon completion of interrupt handling, the previously saved execution environment is restored and the program returns to the system main program.

The HART communication protocol employs horizontal and vertical parity checking mechanisms to ensure data integrity. When data errors are detected during reception, the system waits until the master device completes command frame transmission before notifying the master device of the reception anomaly. The master device then resends the command frame to maintain communication stability and reliability. The flowchart of the HART serial port interrupt subroutine is illustrated in the following diagram.

图片2.jpg

2.HART command subroutine decomposition

Before processing a command frame, it must first be segmented by verifying the validity of its preamble code. Each received preamble code increments the counter by 1.

Upon receiving another delimiter, if it is a valid delimiter and the preamble count counter exceeds 1, this marks the starting position of the HART frame.

The HART frame type is determined based on the delimiter. If it is a response frame or group mode frame, the receiving service is terminated and carrier termination is awaited. For request frames, the frame format is identified, and the address count value is configured for either long-frame or short-frame formats. Short-frame addresses receive 1 byte, while long-frame addresses receive 5 bytes.

Receive the command number and data byte length byte. If parity check errors occur in the data byte length byte, terminate the reception service and wait for the carrier to end; otherwise, set the data byte length counter, decrementing by 1 for each received data byte.

First, calculate the horizontal checksum. If the received request address matches, perform XOR operations on the HART frame's checksum and compare it with the received checksum. A match indicates no communication error, while a mismatch sets the checksum error flag to 1, terminates the reception service, and initiates the HART command execution subroutine. The command frame splitting process flow is illustrated in the diagram below.

图片3.jpg

III.Experimental Validation and Summary

Through experimental analysis of intelligent electromagnetic flow meters, we have concluded that these devices feature not only high integration but also robust functionality, user-friendly operation, and stable performance. They incorporate self-diagnostic capabilities, self-calibration functions, and HART data communication protocols. Beyond measuring bidirectional flow rates, they can accurately detect pulsating flow patterns. With exceptional electromagnetic interference resistance and temperature tolerance, these flow meters excel in field measurement and display applications. Their wide measurement range and high accuracy make them ideal for practical use.