UART通讯协议规范_8003525

UART IP Core Specification

Author: Jacob Gorban

gorban@https://www.360docs.net/doc/c76008556.html,

Rev. 0.6

August 11, 2002

This page has been intentionally left blank

Revision History Rev. Date Author Description

0.1 Jacob Gorban First Draft

0.2 27/5/01 Jacob Gorban Added reset values and other changes.

0.3 23/6/01 Jacob Gorban Divisor latch is 16-bit wide update

0.4 17/08/01 Jacob Gorban Modified port names

0.5 03/12/01 Jacob Gorban LSR bits 5,6 clear conditions fixed.

In IIR, THRE was fixed.

Debug registers were added to Registers.

Debug interface was added to Operation.

WISHBONE interface ports width modified and

wb_sel_i signal is added to the list.

0.6 11/08/02 Jacob Gorban Added optional BAUD_O output

Contents

Introduction (1)

IO ports (2)

Clocks (3)

Registers (4)

Operation (13)

Architecture (15)

Introduction The UART (Universal Asynchronous Receiver/Transmitter) core provides serial communication capabilities, which allow communication with modem or other external devices, like another computer using a serial cable and RS232 protocol. This core is designed to be maximally compatible with the industry standard National Semiconductors’ 16550A device.

Features:

? WISHBONE interface in 32-bit or 8-bit data bus modes (selectable)

? FIFO only operation

? Register level and functionality compatibility with NS16550A (but not 16450).

? Debug Interface in 32-bit data bus mode.

IO ports 2.1 WISHBONE interface signals

Direction

Description

Port Width

CLK 1 Input Block’s clock input

Reset

WB_RST_I 1 Input Asynchronous

WB_ADDR_I 5 or 3 Input Used for register selection

signal

WB_SEL_I 4 Input Select

WB_DAT_I 32 or 8 Input Data input

WB_DAT_O 32 or 8 Output Data output

WB_WE_I 1 Input Write or read cycle selection

WB_STB_I 1 Input Specifies transfer cycle

WB_CYC_I 1 Input A bus cycle is in progress

WB_ACK_O 1 Output Acknowledge of a transfer

2.2 Other internal signals

Description

Direction

Port Width

output

INT_O 1 Output Interrupt

BAUD_O 1 Output Optional baud rate output signal.

The signal here is the 16 x actual baud rate.

It is enabled if UART_HAS_BAUDRATE_OUTPUT

is defined

2.3 External (off-chip) connections

Direction Description

Port Width

STX_PAD_O 1 Output The serial output signal

SRX_PAD_I 1 Input The serial input signal

RTS_PAD_O 1 Output Request To Send

DTR_PAD_O 1 Output Data Terminal Ready

CTS_PAD_I 1 Input Clear To Send

DSR_PAD_I 1 Input Data Set Ready

Indicator

RI_PAD_I 1 Input Ring

DCD_PAD_I 1 Input Data Carrier Detect

Clocks

Clocks table:

Rates (MHz) Name Source

Max Min Resolution

Description

clk WISHBONE bus 1258Mhz for 1200 bps 3.6864 for 115200 bps WISHBONE

clock

Registers

4.1 Registers list

Access

Description

Width

Name Address

Receiver Buffer 0 8 R Receiver FIFO output

0 8 W Transmit FIFO input

Transmitter Holding

Register (THR)

interrupts Interrupt Enable 1 8 RW

Enable/Mask

generated by the UART

Interrupt Identification 2 8 R Get interrupt information

FIFO Control 2 8 W Control FIFO options

connection

Line Control Register 3 8 RW Control

Modem Control 4 8 W Controls

modem

R

information

Status

8

Line Status 5

Status

Modem

R

Modem Status 6 8

In addition, there are 2 Clock Divisor registers that together form one 16-bit.

The registers can be accessed when the 7th (DLAB) bit of the Line Control Register is set

to ‘1’. At this time the above registers at addresses 0-1 can’t be accessed.

Access

Description Name Address

Width

Divisor Latch Byte 1 (LSB) 0 8 RW The LSB of the divisor

latch

Divisor Latch Byte 2 1 8 RW The MSB of the divisor

latch

When using 32-bit data bus interface, additional read-only registers are available for

debug purposes:

Description

Access

Width

Name Address

Debug 18 32 R First debug register

Debug 212 32 R Second debug register

4.2 Interrupt Enable Register (IER)

This register allows enabling and disabling interrupt generation by the UART. Bit # Access Description

0 RW Received Data available interrupt

‘0’ – disabled

‘1’ – enabled

1 RW Transmitter Holding Register empty interrupt

‘0’ – disabled

‘1’ – enabled

2 RW Receiver Line Status Interrupt

‘0’ – disabled

‘1’ – enabled

3 RW Modem Status Interrupt

‘0’ – disabled

‘1’ – enabled

7-4 RW Reserved. Should be logic ‘0’.

Reset Value: 00h

4.3 Interrupt Identification Register (IIR)

The IIR enables the programmer to retrieve what is the current highest priority pending interrupt.

Bit 0 indicates that an interrupt is pending when it’s logic ‘0’. When it’s ‘1’ – no interrupt is pending.

The following table displays the list of possible interrupts along with the bits they enable, priority, and their source and reset control.

B i t 3

B i t 2

B i t 1

P r i o r i t y

Interrupt Type Interrupt Source Interrupt Reset Control 0 1 1 1st Receiver Line Status Parity, Overrun or Framing errors or Break Interrupt

Reading the Line Status Register 0 1 0 2nd Receiver Data available FIFO trigger level reached

FIFO drops below trigger level

1 1 0 2nd

Timeout Indication There’s at least 1 character

in the FIFO but no character

has been input to the FIFO or read from it for the last 4 Char times.

Reading from the FIFO (Receiver Buffer Register) 0 0 1 3rd

Transmitter Holding Register empty Transmitter Holding

Register Empty Writing to the

Transmitter Holding Register or reading IIR.

0 0 0 4th Modem Status

CTS, DSR, RI or DCD.

Reading the Modem status register.

Bits 4 and 5: Logic ‘0’.

Bits 6 and 7: Logic ‘1’ for compatibility reason.

Reset Value: C1h

The FCR allows selection of the FIFO trigger level (the number of bytes in FIFO required to enable the Received Data Available interrupt). In addition, the FIFOs can be cleared using this register.

Bit # Access Description

0 W Ignored (Used to enable FIFOs in NS16550D). Since this UART

only supports FIFO mode, this bit is ignored.

1 W Writing a ‘1’ to bit 1 clears the Receiver FIFO and resets its logic.

But it doesn’t clear the shift register, i.e. receiving of the current

character continues.

2 W Writing a ‘1’ to bit 2 clears the Transmitter FIFO and resets its

logic. The shift register is not cleared, i.e. transmitting of the

current character continues.

5-3 W Ignored

7-6 W Define the Receiver FIFO Interrupt trigger level

‘00’ – 1 byte

‘01’ – 4 bytes

‘10’ – 8 bytes

‘11’ – 14 bytes

Reset Value : 11000000b

The line control register allows the specification of the format of the asynchronous data communication used. A bit in the register also allows access to the Divisor Latches, which define the baud rate. Reading from the register is allowed to check the current settings of the communication.

Bit # Access Description

1-0 RW Select number of bits in each character

‘00’ – 5 bits

‘01’ – 6 bits

‘10’ – 7 bits

‘11’ – 8 bits

2 RW Specify the number of generated stop bits

‘0’ – 1 stop bit

‘1’ – 1.5 stop bits when 5-bit character length selected and

otherwise

bits

2

Note that the receiver always checks the first stop bit only.

Enable

3 RW Parity

‘0’ – No parity

‘1’ – Parity bit is generated on each outgoing character and

is checked on each incoming one.

4 RW Even Parity select

‘0’ – Odd number of ‘1’ is transmitted and checked in each word (data and parity combined). In other words, if the data has an

even number of ‘1’ in it, then the parity bit is ‘1’.

‘1’ – Even number of ‘1’ is transmitted in each word.

5 RW Stick Parity bit.

‘0’ – Stick Parity disabled

‘1’ - If bits 3 and 4 are logic ‘1’, the parity bit is transmitted and checked as logic ‘0’. If bit 3 is ‘1’ and bit 4 is ‘0’ then the

parity bit is transmitted and checked as ‘1’.

6 RW Break Control bit

‘1’ – the serial out is forced into logic ‘0’ (break state).

‘0’ – break is disabled

7 RW Divisor Latch Access bit.

‘1’ – The divisor latches can be accessed

‘0’ – The normal registers are accessed

Reset Value: 00000011b

4.6 Modem Control Register (MCR)

The modem control register allows transferring control signals to a modem connected to the UART.

Bit # Access Description

0 W Data Terminal Ready (DTR) signal control

‘0’ – DTR is ‘1’

‘1’ – DTR is ‘0’

1 W Request To Send (RTS) signal control

‘0’ – RTS is ‘1’

‘1’ – RTS is ‘0’

2 W Out1. In loopback mode, connected Ring Indicator (RI) signal input

3 W Out2. In loopback mode, connected to Data Carrier Detect (DCD)

input.

mode

4 W Loopback

‘0’ – normal operation

‘1’ – loopback mode. When in loopback mode, the Serial

Output Signal (STX_PAD_O) is set to logic ‘1’. The signal of the

transmitter shift register is internally connected to the input of the

receiver shift register.

The following connections are made:

DTR ? DSR

RTS ? CTS

Out1 ? RI

Out2 ? DCD

7-5 W Ignored

Reset Value: 0

4.7 Line Status Register (LSR)

Bit # Access Description

0 R Data Ready (DR) indicator.

‘0’ – No characters in the FIFO

‘1’ – At least one character has been received and is in the FIFO.

1 R Overrun Error (OE) indicator

‘1’ – If the FIFO is full and another character has been

received in the receiver shift register. If another character is starting

to arrive, it will overwrite the data in the shift register but the FIFO

will remain intact. The bit is cleared upon reading from the register.

Generates Receiver Line Status interrupt.

‘0’ – No overrun state

2 R Parity Error (PE) indicator

‘1’ – The character that is currently at the top of the FIFO

has been received with parity error. The bit is cleared upon reading

from the register. Generates Receiver Line Status interrupt.

‘0’ – No parity error in the current character

3 R Framing Error (FE) indicator

‘1’ – The received character at the top of the FIFO did not have a valid stop bit. Of course, generally, it might be that all the

following data is corrupt. The bit is cleared upon reading from the

register. Generates Receiver Line Status interrupt.

‘0’ – No framing error in the current character

4 R Break Interrupt (BI) indicator

‘1’ –A break condition has been reached in the current

character. The break occurs when the line is held in logic 0 for a

time of one character (start bit + data + parity + stop bit). In that

case, one zero character enters the FIFO and the UART waits for a

valid start bit to receive next character. The bit is cleared upon

reading from the register. Generates Receiver Line Status interrupt.

‘0’ – No break condition in the current character

5 R Transmit FIFO is empty.

‘1’ – The transmitter FIFO is empty. Generates Transmitter Holding Register Empty interrupt. The bit is cleared when data is

being been written to the transmitter FIFO.

‘0’ – Otherwise

6 R Transmitter Empty indicator.

‘1’ – Both the transmitter FIFO and transmitter shift register are empty. The bit is cleared when data is being been written to the

transmitter FIFO.

‘0’ – Otherwise

7 R ‘1’ – At least one parity error, framing error or break

indications have been received and are inside the FIFO. The bit is

cleared upon reading from the register.

‘0’ – Otherwise.

4.8 Modem Status Register (MSR)

The register displays the current state of the modem control lines. Also, four bits also provide an indication in the state of one of the modem status lines. These bits are set to ‘1’ when a change in corresponding line has been detected and they are reset when the register is being read.

Bit # Access Description

0 R Delta Clear To Send (DCTS) indicator

‘1’ – The CTS line has changed its state.

1 R Delta Data Set Ready (DDSR) indicator

‘1’ – The DSR line has changed its state.

2 R Trailing Edge of Ring Indicator (TERI) detector. The RI line has

changed its state from low to high state.

3 R Delta Data Carrier Detect (DDCD) indicator

‘1’ – The DCD line has changed its state.

4 R Complement of the CTS input or equals to RTS in loopback mode.

5 R Complement of the DSR input or equals to DTR in loopback mode.

6 R Complement of the RI input or equals to Out1 in loopback mode.

7 R Complement of the DCD input or equals to Out2 in loopback mode. 4.9 Divisor Latches

The divisor latches can be accessed by setting the 7th bit of LCR to ‘1’. You should restore this bit to ‘0’ after setting the divisor latches in order to restore access to the other registers that occupy the same addresses. The 2 bytes form one 16-bit register, which is internally accessed as a single number. You should therefore set all 2 bytes of the register to ensure normal operation. The register is set to the default value of 0 on reset, which disables all serial I/O operations in order to ensure explicit setup of the register in the software. The value set should be equal to (system clock speed) / (16 x desired baud rate). The internal counter starts to work when the LSB of DL is written, so when setting the divisor, write the MSB first and the LSB last.

4.10 Debug 1

This register is only available when the core has 32-bit data bus and 5-bit address bus.

It is read only and is provided for debugging purposes of chip testing as it is not part of the original UART16550 device specifications. Reading from the does not influence core’s bahaviour.

7-0 R Line Status Register value.

11-8 R Interrupt Enable Register value (bits 3-0).

15-12 R Interrupt Identifier Register value (bits 3-0).

23-16 R Line Control Register value.

31-24 R Modem Status Register value.

4.11 Debug 2

This register is only available when the core has 32-bit data bus and 5-bit address bus. It is read only and is provided for debugging purposes of chip testing as it is not part of the original UART16550 device specifications. Reading from the does not influence core’s bahaviour.

Bit # Access Description

2-0 R Transmitter FSM state

7-3 R Number of characters in Transmitter FIFO (tf_count)

11-8 R Receiver FSM state

16-12 R Number of characters in Receiver FIFO (rf_count)

18-17 R Modem Control Register value (bits 4-0)

23-19 R FIFO Control Register value (bits 7-6)

31-24 R Reserved. Returned value is 0.

5

Operation

This UART core is very similar in operation to the standard 16550 UART chip with the main exception being that only the FIFO mode is supported. The scratch register is removed, as it serves no purpose.

This core can operate in 8-bit data bus mode or in 32-bit bus mode, which is now the default mode.

The 32-bit mode is fully WISHBONE compatible and it uses the WISHBONE [SEL_I] signal to properly receive and return 8-bit data on 32-bit data bus. The 8-bit version might have problems in various WISHBONE implementations because a 32-bit master reading from 8-bit bus can expect data on different bytes of the 4-byte word, depending on the register address.

Also, in 32-bit data bus mode, the [ADR_I] is 5 and not 3 bits wide.

In addition, in the 32-bit data bus mode a debug interface is present in the system. This interface has 2 32-bit registers that can be read to provide non-intrusive look into the core’s registers and other internal values of importance.

The selection between 32- and 8-bits data bus modes is performed by defining

DATA_BUS_WIDTH_8 in uart_defines.v, uart_top.v or on the compiler/synthesizer tool command line.

5.1 Initialization

Upon reset the core performs the following tasks:

? The receiver and transmitter FIFOs are cleared.

? The receiver and transmitter shift registers are cleared

? The Divisor Latch register is set to 0.

? The Line Control Register is set to communication of 8 bits of data, no parity, 1 stop bit.

? All interrupts are disabled in the Interrupt Enable Register.

For proper operation, perform the following:

? Set the Line Control Register to the desired line control parameters. Set bit 7 to ‘1’ to allow access to the Divisor Latches.

? Set the Divisor Latches, MSB first, LSB next.

? Set bit 7 of LCR to ‘0’ to disable access to Divisor Latches. At this time the

transmission engine starts working and data can be sent and received.

? Set the FIFO trigger level. Generally, higher trigger level values produce less

interrupt to the system, so setting it to 14 bytes is recommended if the system

responds fast enough.

? Enable desired interrupts by setting appropriate bits in the Interrupt Enable

register.

Remember that (Input Clock Speed)/(Divisor Latch value) = 16 x the communication baud rate. Since the protocol is asynchronous and the sampling of the bits is performed in the perceived middle of the bit time, it is highly immune to small differences in the clocks of the sending and receiving sides, yet no such assumption should be made when calculating the Divisor Latch values.

6

Architecture The core implements the WISNBONE SoC bus interface for communication with the system. It has an 8-bit data bus for compatibility reason. The core requires one interrupt.

It requires 2 pads in the chip (serial in and serial out) and, optionally, another six modem control signals, which can otherwise be implemented using general purpose I/Os on the chip.

The block diagram of the core is on the following page.

通信协议(ASCII)

组态王与单片机协议 1.通讯口设置: 通讯方式:RS-232,RS-485,RS-422均可。 波特率:由单片机决定(2400,4800,9600and19200bps)。 注意:在组态王中设置的通讯参数如波特率,数据位,停止位,奇偶校验必须与单片机编程中的通讯参数一致 2.在组态王中定义设备地址的格式 格式:##.# 前面的两个字符是设备地址,范围为0-255,此地址为单片机的地址,由单片机中的程序决定; 后面的一个字符是用户设定是否打包,“0”为不打包、“1”为打包,用户一旦在定义设备时确定了打包,组态王将处理读下位机变量时数据打包的工作。 注意:在组态王中定义变量时,一个X寄存器根据所选数据类型(BYTE,UINT,FLOAT)的不同分别占用一个、两个,四个字节,定义不同的数据类型要注意寄存器后面的地址,同一数据区内不可交叉定义不同数据类型的变量。为提高通讯速度建议用户使用连续的数据区。 例如, 1、在单片机中定义从地址0开始的数据类型为BYTE型的变量: 则在组态王中定义相应的变量的寄存器为X0、X1、X2、X3、X4。。。。。。。。,数据类型为BYTE,每个变量占一个字节 2、在单片机中定义从地址100开始的数据类型为UINT型的变量: 则在组态王中定义相应的变量的寄存器为X100、X102、X104、X106、X108。。。。。。。。,数据类型UINT,每个变量占两个字节 3、在单片机中定义从地址200开始的数据类型为FLOAT型的变量: 则在组态王中定义相应的变量的寄存器为X200、X204、X208、X212。。。。。。。,数据类型FLOAT,每个变量占四个字节 3.组态王与单片机通讯的命令格式:

单片机串口通信协议程序

#include #include #define R55 101 #define RAA 202 #define RLEN 203 #define RDATA 104 #define RCH 105 //#define unsigned char gRecState=R55; unsigned char gRecLen; unsigned char gRecCount; unsigned char RecBuf[30]; unsigned char gValue; void isr_UART(void) interrupt 4 using 1 { unsigned char ch; unsigned char i; unsigned char temp; if (RI==1) { ch=SBUF; switch(gRecState) { case R55: // wait 0x55 if (ch==0x55) gRecState=RAA; break;

case RAA: if (ch==0xaa) gRecState=RLEN; else if (ch==0x55) gRecState=RAA; else gRecState=R55; break; case RLEN: gRecLen=ch; gRecCount=0; gRecState=RDATA; break; case RDATA: RecBuf[gRecCount]=ch; gRecCount++; if (gRecCount>=gRecLen) { gRecState=RCH; } break; case RCH: temp=0; for(i=0;i

常用无线通信协议

常用无线通信协议 目前使用较广泛的近距无线通信技术有蓝牙(Bluetooth),无线局域网802.11(Wi-Fi)和红外线数据传输(IrDA).此外,还有一些具有发展潜力的近距无线技术标准,分别是ZigBee,超宽频,短距通信,WiMedia,GPS,DECT,无线1394和专用无线系统等。 蓝牙(Bluetooth)技术 蓝牙是一种支持设备短距离通信的无线电技术。它是一种无线数据与语音通信的开放性全球规范,它以低成本的短距离无线连接为基础,可为固定的或移动的终端设备提供廉价的接入服务。蓝牙技术的实质内容是为固定设备或移动设备之间的通信环境建立通用的近距无线接口,将通信技术与计算机技术进一步结合起来,使各种设备在没有电线或电缆相互连接的情况下,能在近距离范围内实现相互通信或操作。其传输频段为全球公众通用的2.4GHzISM频段,提供1Mbps的传输速率和10m 的传输距离。 优势:⑴全性高。蓝牙设备在通信时,工作的频率是不停地同步变化的,也就是跳频通信。双方的信息很难被抓获,防止被破解或恶意插入欺骗信息。⑵于使用。蓝牙技术是一项即时技术,不要求固定的基础设施,且易于安装和设置。 不足:⑴通信速度不高。蓝牙设备的通信速度较慢,有很多的应用需求不能得到满足。⑵传输距离短。蓝牙规范最初为近距离通信而设计,所以他的通信距离比较短,一般不超过10m。 Wi-Fi(无线高保真)技术 无线宽带是Wi-Fi的俗称。所谓Wi-Fi就是IEEE 802.11b的别称,它是一种短程无线传输技术,能够在数百英尺范围内支持互联网接入的无线电信号。Wi-Fi速率最高可达11Mb/s,电波的覆盖范围可达200m左右。 优势:⑴覆盖广。其无线电波的覆盖范围广,穿透力强。可以方便地为整栋大楼提供无线的宽带互联网的接入。⑵速度高。Wi-Fi技术的传输速度非常快,通信速度可达300Mb/s,能满足用户接入互联网,浏览和下载各类信息的要求。 不足:安全性不好。由于Wi-Fi设备在通信中没有使用跳频等技术,虽然使用了加密协议,但还是存在被破解的隐患。 IrDA(红外线数据协会)技术 IrDA是一种利用红外线进行点对点通信的技术,是第一个实现无线个人局域网(PAN)的技术。 IrDA 的主要优点是无需申请频率的使用权,因而红外通信成本低廉。并且还具有移动通信所需的体积小、功耗低、连接方便、简单易用的特点。此外,红外线发射角度较小,传输上安全性高。IrDA的不足在于它是一种视距传输,两个相互通信的设备之间必须对准,中间不能被其它物体阻隔,因而该技术只能用于 2 台(非多台)设备之间的连接。 优势:⑴无需申请频率的使用权,因此红外线通信成本低廉。⑵移动通信所需的体积小、功耗低、连接方便、简单易用。⑶外线发射角度较小,传输上安全性高。 不足:IrDA是一种视距传输,两个相互通信的设备之间必须对准,中间不能被其它物体阻隔,因而只用于两台设备之间连接。ZigBee(紫蜂)技术 ZigBee使用2.4 GHz 波段,采用跳频技术。它的基本速率是250kb/s,当降低到28kb/s 时,传输范围可扩大到134m,并获得更高的可靠性。另外,它可与254个节点联网。 优势:⑴功耗低。在低耗电待机模式下,两节普通5号干电池可使用6个月以上。⑵成本低。因ZigBee数据传输速率低,协议简单,所以成本很低。⑶网络容量大。每个ZigBee网络最多可支持255个设备。⑷作频段灵活。使用的频段分别为2.4GHz、868MHz(欧)及915MHz(美),均为免执照频段。 不足:⑴数据传输速率低。只有10kb/s~250kb/s,专注于低传输应用。⑵有效范围小。有效覆盖范围为10~75m之间,具体依据实际发射功率的大小和各种不同的应用模式而定,基本上能够覆盖普通的家庭或办公室环境。 UWB(超宽带)技术 UWB(Ultra Wideband)是一种无线载波通信技术,利用纳秒级的非正弦波窄脉冲传输数据,因此其所占的频谱范围很宽。UWB 有可能在10 m 范围内,支持高达110 Mb/s的数据传输率,不需要压缩数据,可以快速、简单、经济地完成视频数据处理。 特点:⑴系统复杂度低,发射信号功率谱密度低,对信道衰落不敏感,载货能力低。⑵定位精度高,相容性好,速度高。⑶成本低,功耗低,可穿透障碍物。近距离无线传输 NFC(近距离无线传输)技术 NFC采用了双向的识别和连接。在20cm 距离内工作于13.56MHz 频率范围。NFC现已发展成无线连接技术。它能快速自动地建立无线网络,为蜂窝设备、蓝牙设备、Wi-Fi 设备提供一个“虚拟连接”,使电子设备可以在短距离范围进行通讯。 特点:NFC的短距离交互大大简化了整个认证识别过程,使电子设备间互相访问更直接、更安全和更清楚,不用再听到各种电子杂音。NFC 通过在单一设备上组合所有的身份识别应用和服务,帮助解决记忆多个密码的麻烦,同时也保证了数据的安全保护。此外NFC 还可以将其它类型无线通讯(如Wi-Fi 和蓝牙)“加速”,实现更快和更远距离的数据传输。

水文通信协议规范

湖南省山洪灾害监测预警系统水文通信协议规范

目录 1 总则 (1) 2 术语、符号和代号 (3) 3 数据报文传输规约 (5) 3.1帧结构 (5) 3.1.1本标准采用异步式传输帧格式。 (5) 3.1.2传输规则应按以下规定执行 (5) 3.1.3链路层应符合以下规定: (6) 3.1.4报文传输 (7) 3.2链路传输 (8) 3.3物理层规约 (9) 4 数据传输报文及数据结构 (10) 4.1应用层数据编码规定 (10) 4.1.1链路用户数据编码格式 (10) 4.1.2站点水情信息编报 (11) 4.1.3水情信息编码分类码 (11) 4.1.4水情站码 (12) 4.1.5测报时间码 (12) 4.1.6要素标识符 (13) 4.1.7数据编码 (14) 4.2水文信息编码 (14) 4.2.1降雨量编码 (14) 4.2.2蒸发量编码 (16) 4.2.3河道水情编码 (17) 4.2.4水库(湖泊)水情编码 (19) 4.2.5闸坝水情编码 (20) 4.2.6泵站水情编码 (22) 4.2.7潮汐水情编码 (23) 4.2.8土壤墒情编码 (25) 4.3数据传输报文结构 (27) 4.3.1 链路测试(AFN=02H) (27) 4.3.2 参数设置(AFN=04H) (28) 4.3.3 参数查询(AFN=0AH) (31) 4.3.4 控制命令(AFN=0CH) (32) 5 通信方式和误码率 (34) 5.1通信方式 (34) 5.2误码率 (36) 6 仪表设备数据传输规约 (37) 6.1仪表数据通信规约 (37)

7 数据传输的考核 (38) 7.1考核内容和指标 (38) 7.2考核方法 (38) 附录A 事件记录表 (39) 附录B 编码要素及标识符汇总表 (40) 附录C本标准用词说明 (47)

串口通信协议

串口通讯—通信协议 所谓通信协议是指通信双方的一种约定。约定包括对数据格式、同步方式、传送速度、传送步骤、检纠错方式以及控制字符定义等问题做出统一规定,通信双方必须共同遵守。因此,也叫做通信控制规程,或称传输控制规程,它属于ISO'S OSI七层参考模型中的数据链路层。 目前,采用的通信协议有两类:异步协议和同步协议。同步协议又有面向字符和面向比特以及面向字节计数三种。其中,面向字节计数的同步协议主要用于DEC公司的网络体系结构中。 一、物理接口标准 1.串行通信接口的基本任务 (1)实现数据格式化:因为来自CPU的是普通的并行数据,所以,接口电路应具有实现不同串行通信方式下的数据格式化的任务。在异步通信方式下,接口自动生成起止式的帧数据格式。在面向字符的同步方式下,接口要在待传送的数据块前加上同步字符。 (2)进行串-并转换:串行传送,数据是一位一位串行传送的,而计算机处理数据是并行数据。所以当数据由计算机送至数据发送器时,首先把串行数据转换为并行数才能送入计算机处理。因此串并转换是串行接口电路的重要任务。 (3)控制数据传输速率:串行通信接口电路应具有对数据传输速率——波特率进行选择和控制的能力。 (4)进行错误检测:在发送时接口电路对传送的字符数据自动生成奇偶校验位或其他校验码。在接收时,接口电路检查字符的奇偶校验或其他校验码,确定是否发生传送错误。 (5)进行TTL与EIA电平转换:CPU和终端均采用TTL电平及正逻辑,它们与EIA采用的电平及负逻辑不兼容,需在接口电路中进行转换。 (6)提供EIA-RS-232C接口标准所要求的信号线:远距离通信采用MODEM时,需要9根信号线;近距离零MODEM方式,只需要3根信号线。这些信号线由接口电路提供,以便与MODEM或终端进行联络与控制。 2、串行通信接口电路的组成 为了完成上述串行接口的任务,串行通信接口电路一般由可编程的串行接口芯片、波特率发生器、EIA 与TTL电平转换器以及地址译码电路组成。其中,串行接口芯片,随着大规模继承电路技术的发展,通用的同步(USRT)和异步(UART)接口芯片种类越来越多,如下表所示。它们的基本功能是类似的,都能实现上面提出的串行通信接口基本任务的大部分工作,且都是可编程的。才用这些芯片作为串行通信接口电路的核心芯片,会使电路结构比较简单。 3.有关串行通信的物理标准 为使计算机、电话以及其他通信设备互相沟通,现在,已经对串行通信建立了几个一致的概念和标准,这些概念和标准属于三个方面:传输率,电特性,信号名称和接口标准。 1、传输率:所谓传输率就是指每秒传输多少位,传输率也常叫波特率。国际上规定了一个标准波特率系列,标准波特率也是最常用的波特率,标准波特率系列为110、300、600、1200、4800、9600和19200。大多数CRT终端都能够按110到9600范围中的任何一种波特率工作。打印机由于机械速度比较慢而使传输波特率受到限制,所以,一般的串行打印机工作在110波特率,点针式打印机由于其内部有较大的行缓冲

模块通讯协议

电脑通讯协议 数据格式说明: 0XAF,0XAF:同步头 0X00,0X00:ID码(一般是0X00,0X00) 0XAF:头 0X80,0X00:命令码(上位机发码是0X80,YY,单片几发码给电脑0X00,YY)LEN:数据长度是从LEN开始到CS的数据个数,不包括LEN和CS CS:是验证码,CS前面所有数据之和%0XFF 结束码:0X0D 0X0A 举例: 设置空中参数为9600代码为: AF AF 00 00 AF 80 03 02 04 00 96 0D 0A 读取空中参数代码为: AF AF 00 00 AF 80 04 02 00 00 93 0D 0A //*************************************************************** **** 02发码设置串口 AF AF 00 00 AF 80 01 LEN XX YY CS 0D 0A XX:01-1200 02-2400 03-4800 04-9600 05-19200 06-38400 07-56700 08-115200 YY:00-无验证 01-偶验证 02-奇验证 答应回码 AF AF 00 00 AF 00 01 LEN XX YY CS 0D 0A XX:01-1200 02-2400 03-4800

05-19200 06-38400 07-56700 08-115200 YY:00-无验证 01-验证 02-奇验证 //*************************************************************** **** 03读串口参数 //读串口参数 //AF AF 00 00 AF 80 02 LEN 00 00 CS 0D 0A //答应参数 //AF AF 00 00 AF 00 02 LEN XX YY CS 0D 0A XX:01-1200 02-2400 03-4800 04-9600 05-19200 06-38400 07-56700 08-115200 YY:00-无验证 01-偶验证 02-奇验证 //*************************************************************** **** 04设空中参数// //AF AF 00 00 AF 80 03 LEN XX YY CS 0D 0A //XX 01-1200 02-2400 03-4800 04-9600 05-19200 06-38400 07-56700 08-115200 YY=0 //答应参数 //AF AF 00 00 AF 00 03 LEN XX YY CS 0D 0A //XX 01-1200 02-2400 03-4800

51串口通信协议(新型篇)

51串口通信协议(新型篇) C51编程:这是网友牛毅编的一个C51串口通讯程序! //PC读MCU指令结构:(中断方式,ASCII码表示) //帧:帧头标志|帧类型|器件地址|启始地址|长度n|效验和|帧尾标志 //值: 'n' 'y'| 'r' | 0x01 | x | x | x |0x13 0x10 //字节数: 2 | 1 | 1 | 1 | 1 | 1 | 2 //求和: ///////////////////////////////////////////////////////////////////// //公司名称:*** //模块名:protocol.c //创建者:牛毅 //修改者: //功能描述:中断方式:本程序为mcu的串口通讯提供(贞结构)函数接口,包括具体协议部分 //其他说明:只提供对A T89c51具体硬件的可靠访问接口 //版本:1.0 //信息:QQ 75011221 ///////////////////////////////////////////////////////////////////// #include #include //预定义 //帧 #define F_ST1 0x6e //帧头标志n #define F_ST2 0x79 //帧头标志y #define F_R 0x72 //帧类型读r #define F_W 0x77 //帧类型写w #define F_D 0x64 //帧类型数据帧d #define F_B 0x62 //帧类型写回应帧b #define F_C 0x63 //帧类型重发命令帧c #define F_Q 0x71 //帧类型放弃帧q #define F_ADDR 0x31 //器件地址0-9 #define F_END 0x7a //帧尾标志z #define F_SPACE 0x30 //空标志0 #define F_ERR1 0x31 //错误标志1,flagerr 1 #define F_ERR2 0x32 //错误标志2 2 //常数 #define S_MAXBUF 16 //接收/发送数据的最大缓存量 #define FIELD_MAXBUF 48 //最小场缓存,可以大于48字节,因为协议是以20字节为

常用网络通信协议简介

常用网络通信协议简介 常用网络通信协议 物理层: DTE(Data Terminal Equipment):数据终端设备 DCE(Data Communications Equipment):数据电路端接设备 #窄宽接入: PSTN ( Public Switched Telephone Network )公共交换电话网络 ISDN(Integrated Services Digital Network)ISDN综合业务数字网 ISDN有6种信道: A信道 4khz模拟信道 B信道 64kbps用于语音数据、调整数据、数字传真 C信道 8kbps/16kbps的数字信道,用于传输低速数据 D信道 16kbps数字信道,用于传输用户接入信令 E信道 64kbps数字信道,用于传输内部信令 H信道 384kbps高速数据传输数字信道,用于图像、视频会议、快速传真等. B代表承载, D代表Delta. ISDN有3种标准化接入速率: 基本速率接口(BRI)由2个B信道,每个带宽64kbps和一个带宽16kbps的D信道组成。三个信道设计成2B+D。 主速率接口(PRI) - 由很多的B信道和一个带宽64Kbps的D信道组成,B信道的数量取决于不同的国家: 北美和日本: 23B+1D, 总位速率1.544 Mbit/s (T1) 欧洲,澳大利亚:30B+2D,总位速率2.048 Mbit/s (E1) FR(Frame Relay)帧中继

X.25 X.25网络是第一个面向连接的网络,也是第一个公共数据网络. #宽带接入: ADSL:(Asymmetric Digital Subscriber Line)非对称数字用户环路 HFC(Hybrid Fiber,Coaxial)光纤和同轴电缆相结合的混合网络 PLC:电力线通信技术 #传输网: SDH:(Synchronous Digital Hierarchy)同步数字体系 DWDM:密集型光波复用(DWDM:Dense Wavelength Division Multiplexing)是能组合一组光波长用一根光纤进行传送。这是一项用来在现有的光纤骨干网上提高带宽的激光技术。更确切地说,该技术是在一根指定的光纤中,多路复用单个光纤载波的紧密光谱间距,以便利用可以达到的传输性能(例如,达到最小程度的色散或者衰减)。 #无线/卫星: LMDS:(Local Multipoint Distribution Services)作区域多点传输服务。这是一种微波的宽带业务,工作在28GHz附近频段,在较近的距离双向传输话音、数据和图像等信息。 GPRS:(General Packet Radio Service)通用分组无线服务技术。 3G:(3rd-generation,3G)第三代移动通信技术 DBS:(Direct Broadcasting Satellite Service)直播卫星业务 VAST: 协议:RS-232、RS-449、X.21、V.35、ISDN、FDDI、IEEE802.3、IEEE802.4、IEEE802.5等。 RS-232:是个人计算机上的通讯接口之一,由电子工业协会(Electronic Industries

多机通信协议规范

通信协议 来自中国工控网 所谓通信协议是指通信双方的一种约定。约定包括对数据格式、同步方式、传送速度、传送步骤、 检纠错方式以及控制字符定义等问题做出统一规定,通信双方必须共同遵守。因此,也叫做通信控制规程,或称传输控制规程,它属于ISO'S OSI七层参考模型中的数据链路层。 目前,采用的通信协议有两类:异步协议和同步协议。同步协议又有面向字符和面向比特以及面向 字节计数三种。其中,面向字节计数的同步协议主要用于DEC公司的网络体系结构中。 串行通讯简单认识 串行通讯的基本概念:与外界的信息交换称为通讯。基本的通讯方式有并行通讯和串行通讯两种。 一条信息的各位数据被同时传送的通讯方式称为并行通讯。并行通讯的特点是:各数据位同时传送,传送速度快、效率高,但有多少数据位就需多少根数据线,因此传送成本高,且只适用于近距离(相距 数米)的通讯。 一条信息的各位数据被逐位按顺序传送的通讯方式称为串行通讯。串行通讯的特点是:数据位传送,传按位顺序进行,最少只需一根传输线即可完成,成本低但送速度慢。串行通讯的距离可以从几米到几 千米。 根据信息的传送方向,串行通讯可以进一步分为单工、半双工和全双工三种。信息只能单向传送为 单工;信息能双向传送但不能同时双向传送称为半双工;信息能够同时双向传送则称为全双工。 串行通讯又分为异步通讯和同步通讯两种方式。在单片机中,主要使用异步通讯方式。 MCS_51单片机有一个全双工串行口。全双工的串行通讯只需要一根输出线和一根输入线。数据的输 出又称发送数据(TXD),数据的输入又称接收数据(RXD)。串行通讯中主要有两个技术问题,一个是数 据传送、另一个是数据转换。数据传送主要解决传送中的标准、格式及工作方式等问题。数据转换是指 数据的串并行转换。具体说,在发送端,要把并行数据转换为串行数据;而在接收端,却要把接收到的 串行数据转换为并行数据。 单工、半双工和全双工的定义 如果在通信过程的任意时刻,信息只能由一方A传到另一方B,则称为单工。 如果在任意时刻,信息既可由A传到B,又能由B传A,但只能由一个方向上的传输存在,称为半双工传输如果在任意时刻,线路上存在A到B和B到A的双向信号传输,则称为全双工。 电话线就是二线全双工信道。由于采用了回波抵消技术,双向的传输信号不致混淆不清。双工信道有时也发信道分开,采用分离的线路或频带传输相反方向的信号,如回线传输。 --------> <--------> --------> A---------B A----------B A---------B <-------- 单工半双工全双工

AB DF1串口通讯协议API接口

Fax: 1-703-709-0985 https://www.360docs.net/doc/c76008556.html, Allen-Bradley DF1 Serial Communication Interface API The DASTEC Corporation Allen-Bradley DF1 Serial Communication Interface API allows the user to implement bi-directional serial communications to exchange data between applications running on a Windows/WinCE-based system with other devices supporting the Allen-Bradley DF1 full-duplex serial protocol. The devices can be AB devices, other host computers or even other system applications using the API. The Allen-Bradley DF1 Serial Communication Interface API enables a system to acts as a client device to other Allen-Bradley peer devices, initiating read and write operations on behalf of the system applications. The API also allows the system to emulate an Allen-Bradley PLC to respond to read and write requests and thus acts as a “virtual PLC” to other AB peers. The API is available for different Windows/WinCE-based systems/platforms and can be used with C/C++ or Visual Basic. The API consists of two component functionalities, client side and server side. The client side functionality is implemented with a single API DLL. Server side functionality is implemented with a DLL/executable pair. Together these components manage all aspects of the protocol and data exchange including responding to peers with proper acknowledgements, error/success codes and protocol data byte ordering. The system application need only to deal with the data values exchanged in native byte order. The user can employ either the API’s client, server or both functionalities with minimal code implementation.

通讯协议大全

T C P/I P TCP/IP是网络中使用的基本的通信协议。 TCP/IP协议包括TCP、IP、UDP、ICMP、RIP、TELNETFTP、SMTP、ARP、TFTP等许多协议,这些协议一起称为TCP/IP协议。 IPX/SPX(多用于局域网) 是基于施乐的XEROX’S Network System(XNS)协议,而SPX是基于施乐的XEROX’S SPP (Sequenced Packet Protocol:顺序包协议)协议 NetBEUI 即NetBios Enhanced User Interface,或NetBios增强用户接口。 网络通信协议: RS-232-C、RS-449、V.35、X.21、HDLC 简单网络管理协议: 简单网络管理协议SNMP、点到点协议PPP 3G标准: WCDMA(欧洲版)、CDMA2000(美国版)和TD-SCDMA(中国版) Modbus协议 Modbus就是工业控制器的网络协议中的一种 包括ASCII、RTU和TCP

现在Modbus已经是工业领域全球最流行的协议。此协议支持传统的RS-232、RS-422、RS-485和以太网设备。许多工业设备,包括PLC,DCS,智能仪表等都在使用Modbus协议作为他们之间的通讯标准。有了它,不同厂商生产的控制设备可以连成工业网络,进行集中监控。 网络协议大全 1、ARP(address resolution protocol)地址解析协议 2、SNMP(simple network management P)网络管理协议,是TCP/IP的一部分 3、AppleShare protocol(AppleShare 协议) 4、AppleTalk 协议 5?、BOOTP协议(Bootstrap?Protocol)?应用一个基于TCP/IP协议的协议,该协议主要用于有无盘工作站的局域网 6、CMIP(Common Management Information Protocol)通用管理信息协议,它是建立在开放系统互连通信模式上的网络管理协议。相关的通用管理信息服务(CMIS)定义了访问和控制网络对象,设备和从对象设备接收状态信息的方法。 7、 DHCP协议、Dynamic?Host?Configuration?Protocol(动态主机配置协议),应用:在Windows中要启用DHCP协议,只要将IP地址设置为“自动获得IP地址”即可 9、Connection-oriented Protocol/Connectionless Protocol面向连接的协议/无连接协议 10 、Discard Protocol抛弃协议它的作用就是接收到什么抛弃什么,它对调试网络状态

系统串口通讯协议

ZHET 系统串口通讯协议 通 讯 技 术 手 册 型号:SYRDS1-485 (SYRDSSS1) SYRDL1-485 (SYRLSSS1) 玺瑞国际企业有限公司 SYRIS International Corp.

通讯技术手册 通讯协议(Protocol) 卡片阅读机模块(Reader Module)的通讯协议(Protocol)皆出自于SYRIS 的一种标准通讯协议,这种协议格式如下表: 1.SOH 和 END 都是一个字节的控制字符: SOH 控制器端定义为 <0x09> 模块端定义为 <0x0A> END 控制器及模块端均固定为 <0x0D> 其中 <0x> 为十六进制表示法. 2.TYPE 为模块型式编号,固定为一个字节,本型式编号固定为“A”. 3.ID为模块端的识别代码,这一字节的 ASCII 字符必须是在 1 <0x31> 到 8 <0x38> 的范围内,假如控制器端传送之ID值与模块地址编号相同时, 则该模块将会接收控制器端所传送的数据,而模块响应时,也会传回相同的地址编号.

4.FC是通讯功能码(Function Code)和资料(DATA)有相关性,固定为一个 字节,这些资料请参考通讯协议表及相关说明. 5.错误讯息判断代码(Error Code)为两个字节,第一个字节为固定为 <0x0E> ,第二个字节为错误代码,请参考错误讯息代码表. 6.8 BITS BCC是所有字符的检查字段,为二个字节,有关 8 BITS BCC 的 信息和范例程序,请参考附录A. 7.RS485传输协议请设定为”E,8,1”,速率为”19200”. 错误讯息代码表(Error Code Table) ※ Error Code #1固定为 <0x0E>.

通讯方式和通讯协议介绍

目录 一、RS232的串口通讯 (2) 应用 (2) 工作方式 (2) 接口标准 (2) 电路组成 (3) 概述 (3) 简介 (3) 二、RS485串行通讯 (3) 简介 (3) 接口 (4) 电缆 (4) 布网 (5) 区别 (5) 三、串行通信 (6) 概念 (6) 分类 (7) 同步通信 (7) 异步通信 (7) 特点 (7) 形式和标准 (7) 调幅方式 (7) 调频方式 (8) 数字编码方式 (8) 数据传输率 (8) 发送时钟和接收时钟 (9) 异步通信协议 (9) 通信协议 (10) 普遍协议 (10) USB (11) IEEE 1394 (11) 相关应用 (12) 四、通讯协议 (12) 简介 (12) 详细介绍 (13) TCP/IP (13) IPX/SPX (13) NetBEUI (14) 通信协议 (14) RS-232-C (14) RS-449 (14) V.35 (15) X.21 (15) HDLC (15) 管理协议 (15) SNMP (15) PPP (16)

一、RS232的串口通讯 应用 随着计算机系统的应用和微机网络的发展,通信功能越来越显得重要.这里所说的通信是指计算机与外界的信息交换.因此,通信既包括计算机与外部设备之间,也包括计算机和计算机之间的信息交换.由于串行通信是在一根传输线上一位一位的传送信息,所用的传输线少,并且可以借助现成的电话网进行信息传送,因此,特别适合于远距离传输.对于那些与计算机相距不远的人-机交换设备和串行存储的外部设备如终端、打印机、逻辑分析仪、磁盘等,采用串行方式交换数据也很普遍.在实时控制和管理方面,采用多台微机处理机组成分级分布控制系统中,各CPU 之间的通信一般都是串行方式.所以串行接口是微机应用系统常用的接口。许多外设和计算机按串行方式进行通信,这里所说的串行方式,是指外设与接口电路之间的信息传送方式,实际上,CPU 与接口之间仍按并行方式工作. 工作方式 由于CPU 与接口之间按并行方式传输,接口与外设之间按串行方式传输,因此,在串行接口中,必须要有" 接收移位寄存器" (串→并)和" 发送移位寄存器" (并→串). 在数据输入过程中,数据1 位1 位地从外设进入接口的" 接收移位寄存器",当" 接收移位寄存器" 中已接收完1 个字符的各位后,数据就从" 接收移位寄存器" 进入" 数据输入寄存器" . CPU 从" 数据输入寄存器" 中读取接收到的字符.(并行读取,即D7~D0 同时被读至累加器中). " 接收移位寄存器" 的移位速度由" 接收时钟" 确定. 在数据输出过程中,CPU 把要输出的字符(并行地)送入" 数据输出寄存器"," 数据输出寄存器" 的内容传输到" 发送移位寄存器",然后由" 发送移位寄存器" 移位,把数据1 位 1 位地送到外设. " 发送移位寄存器" 的移位速度由" 发送时钟" 确定. 接口中的" 控制寄存器" 用来容纳CPU 送给此接口的各种控制信息,这些控制信息决定接口的工作方式. " 状态寄存器" 的各位称为" 状态位",每一个状态位都可以用来指示数据传输过程中的状态或某种错误.例如,用状态寄存器的D5 位为"1" 表示" 数据输出寄存器" 空,用D0 位表示" 数据输入寄存器满",用D2 位表示" 奇偶检验错" 等. 能够完成上述" 串<- -> 并" 转换功能的电路,通常称为" 通用异步收发器" (UART :Universal Asynchronous Receiver and Transmitter),典型的芯片有:Intel 8250/8251,16550 接口标准 ⑴实现数据格式化:因为来自CPU的是普通的并行数据,所以,接口电路应具有实现不同串行通信方式下的数据格式化的任务。在异步通信方式下,接口自动生成起止式的帧数据格式。在面向字符的同步方式下,接口要在待传送的数据块前加上同步字符。

通讯协议标准

编号: 密级:内部 页数:__________基于RS485接口的DGL通信协议(修改) 编写:____________________ 校对:____________________ 审核:____________________ 批准:____________________ 北京华美特科贸有限公司 二○○二年十二月六日

1.前言 在常见的数字式磁致伸缩液位计中,多采用RS485通信方式。但RS485标准仅对物理层接口进行了明确定义,并没有制定通信协议标准。因此,在RS485的基础上,派生出很多不同的协议,不同公司均可根据自身需要设计符合实际情况的通信协议。并且,RS485允许单总线多机通信,如果通信协议设计不好,就会造成相互干扰和总线闭锁等现象。如果在一条总线上挂接不同类型的产品,由于协议不一样,很容易造成误触发,造成总线阻塞,使得不同产品对总线的兼容性很差。 随着RS485的发展,Modicon公司提出的MODBUS协议逐步得到广泛认可,已在工业领域得到广泛应用。而MODBUS的协议规范比较烦琐,并且每字节数据仅用低4位(范围:0~15),在信息量相同时,对总线占用时间较长。 DGL协议是根据以上问题提出的一种通信协议。在制定该协议时已充分考虑以下几点要求: a.兼容于MODBUS 。也就是说,符合该协议的从机均可挂接到同一总线上。 b.要适应大数据量的通信。如:满足产品在线程序更新的需要(未来功能)。 c.数据传输需稳定可靠。对不确定因素应加入必要的冗错措施。 d.降低总线的占用率,保证数据传输的通畅。 2.协议描述 为了兼容其它协议,现做以下定义: 通信数据均用1字节的16进制数表示。从机的地址范围为:0x80~0xFD,即:MSB=1; 命令和数据的数值范围均应控制在0~0x7F之间。即:MSB=0,以区别地址和其它数据。 液位计的编码地址为:0x82~0x9F。其初始地址(出厂默认值)为:0x81。 罐旁表的编织地址为:0xA2~0xBF。其初始地址(出厂默认值)为:0xA1。 其它地址用于连接其它类型的设备,也可用于液位计、罐区表地址不够时的扩充。 液位计的命令范围为:0x01~0x2F,共47条,将分别用于参数设定、实时测量、诊断测试、在线编程等。 通信的基本参数为:4800波特率,1个起始位,1个结束位。字节校验为奇校验。 本协议的数据包是参照MODBUS RTU 通信格式编写,并对其进行了部分修改,以提高数据传输的速度。另外,还部分参照了HART协议。其具体格式如下: 表中,数据的最大字节数为16个。也就是说,整个数据包最长为20个字节。 “校验和”是其前面所有数据异或得到的数值,然后将该数值MSB位清零,使其满足0~7F 的要求。在验证接收数据包的“校验和”是否正确时,可将所有接收数据(包括“校验和”)进行异或操作,得到的数据应=0x80。这是因为,只有“地址”的MSB=1,所以异或结果的MSB也必然等于1。 本协议不支持MODBUS中所规定的广播模式。 3.时序安排 在上电后,液位计将先延迟10秒,等待电源稳定。然后,用5秒的时间进行自检和测试数据。

串口通讯协议

串口通讯协议 波特率9600,数据位8位,起始位1位,停止位2位,校验采用16位CRC校验,校验包括头部信息和数据。 帧定义: 主机发送事件数据定义

u16 const crc_table[256] = { 0x0000U, 0x1021U, 0x2042U, 0x3063U, 0x4084U, 0x50a5U, 0x60c6U, 0x70e7U, 0x8108U, 0x9129U, 0xa14aU, 0xb16bU, 0xc18cU, 0xd1adU, 0xe1ceU, 0xf1efU, 0x1231U, 0x0210U, 0x3273U, 0x2252U, 0x52b5U, 0x4294U, 0x72f7U, 0x62d6U, 0x9339U, 0x8318U, 0xb37bU, 0xa35aU, 0xd3bdU, 0xc39cU, 0xf3ffU, 0xe3deU, 0x2462U, 0x3443U, 0x0420U, 0x1401U, 0x64e6U, 0x74c7U, 0x44a4U, 0x5485U, 0xa56aU, 0xb54bU, 0x8528U, 0x9509U, 0xe5eeU, 0xf5cfU, 0xc5acU, 0xd58dU, 0x3653U, 0x2672U, 0x1611U, 0x0630U, 0x76d7U, 0x66f6U, 0x5695U, 0x46b4U, 0xb75bU, 0xa77aU, 0x9719U, 0x8738U, 0xf7dfU, 0xe7feU, 0xd79dU, 0xc7bcU, 0x48c4U, 0x58e5U, 0x6886U, 0x78a7U, 0x0840U, 0x1861U, 0x2802U, 0x3823U, 0xc9ccU, 0xd9edU, 0xe98eU, 0xf9afU, 0x8948U, 0x9969U, 0xa90aU, 0xb92bU, 0x5af5U, 0x4ad4U, 0x7ab7U, 0x6a96U, 0x1a71U, 0x0a50U, 0x3a33U, 0x2a12U, 0xdbfdU, 0xcbdcU, 0xfbbfU, 0xeb9eU, 0x9b79U, 0x8b58U, 0xbb3bU, 0xab1aU, 0x6ca6U, 0x7c87U, 0x4ce4U, 0x5cc5U, 0x2c22U, 0x3c03U, 0x0c60U, 0x1c41U, 0xedaeU, 0xfd8fU, 0xcdecU, 0xddcdU, 0xad2aU, 0xbd0bU, 0x8d68U, 0x9d49U, 0x7e97U, 0x6eb6U, 0x5ed5U, 0x4ef4U, 0x3e13U, 0x2e32U, 0x1e51U, 0x0e70U, 0xff9fU, 0xefbeU, 0xdfddU, 0xcffcU, 0xbf1bU, 0xaf3aU, 0x9f59U, 0x8f78U, 0x9188U, 0x81a9U, 0xb1caU, 0xa1ebU, 0xd10cU, 0xc12dU, 0xf14eU, 0xe16fU, 0x1080U, 0x00a1U, 0x30c2U, 0x20e3U, 0x5004U, 0x4025U, 0x7046U, 0x6067U, 0x83b9U, 0x9398U, 0xa3fbU, 0xb3daU, 0xc33dU, 0xd31cU, 0xe37fU, 0xf35eU, 0x02b1U, 0x1290U, 0x22f3U, 0x32d2U, 0x4235U, 0x5214U, 0x6277U, 0x7256U, 0xb5eaU, 0xa5cbU, 0x95a8U, 0x8589U, 0xf56eU, 0xe54fU, 0xd52cU, 0xc50dU, 0x34e2U, 0x24c3U, 0x14a0U, 0x0481U, 0x7466U, 0x6447U, 0x5424U, 0x4405U, 0xa7dbU, 0xb7faU, 0x8799U, 0x97b8U, 0xe75fU, 0xf77eU, 0xc71dU, 0xd73cU, 0x26d3U, 0x36f2U, 0x0691U, 0x16b0U, 0x6657U, 0x7676U, 0x4615U, 0x5634U, 0xd94cU, 0xc96dU, 0xf90eU, 0xe92fU, 0x99c8U, 0x89e9U, 0xb98aU, 0xa9abU, 0x5844U, 0x4865U, 0x7806U, 0x6827U, 0x18c0U, 0x08e1U, 0x3882U, 0x28a3U, 0xcb7dU, 0xdb5cU, 0xeb3fU, 0xfb1eU, 0x8bf9U, 0x9bd8U, 0xabbbU, 0xbb9aU, 0x4a75U, 0x5a54U, 0x6a37U, 0x7a16U, 0x0af1U, 0x1ad0U, 0x2ab3U, 0x3a92U, 0xfd2eU, 0xed0fU, 0xdd6cU, 0xcd4dU, 0xbdaaU, 0xad8bU, 0x9de8U, 0x8dc9U, 0x7c26U, 0x6c07U, 0x5c64U, 0x4c45U, 0x3ca2U, 0x2c83U, 0x1ce0U, 0x0cc1U, 0xef1fU, 0xff3eU, 0xcf5dU, 0xdf7cU, 0xaf9bU, 0xbfbaU, 0x8fd9U, 0x9ff8U, 0x6e17U, 0x7e36U, 0x4e55U, 0x5e74U, 0x2e93U, 0x3eb2U, 0x0ed1U, 0x1ef0U }; u16 crc16(u16 crc,const u8 *data, u32 len )len可以为u8,u16,u32 { while (len--) crc = crc_table[(crc >> 8 ^ *(data++)) & 0xffU] ^ (crc << 8); return crc; } 例:u8 *buf=”123456789”;

相关文档
最新文档