CN105955905B - A kind of interface circuit and communication protocol based on serial bus structure - Google Patents
A kind of interface circuit and communication protocol based on serial bus structure Download PDFInfo
- Publication number
- CN105955905B CN105955905B CN201610247642.0A CN201610247642A CN105955905B CN 105955905 B CN105955905 B CN 105955905B CN 201610247642 A CN201610247642 A CN 201610247642A CN 105955905 B CN105955905 B CN 105955905B
- Authority
- CN
- China
- Prior art keywords
- bus
- signal line
- data
- node
- circuit
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Expired - Fee Related
Links
Classifications
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F13/00—Interconnection of, or transfer of information or other signals between, memories, input/output devices or central processing units
- G06F13/38—Information transfer, e.g. on bus
- G06F13/40—Bus structure
- G06F13/4004—Coupling between buses
- G06F13/4022—Coupling between buses using switching circuits, e.g. switching matrix, connection or expansion network
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F13/00—Interconnection of, or transfer of information or other signals between, memories, input/output devices or central processing units
- G06F13/38—Information transfer, e.g. on bus
- G06F13/42—Bus transfer protocol, e.g. handshake; Synchronisation
- G06F13/4282—Bus transfer protocol, e.g. handshake; Synchronisation on a serial bus, e.g. I2C bus, SPI bus
Landscapes
- Engineering & Computer Science (AREA)
- Theoretical Computer Science (AREA)
- Physics & Mathematics (AREA)
- General Engineering & Computer Science (AREA)
- General Physics & Mathematics (AREA)
- Mathematical Physics (AREA)
- Computer Hardware Design (AREA)
- Small-Scale Networks (AREA)
Abstract
本发明公开了一种基于串行总线结构的总线接口电路及其总线通信协议,总线接口电路利用发送数据线、发送控制线和竞争控制线的逻辑组合,实现对总线电平的强上拉、弱上拉和强下拉驱动输出,结合对总线逻辑电平的回读功能,支持总线节点以非破坏性仲裁和自动退避的方式竞争总线控制权的总线通信协议。节点通过对总线状态的监听,判断总线空闲,通过对总线电平的“预置”和基于节点地址位的“赋值”,使参与竞争的节点在总线控制权竞争过程中,具有最小地址值的节点向总线发送的信息不会遭到破坏,直至其应用数据发送完毕,总线控制权才会重新被节点竞争,从而实现基于串行总线结构的节点多主通信,保证总线通信的实时性和可靠性。
The invention discloses a bus interface circuit based on a serial bus structure and its bus communication protocol. The bus interface circuit realizes strong pull-up, Weak pull-up and strong pull-down drive output, combined with the readback function of the logic level of the bus, support the bus communication protocol in which bus nodes compete for bus control in the way of non-destructive arbitration and automatic backoff. The nodes judge the bus idleness by monitoring the bus state, and through the "presetting" of the bus level and the "assignment" based on the node address bits, the nodes participating in the competition can have the minimum address value during the competition process of the bus control right. The information sent by the node to the bus will not be destroyed, until the application data is sent, the bus control right will be re-competed by the node, so as to realize the multi-master communication of the node based on the serial bus structure, and ensure the real-time and reliability of the bus communication sex.
Description
技术领域technical field
本发明涉及一种基于串行总线结构的总线接口电路及其非破坏性总线通信协议,属于信息网络通信技术领域。The invention relates to a bus interface circuit based on a serial bus structure and its non-destructive bus communication protocol, belonging to the technical field of information network communication.
背景技术Background technique
电子信息、通信与计算机技术的发展,使整个社会发生了巨大的变化;同时由于工业技术的扩大和发展,电子信息、通信与计算机技术在工厂、楼宇和农业领域中的应用也越来越广泛和深入。其中智能化仪器仪表、控制器、执行机构等设备的之间的数字通信以及与上层控制系统之间的通信是首要的问题,现场总线就是解决这一问题的核心技术。The development of electronic information, communication and computer technology has brought great changes to the whole society; at the same time, due to the expansion and development of industrial technology, the application of electronic information, communication and computer technology in factories, buildings and agricultural fields is becoming more and more extensive. and in-depth. Among them, the digital communication between intelligent instruments, controllers, executive agencies and other equipment and the communication with the upper control system are the primary problems, and the field bus is the core technology to solve this problem.
现场总线为各种仪器设备提供基础的信息传输与组网通信支持,是实现物联网中各节点功能部件协调高效工作的重要保障。目前,国外已经有一些非常成功的现场总线技术,如EIB、LonWorks等,它们被广泛应用于家庭和大型楼宇电气监控系统中,但由于节点对总线的驱动能力小,如果不使用中继器,单总线可挂载的节点数一般不超过100个,如果需要组成大网络,则需要多条总线。工业上常用的485、CAN总线等,单总线节点数量一般略多于100个,在监控点过多时依然要使用多条总线构成网络。Fieldbus provides basic information transmission and networking communication support for various instruments and equipment, and is an important guarantee for the coordinated and efficient work of functional components of each node in the Internet of Things. At present, there are already some very successful fieldbus technologies abroad, such as EIB, LonWorks, etc., which are widely used in household and large-scale building electrical monitoring systems, but due to the small driving ability of nodes to the bus, if repeaters are not used, The number of nodes that can be mounted on a single bus generally does not exceed 100. If a large network needs to be formed, multiple buses are required. For 485 and CAN buses commonly used in industry, the number of single-bus nodes is generally slightly more than 100. When there are too many monitoring points, it is still necessary to use multiple buses to form a network.
使用“推挽”式输出结构作为总线驱动电路可以有效提高总线节点对总线的驱动能力,增加总线可挂载的节点数量。这种方式带来的问题是,若同一时刻一条总线上有多个总线节点传输数据,在高低电平之间出现低阻通路的可能性很高,这种情况会导致总线上逻辑错误甚至短路烧毁。解决这一问题的常用的方法是在总线节点处使用“推挽”式输出结构的三态门接入总线,通过微控制器轮询的方式控制总线节点传输数据,这种方法可以确保总线上每个时刻只有一个三态门处于工作状态,而其他的三态门均为高阻态,但是当总线节点数量很大时,使用轮询方式的通信过程就变得很慢,不符合现场总线对实时性的要求,并且这种方法需要额外的控制总线以控制三态门的工作状态与高阻态。Using the "push-pull" output structure as the bus drive circuit can effectively improve the drive capability of the bus nodes to the bus and increase the number of nodes that the bus can mount. The problem brought about by this method is that if there are multiple bus nodes transmitting data on one bus at the same time, there is a high possibility of a low-impedance path between high and low levels, which will lead to logic errors or even short circuits on the bus. burn. A common method to solve this problem is to use a tri-state gate with a "push-pull" output structure to access the bus at the bus node, and control the bus node to transmit data through the polling method of the microcontroller. This method can ensure Only one tri-state gate is in the working state at each moment, while the other tri-state gates are in high-impedance state, but when the number of bus nodes is large, the communication process using the polling method becomes very slow, which does not conform to the field bus Real-time requirements, and this method requires an additional control bus to control the working state and high-impedance state of the tri-state gate.
发明内容Contents of the invention
本发明是为避免上述现有技术所存在的不足之处,提供一种基于串行总线结构的总线接口电路及其总线通信协议,以期能实现基于串行总线结构的节点多主通信,使总线节点采用竞争的方式获取总线控制权,从而能有效提高串行总线的负载能力、保证总线通信的实时性和可靠性。The present invention provides a bus interface circuit based on a serial bus structure and its bus communication protocol in order to avoid the shortcomings of the above-mentioned prior art, in order to realize node multi-master communication based on a serial bus structure, so that the bus The nodes obtain the control right of the bus by means of competition, which can effectively improve the load capacity of the serial bus and ensure the real-time and reliability of the bus communication.
本发明为解决技术问题采用如下技术方案:The present invention adopts following technical scheme for solving technical problems:
本发明一种基于串行总线结构的总线接口电路,所述串行总线结构是在总线上并联设置有n个节点,记为G={G1,G2,...,Gi,...,Gn};Gi表示第i个节点;所述第i个节点Gi包括:第i个微控制器和第i个总线接口电路;所述第i个微控制器和第i个总线接口电路之间通过第i组信号线相连;所述第i个总线接口电路通过第i个数据线Datai与所述总线相连;1≤i≤n;其特点是:The present invention is a bus interface circuit based on a serial bus structure. The serial bus structure is provided with n nodes connected in parallel on the bus, which is denoted as G={G 1 ,G 2 ,...,G i ,. .., G n }; G i represents the i-th node; the i-th node G i includes: the i-th microcontroller and the i-th bus interface circuit; the i-th microcontroller and the i-th The bus interface circuits are connected through the i-th group of signal lines; the i-th bus interface circuit is connected with the bus through the i-th data line Data i ; 1≤i≤n; its characteristics are:
所述第i组信号线包括:第i个发送信号线TXi、第i个接收信号线RXi、第i个发送控制信号线HIi和第i个竞争控制信号线CIi;The i-th group of signal lines includes: the i-th transmission signal line TX i , the i-th reception signal line RX i , the i-th transmission control signal line HI i and the i-th competition control signal line CI i ;
所述第i个总线接口电路接入有第i个正电源、第i个负电源和地线;The i-th bus interface circuit is connected with the i-th positive power supply, the i-th negative power supply and the ground wire;
所述第i个总线接口电路包括:第i个上拉电路、第i个下拉电路、第i个回读电路、第i个数据发送控制电路和第i个竞争控制电路;The i-th bus interface circuit includes: the i-th pull-up circuit, the i-th pull-down circuit, the i-th readback circuit, the i-th data transmission control circuit and the i-th competition control circuit;
所述第i个下拉电路与所述第i个正电源相连,并通过第i个一号二极管Di,1接入所述第i个数据线Datai;The i-th pull-down circuit is connected to the i-th positive power supply, and connected to the i-th data line Data i through the i-th number one diode D i,1 ;
所述第i个下拉电路与所述第i个数据发送控制电路相连;The i-th pull-down circuit is connected to the i-th data transmission control circuit;
所述第i个回读电路通过第i个八号电阻Ri,8和所述第i个数据线Datai相连;The i-th readback circuit is connected to the i-th data line Data i through the i-th No. 8 resistor R i,8 ;
所述第i个回读电路通过第i个接收信号线RXi与所述第i个微控制器相连;The i-th readback circuit is connected to the i-th microcontroller through the i-th receiving signal line RX i ;
所述第i个数据发送控制电路与所述地线相连,并通过第i个三号二极管Di,3接入所述第i个回读电路与所述第i个八号电阻Ri,8之间;The i-th data transmission control circuit is connected to the ground wire, and connected to the i-th readback circuit and the i-th number eight resistor R i, 3 through the i-th number three diode D i,3 between 8 ;
所述第i个数据发送控制电路分别通过第i个发送信号线TXi和第i个发送控制信号线HIi与所述第i个微控制器相连;The i-th data transmission control circuit is connected to the i-th microcontroller through the i-th transmission signal line TX i and the i-th transmission control signal line HI i respectively;
所述第i个上拉电路与所述第i个负电源相连,并通过第i个二号二极管Di,2接入所述第i个数据线Datai;The i-th pull-up circuit is connected to the i-th negative power supply, and connected to the i-th data line Data i through the i-th No. 2 diode D i,2 ;
所述第i个上拉电路外部接入有第i个五号电阻Ri,5;所述第i个五号电阻Ri,5的一端接入所述第i个二号二极管Di,2的负极,另一端接入第i个负电源;The i-th pull-up circuit is externally connected with the i-th No. 5 resistor R i,5 ; one end of the i-th No. 5 resistor R i,5 is connected to the i-th No. 2 diode D i, 2 , the other end is connected to the i-th negative power supply;
所述第i个上拉电路与所述第i个竞争控制电路相连;The i-th pull-up circuit is connected to the i-th competition control circuit;
所述第i个竞争控制电路通过第i个四号二极管Di,4接入所述第i个回读电路与所述第i个八号电阻Ri,8之间;The i-th competition control circuit is connected between the i-th readback circuit and the i-th No. 8 resistor R i,8 through the i-th No. 4 diode D i,4 ;
所述第i个竞争控制电路通过所述第i个竞争控制信号线CIi、第i个发送信号线TXi和第i个发送控制信号线HIi与所述第i个微控制器相连。The i-th contention control circuit is connected to the i-th microcontroller through the i-th contention control signal line CI i , the i-th transmission signal line TX i and the i-th transmission control signal line HI i .
本发明所述的基于串行总线结构的总线接口电路的特点也在于:所述第i个竞争控制电路包括:第i个与非门Ui、第i个十二号电阻Ri,12和第i个五号PNP三极管Qi,5;The characteristics of the bus interface circuit based on the serial bus structure in the present invention are also that: the i-th competition control circuit includes: the i-th NAND gate U i , the i-th No. 12 resistor R i,12 and The i-th No. 5 PNP transistor Q i,5 ;
所述第i个五号PNP三极管Qi,5的发射极接入第i个正电源、集电极分别与第i个四号二极管Di,4的正极和所述第i个上拉电路相连、基极与所述第i个十二号电阻Ri,12的一端相连;所述第i个十二号电阻Ri,12的另一端与第i个与非门Ui的输出端相连;所述第i个与非门Ui的输入端分别与所述第i个竞争控制信号线CIi、第i个发送信号线TXi和第i个发送控制信号线HIi相连。The emitter of the i-th No. 5 PNP transistor Q i, 5 is connected to the i-th positive power supply, and the collector is respectively connected to the anode of the i-th No. 4 diode D i, 4 and the i-th pull-up circuit , the base is connected to one end of the i-th No. 12 resistor R i , 12 ; the other end of the i-th No. 12 resistor R i, 12 is connected to the output end of the i-th NAND gate U i ; The input terminals of the i-th NAND gate U i are respectively connected to the i-th contention control signal line CI i , the i-th transmission signal line TX i and the i-th transmission control signal line HI i .
本发明一种基于总线接口电路的总线通信协议的特点是应用于由n个节点并联设置在总线上所组成的串行总线结构中,第i个节点包括:第i个微控制器和第i个总线接口电路;所述第i个微控制器和第i个总线接口电路之间通过第i组信号线相连;所述第i组信号线包括:第i个发送信号线TXi、第i个接收信号线RXi、第i个发送控制信号线HIi和第i个竞争控制信号线CIi;所述第i个总线接口电路通过第i个数据线Datai与所述总线相连;1≤i≤n;A kind of bus communication protocol based on the bus interface circuit of the present invention is characterized in that it is applied in a serial bus structure composed of n nodes connected in parallel on the bus, and the i-th node includes: the i-th microcontroller and the i-th a bus interface circuit; the i-th microcontroller and the i-th bus interface circuit are connected through the i-th group of signal lines; the i-th group of signal lines includes: the i-th sending signal line TX i , the i-th signal line The first receiving signal line RX i , the i-th sending control signal line HI i and the i-th competition control signal line CI i ; the i-th bus interface circuit is connected to the bus through the i-th data line Data i ; 1 ≤i≤n;
所述总线通信协议是按如下步骤进行:Described bus communication protocol is to carry out as follows:
步骤1、定义变量j和k;假设以所述第i个节点作为发送节点并向所述总线发送一帧二进制数据数据,定义所述一帧二进制数据的位数为M=m+z+l;m≥2且为偶数,m表示所述一帧二进制数据中数据位的个数;z=1表示所述一帧二进制数据中起始位的个数为1;l=1表示所述一帧二进制数据中停止位的个数为1;Step 1, define variables j and k; Assume that the i-th node is used as the sending node and send a frame of binary data data to the bus, define the number of bits of the frame of binary data as M=m+z+l ; m≥2 and is an even number, m represents the number of data bits in the one frame of binary data; z=1 represents that the number of start bits in the one frame of binary data is 1; l=1 represents the one The number of stop bits in the frame binary data is 1;
则将第i个节点的地址IDi中的m个地址位中的高位封装为第1帧二进制数据、低位封装为第2帧二进制数据;Then set the high value of the m address bits in the address ID i of the i-th node Bit packed as Frame 1 binary data, low Bit packed as frame 2 binary data;
所述第1帧二进制数据和第2帧二进制数据中的数据位分别是在每个地址位之前的高位上插入二进制码“1”构成;即,The data bits in the binary data of the first frame and the binary data of the second frame are formed by inserting a binary code "1" into the high bit before each address bit; that is,
所述第1帧二进制数据的数据位:1,IDm-1,1,IDm-2,1,...,1,IDm/2;Data bits of the first frame of binary data: 1, ID m-1 , 1, ID m-2 , 1, ..., 1, ID m/2 ;
所述第2帧二进制数据的数据位:1,IDm/2-1,1,IDm/2-2,1,...,1,ID0;The data bits of the binary data of the second frame: 1, ID m/2-1 , 1, ID m/2-2 , 1, ..., 1, ID 0 ;
步骤2、所述第i个节点中的微控制器将所述第i个发送控制信号线HIi置为低电平,表示所述第i个总线接口电路处于“弱上拉”输出;Step 2. The microcontroller in the i-th node sets the i-th transmission control signal line HI i to a low level, indicating that the i-th bus interface circuit is in a "weak pull-up"output;
步骤3、初始化j=1;Step 3, initialize j=1;
步骤4、所述第i个节点中的微控制器在第j个监听周期Tj下,通过第i个接收信号线RXi采集所述总线的逻辑值Fj并进行判断,Step 4, the microcontroller in the i-th node collects the logic value F j of the bus through the i-th receiving signal line RX i under the j-th monitoring period T j and makes a judgment,
当Fj=1时,将j+1赋值给j,并判断j>M是否成立,若成立,则表示所述总线处于“空闲”状态,并执行步骤5,否则重复步骤4执行;When F j =1, assign j+1 to j, and judge whether j>M is true, if true, it means that the bus is in the "idle" state, and execute step 5, otherwise repeat step 4;
当Fj=0时,则表示所述总线处于“占用”状态;并返回步骤3执行;When F j =0, it means that the bus is in the "occupied"state; and return to step 3 for execution;
步骤5、初始化k=1;Step 5, initializing k=1;
步骤6、初始化j=0;在第j个发送周期Tj的起始时刻,所述第i个节点中的微控制器将所述第i个发送控制信号线HIi置为高电平、并将第i个竞争控制信号线CIi和第i个发送信号线TXi置为低电平后,等待第j个发送周期Tj的结束时刻;从而完成所述第k帧二进制数据中的起始位的发送,并令j=1;Step 6, initializing j=0; at the start moment of the j-th sending cycle T j , the microcontroller in the i-th node sets the i-th sending control signal line HI i to a high level, After setting the i-th contention control signal line CI i and the i-th transmission signal line TX i to a low level, wait for the end moment of the j-th transmission cycle T j ; thereby completing the k-th frame of binary data The transmission of the start bit, and let j=1;
步骤7、在第j个发送周期Tj的起始时刻,所述第i个节点中的微控制器分别将所述第i个发送控制信号线HIi、第i个竞争控制信号线CIi和第i个发送信号线TXi置为高电平,从而使得所述第i个总线接口电路处于“强上拉”输出;并在第j个发送周期Tj的中间时刻,将第i个竞争控制信号线CIi置为低电平,从而使得所述第i个总线接口电路处于“弱上拉”输出,完成总线电平状态的预置;Step 7. At the starting moment of the j-th sending cycle T j , the microcontroller in the i-th node connects the i-th sending control signal line HI i and the i-th competition control signal line CI i respectively and the i-th transmission signal line TX i is set to a high level, so that the i-th bus interface circuit is in a "strong pull-up"output; and at the middle moment of the j-th transmission cycle T j , the i-th The competition control signal line CI i is set to a low level, so that the i-th bus interface circuit is in the "weak pull-up" output, and the preset of the bus level state is completed;
步骤8、在第j+1个发送周期Tj+1的起始时刻,所述第i个节点中的微控制器将所述第k帧二进制数据的数据位中的第m-j-1位的数据通过所述第i个发送信号线TXi发送到所述总线上;若所述第i个发送信号线TXi为高电平,则表示所述第i个总线接口电路维持“弱上拉”输出;若所述第i个发送信号线TXi为低电平,则表示所述第i个总线接口电路处于“强下拉”输出;Step 8. At the start moment of the j+1th transmission cycle T j+1 , the microcontroller in the i-th node sends the mj-1th bit of the k-th frame of binary data to Data is sent to the bus through the i-th transmission signal line TX i ; if the i-th transmission signal line TX i is at a high level, it means that the i-th bus interface circuit maintains a "weak pull-up""output; if the i-th transmission signal line TX i is low level, it means that the i-th bus interface circuit is in the "strong pull-down"output;
并在第j+1个发送周期Tj+1的中间时刻,所述第i个节点中的微控制器通过第i个接收信号线RXi读取所述总线的逻辑值Fj+1并进行判断,And at the middle moment of the j+1th sending cycle T j+1 , the microcontroller in the i-th node reads the logic value F j+1 of the bus through the i-th receiving signal line RX i and judge,
当总线的逻辑值Fj+1与第k帧二进制数据的数据位中的第m-j-1位的数据相同时,等待第j+1个发送周期Tj+1的结束时刻,再将j+2赋值给j,并判断j>m-1是否成立;若成立,则在第j个发送周期Tj的起始时刻,所述第i个节点中的微控制器分别将所述第i个发送控制信号线HIi、第i个竞争控制信号线CIi和第i个发送信号线TXi置为高电平后,等待第j个发送周期Tj的结束时刻;从而完成所述第k帧二进制数据中的停止位的发送,再执行步骤9;否则,返回步骤7执行;When the logic value F j+1 of the bus is the same as the data of the mj-1th bit in the data bits of the kth frame binary data, wait for the end of the j+1th sending cycle T j+1 , and then set j+ 2 Assign a value to j, and judge whether j>m-1 is true; if true, at the beginning of the jth sending cycle T j , the micro-controller in the i-th node sends the i-th After sending the control signal line HI i , the i-th contention control signal line CI i and the i-th sending signal line TX i at high level, wait for the end moment of the j-th sending cycle T j ; thus completing the k-th Send the stop bit in the frame binary data, and then execute step 9; otherwise, return to step 7 for execution;
当总线的逻辑值Fj+1与第k帧二进制数据的数据位中的第m-j-1位的数据不相同时,则表示存在高于所述第i个节点优先级的其他节点,所述第i个节点中的微控制器将所述第i个发送控制信号线HIi置为低电平,表示所述第i个总线接口电路处于“弱上拉”输出;并返回步骤3执行;When the logic value F j+1 of the bus is not the same as the data of the mj-1th bit in the data bits of the kth frame binary data, it means that there are other nodes higher than the i-th node priority, the said The microcontroller in the i-th node sets the i-th sending control signal line HI i to a low level, indicating that the i-th bus interface circuit is in a "weak pull-up"output; and returns to step 3 for execution;
步骤9、将k+1赋值给k,并判断k>2是否成立,若成立,则表示所述第i个节点中的微控制器获得向所述总线发送数据的控制权并通过第i个数据线Datai完成自身的数据发送;并返回步骤2执行;否则,返回步骤6执行。Step 9. Assign k+1 to k, and judge whether k>2 is true, if true, it means that the microcontroller in the i-th node obtains the control right to send data to the bus and passes the i-th node The data line Data i completes its own data transmission; and returns to step 2 for execution; otherwise, returns to step 6 for execution.
与已有技术相比,本发明有益效果体现在:Compared with the prior art, the beneficial effects of the present invention are reflected in:
1、本发明设计一种基于串行总线结构的总线接口电路,利用对发送数据线、发送控制信号线和竞争控制信号线的组合设置,实现了对总线电平的强上拉、弱上拉和强下拉驱动输出。其效果是:对总线电平的强上拉和强下拉驱动,构成对总线的“推挽”式输出功能,显著提高了接口电路对总线的输出驱动能力,增加了总线上可同时并联挂载节点的数量。同时,结合对总线电平的弱下拉和对总线逻辑电平的回读功能,所提出的总线接口电路为实现节点竞争总线控制权的非破坏性总线通信协议,提供了硬件支持。1. The present invention designs a bus interface circuit based on a serial bus structure, and realizes a strong pull-up and a weak pull-up of the bus level by using the combined setting of the sending data line, the sending control signal line and the competition control signal line and strong pull-down driver output. The effect is: the strong pull-up and pull-down drive of the bus level constitutes the "push-pull" output function of the bus, which significantly improves the output drive capability of the interface circuit to the bus, and increases the number of devices that can be mounted in parallel on the bus at the same time. the number of nodes. At the same time, combined with the weak pull-down of the bus level and the readback function of the bus logic level, the proposed bus interface circuit provides hardware support for the non-destructive bus communication protocol in which nodes compete for bus control.
2、本发明的总线接口电路主要由上拉电路、下拉电路、弱下拉电阻、发送控制电路、竞争控制电路和总线电平回读电路构成,并通过数据线和地线接入串行总线。当有数据需要向总线发送时,节点通过回读总线逻辑电平,对总线状态进行监听,如果连续出现高电平逻辑位的数量超过一帧数据的位数,则判断总线空闲,否则判断总线被占用。当总线空闲时,节点通过接口电路将自身的地址ID按照先高位后低位的次序发送出去。但在发送每一位地址之前,先利用接口电路的强上拉能力,向总线发送一位逻辑1,然后控制接口电路进入弱上拉状态,从而完成总线电平的“预置”,在接下来的一位时间里,判断要发送的地址位的逻辑值,如果为1,则保持接口的弱上拉输出;如果为0,则控制接口电路强下拉,向总线发送一位逻辑0,从而完成总线电平的“赋值”。其效果是:在“预置”阶段,总线电平被快速上拉至逻辑1,然后根据参与竞争节点的地址位,通过高电平保持或强下拉驱动,实现了总线电平的快速“赋值”,从而实现了强驱动“推挽”输出的“线与”功能。2. The bus interface circuit of the present invention is mainly composed of a pull-up circuit, a pull-down circuit, a weak pull-down resistor, a transmission control circuit, a competition control circuit and a bus level readback circuit, and is connected to the serial bus through a data line and a ground line. When there is data that needs to be sent to the bus, the node monitors the bus status by reading back the logic level of the bus. If the number of consecutive high-level logic bits exceeds the number of bits in a frame of data, the bus is judged to be idle, otherwise the bus is judged to be idle. Occupied. When the bus is free, the node sends out its own address ID through the interface circuit in the order of high bits first and then low bits. But before sending each bit address, use the strong pull-up capability of the interface circuit to send a bit of logic 1 to the bus, and then control the interface circuit to enter the weak pull-up state, thereby completing the "presetting" of the bus level. In the next bit time, judge the logical value of the address bit to be sent. If it is 1, the weak pull-up output of the interface will be maintained; if it is 0, the interface circuit will be pulled down strongly, and a logic 0 will be sent to the bus. Complete the "assignment" of the bus level. The effect is: in the "preset" stage, the bus level is quickly pulled up to logic 1, and then according to the address bits of the competing nodes, the bus level is quickly "assigned" through high-level hold or strong pull-down drive. ", thereby realizing the "wire-AND" function of the strong drive "push-pull" output.
3、本发明对接口电路输出的“线与”结果产生的总线逻辑电平,节点通过其总线接口的回读电路进行回读,判断回读结果与当前节点发送的地址位是否一致,如果一致则继续下一位的竞争,否则,节点暂时退出总线竞争而转入对总线状态的监听。其效果是:只要总线上各节点的地址ID具有唯一性,那么当某节点的地址位全部发送出去,则该节点就获得了总线的控制权,可以继续向总线发送应用数据。参与竞争的节点在总线控制权竞争和仲裁的整个过程中,具有最小地址ID值的节点向总线发送的信息不会遭到任何破坏,直至其应用数据发送完毕,总线控制权才会重新被竞争和仲裁,从而实现了基于串行总线结构的节点多主通信,有效提高了串行总线通信的实时性和可靠性。3. The present invention reads back the logic level of the bus generated by the "wire-AND" result output by the interface circuit, and the node reads back through the readback circuit of its bus interface, and judges whether the readback result is consistent with the address bits sent by the current node. If they are consistent Then continue to compete for the next bit, otherwise, the node temporarily withdraws from the bus competition and turns to monitor the bus state. The effect is: as long as the address ID of each node on the bus is unique, when all the address bits of a certain node are sent out, the node has obtained the control right of the bus and can continue to send application data to the bus. During the whole process of competition and arbitration for the nodes participating in the bus control right, the information sent by the node with the smallest address ID value to the bus will not be damaged in any way, and the bus control right will not be re-competed until its application data is sent. And arbitration, thus realizing the node multi-master communication based on the serial bus structure, effectively improving the real-time and reliability of the serial bus communication.
附图说明Description of drawings
图1为本发明中串行总线结构示意图;Fig. 1 is the structural representation of serial bus among the present invention;
图2为本发明中总线接口电路原理图;Fig. 2 is the schematic diagram of bus interface circuit in the present invention;
图3为本发明中总线通信接口数据信道编码脉冲示意图;Fig. 3 is a schematic diagram of bus communication interface data channel coding pulse in the present invention;
图4为本发明中节点发送数据及一帧二进制数据的构成图;Fig. 4 is a composition diagram of node sending data and a frame of binary data in the present invention;
图5为本发明中通信协议流程图;Fig. 5 is a communication protocol flow chart in the present invention;
图6为本发明中非破坏性总线仲裁实施实例图。FIG. 6 is a diagram of an implementation example of non-destructive bus arbitration in the present invention.
具体实施方式Detailed ways
本实施例中,总线接口电路利用发送数据线、发送控制线和竞争控制线的逻辑组合,实现对总线电平的强上拉、弱上拉和强下拉驱动输出,结合对总线逻辑电平的回读功能,支持总线节点以非破坏性仲裁和自动退避的方式竞争总线控制权的总线通信协议。节点通过对总线状态的监听,判断总线空闲,通过对总线电平的“预置”和基于节点地址位的“赋值”,使参与竞争的节点在总线控制权竞争过程中,具有最小地址值的节点向总线发送的信息不会遭到破坏,直至其应用数据发送完毕,总线控制权才会重新被节点竞争,从而实现了基于串行总线结构的节点多主通信,保证了总线通信的实时性和可靠性。In this embodiment, the bus interface circuit utilizes the logical combination of the sending data line, the sending control line and the contention control line to realize the strong pull-up, weak pull-up and strong pull-down drive output of the bus level, combined with the control of the bus logic level The readback function supports the bus communication protocol in which the bus nodes compete for the control right of the bus in the way of non-destructive arbitration and automatic backoff. The nodes judge the bus idleness by monitoring the bus state, and through the "presetting" of the bus level and the "assignment" based on the node address bits, the nodes participating in the competition can have the minimum address value during the competition process of the bus control right. The information sent by the node to the bus will not be destroyed, until the application data is sent, the bus control right will be re-competed by the node, thus realizing the node multi-master communication based on the serial bus structure and ensuring the real-time performance of the bus communication and reliability.
具体的说,一种基于串行总线结构的总线接口电路,其结构如图1所示。串行总线结构是在总线上并联设置有n个节点,记为G={G1,G2,...,Gi,...,Gn};Gi表示第i个节点;第i个节点Gi包括:第i个微控制器和第i个总线接口电路;第i个微控制器和第i个总线接口电路之间通过第i组信号线相连;第i个总线接口电路通过第i个数据线Datai与总线相连,第i个微控制器利用第i组信号线控制第i个总线接口电路,从而向总线发送数据或从总线接收数据;1≤i≤n;Specifically, a bus interface circuit based on a serial bus structure, the structure of which is shown in FIG. 1 . The serial bus structure is that n nodes are arranged in parallel on the bus, recorded as G={G 1 ,G 2 ,...,G i ,...,G n }; G i represents the i-th node; The i node G i includes: the i-th microcontroller and the i-th bus interface circuit; the i-th microcontroller and the i-th bus interface circuit are connected through the i-th group of signal lines; the i-th bus interface circuit The i-th data line Data i is connected to the bus, and the i-th microcontroller uses the i-th group of signal lines to control the i-th bus interface circuit, thereby sending data to the bus or receiving data from the bus; 1≤i≤n;
第i组信号线包括:第i个发送信号线TXi、第i个接收信号线RXi、第i个发送控制信号线HIi和第i个竞争控制信号线CIi;The i-th group of signal lines includes: the i-th transmission signal line TX i , the i-th reception signal line RX i , the i-th transmission control signal line HI i and the i-th competition control signal line CI i ;
第i个总线接口电路接入有第i个正电源+U、第i个负电源-U和地线;The i-th bus interface circuit is connected with the i-th positive power supply +U, the i-th negative power supply-U and the ground wire;
参见图2;第i个总线接口电路包括:第i个上拉电路、第i个下拉电路、第i个回读电路、第i个数据发送控制电路和第i个竞争控制电路;See Figure 2; the i-th bus interface circuit includes: the i-th pull-up circuit, the i-th pull-down circuit, the i-th readback circuit, the i-th data transmission control circuit and the i-th competition control circuit;
第i个下拉电路与第i个正电源相连,并通过第i个一号二极管Di,1接入第i个数据线Datai;The i-th pull-down circuit is connected to the i-th positive power supply, and connected to the i-th data line Data i through the i-th No. 1 diode D i,1 ;
第i个下拉电路与第i个数据发送控制电路相连;The i-th pull-down circuit is connected to the i-th data sending control circuit;
第i个回读电路通过第i个八号电阻Ri,8和第i个数据线Datai相连;The i-th readback circuit is connected to the i-th data line Data i through the i-th No. 8 resistor R i,8 ;
第i个回读电路通过第i个接收信号线RXi与第i个微控制器相连;The i-th readback circuit is connected to the i-th microcontroller through the i-th receiving signal line RX i ;
第i个数据发送控制电路与地线相连,并通过第i个三号二极管Di,3接入第i个回读电路与第i个八号电阻Ri,8之间;The i-th data transmission control circuit is connected to the ground wire, and connected between the i-th readback circuit and the i-th No. 8 resistor R i,8 through the i-th No. 3 diode D i,3 ;
第i个数据发送控制电路分别通过第i个发送信号线TXi和第i个发送控制信号线HIi与第i个微控制器相连;The i-th data transmission control circuit is connected to the i-th microcontroller through the i-th transmission signal line TX i and the i-th transmission control signal line HI i respectively;
第i个上拉电路与第i个负电源相连,并通过第i个二号二极管Di,2接入第i个数据线Datai;第i个下拉电路和第i个上拉电路共同构成了第i个“推挽”式输出电路;当第i个下拉电路中的第i个一号NPN三极管Qi,1导通并且第i个上拉电路中的第i个二号NPN三极管Qi,2截止,第i个总线接口电路被置为“强下拉”输出;当第i个下拉电路中的第i个一号NPN三极管Qi,1截止并且第i个上拉电路中的第i个二号NPN三极管Qi,2导通,则第i个总线接口电路输出被置为“强上拉”输出。The i-th pull-up circuit is connected to the i-th negative power supply, and connected to the i-th data line Data i through the i-th second diode D i,2 ; the i-th pull-down circuit and the i-th pull-up circuit together constitute The i-th "push-pull" output circuit; when the i-th No. 1 NPN transistor Q i,1 in the i-th pull-down circuit is turned on and the i-th No. 2 NPN transistor Q in the i-th pull-up circuit When i , 2 is cut off, the i-th bus interface circuit is set as a "strong pull-down"output; When the i second NPN transistor Q i,2 is turned on, the output of the ith bus interface circuit is set as a "strong pull-up" output.
第i个一号二极管Di,1和第i个二号二极管Di,2共同工作,其功能一是避免了因误将第i个正电源+U和第i个负电源-U接反而损毁第i个总线接口电路和总线;二是分别对第i个下拉电路和第i个上拉电路限幅,避免了由于正电源+U或第i个负电源-U输出电压不稳定而损毁第i个总线接口电路。The i-th No. 1 diode D i,1 and the i-th No. 2 diode D i,2 work together. The first function is to avoid the reverse connection of the i-th positive power supply +U and the i-th negative power supply-U by mistake. Damage the i-th bus interface circuit and the bus; the second is to limit the i-th pull-down circuit and the i-th pull-up circuit respectively, avoiding damage due to unstable output voltage of the positive power supply +U or the i-th negative power supply-U The i-th bus interface circuit.
第i个上拉电路外部接入有第i个五号电阻Ri,5;第i个五号电阻Ri,5的一端接入第i个二号二极管Di,2的负极,另一端接入第i个负电源;第i个五号电阻Ri,5的电阻值很大;当第i个上拉电路中的第i个二号NPN三极管Qi,2和第i个下拉电路中的第i个一号NPN三极管Qi,1均截止,第i个负电源-U可以通过第i个五号电阻Ri,5将第i个总线接口电路输出置为“弱上拉”输出;此时,若总线上第x(1≤x≤n且x≠i)个节点Gx中第x个下拉电路里的第x个五号NPN三极管Qx,5处于导通状态,第i个五号电阻Ri,5可以将第x个正电源+U和第i个负电源-U之间通路中的电流限制在微安级别,避免在第x个正电源+U和第i个负电源-U之间形成低阻通路。The i-th pull-up circuit is externally connected to the i-th No. 5 resistor R i,5 ; one end of the i-th No. 5 resistor R i,5 is connected to the negative pole of the i-th No. 2 diode D i,2 , and the other end Connect to the i-th negative power supply; the resistance value of the i-th No. 5 resistor R i,5 is very large; when the i-th No. 2 NPN transistor Q i,2 in the i-th pull-up circuit and the i-th pull-down circuit The i-th No. 1 NPN transistor Q i, 1 is all cut off, and the i-th negative power supply -U can set the output of the i-th bus interface circuit to "weak pull-up" through the i-th No. 5 resistor R i, 5 Output; at this time, if the xth fifth NPN transistor Qx , 5 in the xth pull-down circuit in the xth (1≤x≤n and x ≠i) node Gx on the bus is in the conduction state, the The i fifth resistor R i,5 can limit the current in the path between the xth positive power supply +U and the ith negative power supply -U to the microampere level, avoiding the xth positive power supply +U and the ith A low-impedance path is formed between a negative power supply -U.
定义:“强上拉”状态和“弱上拉”状态并称为“上拉”状态;Definition: The "strong pull-up" state and the "weak pull-up" state are collectively referred to as the "pull-up" state;
当总线电平状态被置为“强下拉”状态时,第i个回读电路中的第六号NPN三极管Qi,6导通,第i个接收信号线RXi被置为低电平;当总线的电平状态被置为“上拉”状态时,第i个回读电路中的第六号NPN三极管Qi,6截止,第i个接收信号线RXi被置为高电平;若第i个微控制器检测到第i个接收信号线RXi为低电平,则读取到总线处于“强下拉”状态;若第i个微控制器检测到第i个接收信号线RXi为高电平,则读取到总线处于“上拉”状态。When the bus level state is set to "strong pull-down" state, the sixth NPN transistor Q i, 6 in the i-th readback circuit is turned on, and the i-th receiving signal line RX i is set to low level; When the level state of the bus is set to "pull-up" state, the sixth NPN transistor Q i, 6 in the i-th readback circuit is turned off, and the i-th receiving signal line RX i is set to high level; If the i-th microcontroller detects that the i-th receiving signal line RX i is low, it reads that the bus is in a "strong pull-down"state; if the i-th microcontroller detects that the i-th receiving signal line RX If i is high level, it is read that the bus is in the "pull-up" state.
第i个上拉电路与第i个竞争控制电路相连;The i-th pull-up circuit is connected to the i-th competition control circuit;
第i个竞争控制电路通过第i个四号二极管Di,4接入第i个回读电路与第i个八号电阻Ri,8之间;第i个三号二极管Di,3和第i个四号二极管Di,4共同工作,其功能与第i个一号二极管Di,1和第i个二号二极管Di,2共同工作的功能相同。The i-th competition control circuit is connected between the i-th readback circuit and the i-th No. 8 resistor R i, 8 through the i-th No. 4 diode D i, 4 ; the i-th No. 3 diode D i, 3 and The i-th No. 4 diode D i,4 works together, and its function is the same as that of the i-th No. 1 diode D i,1 and the i-th No. 2 diode D i,2 .
第i个竞争控制电路通过第i个竞争控制信号线CIi、第i个发送信号线TXi和第i个发送控制信号线HIi与第i个微控制器相连。The i-th contention control circuit is connected to the i-th microcontroller through the i-th contention control signal line CI i , the i-th transmission signal line TX i and the i-th transmission control signal line HI i .
具体的,第i个竞争控制电路包括:第i个与非门Ui、第i个十二号电阻Ri,12和第i个五号PNP三极管Qi,5;Specifically, the i-th competition control circuit includes: the i-th NAND gate U i , the i-th No. 12 resistor R i,12 and the i-th No. 5 PNP transistor Q i,5 ;
第i个五号PNP三极管Qi,5的发射极接入第i个正电源、集电极分别与第i个四号二极管Di,4的正极和第i个上拉电路相连、基极与第i个十二号电阻Ri,12的一端相连;第i个十二号电阻Ri,12的另一端与第i个与非门Ui的输出端相连;第i个与非门Ui的输入端分别与第i个竞争控制信号线CIi、第i个发送信号线TXi和第i个发送控制信号线HIi相连。The emitter of the i-th No. 5 PNP transistor Q i,5 is connected to the i-th positive power supply, the collector is respectively connected to the anode of the i-th No. 4 diode D i,4 and the i-th pull-up circuit, and the base is connected to the i-th pull-up circuit. One end of the i-th No. 12 resistor R i, 12 is connected; the other end of the i-th No. 12 resistor R i, 12 is connected with the output end of the i-th NAND gate U i ; the i-th NAND gate U The input end of i is connected to the i-th contention control signal line CI i , the i-th transmission signal line TX i and the i-th transmission control signal line HI i respectively.
第i个微控制器利用第i组信号线控制第i个总线接口电路,基于第i个总线接口电路的原理,可以得到第i个微控制器对第i个总线接口电路的控制方式,如表1所示。The i-th microcontroller uses the i-th group of signal lines to control the i-th bus interface circuit. Based on the principle of the i-th bus interface circuit, the control method of the i-th microcontroller on the i-th bus interface circuit can be obtained, as shown in Table 1 shows.
表1 第i个微控制器对第i个总线接口电路的控制方式Table 1 Control mode of the i-th microcontroller to the i-th bus interface circuit
由表1可知,第i个发送控制信号线HIi为控制发送数据的信号线;当第i个发送控制信号线HIi为低电平时,第i个总线接口电路始终保持“弱上拉”状态,不随第i个发送信号线TXi和第i个竞争控制信号线CIi中信号的改变而变化。当第i个发送控制信号线HIi为高电平时,第i个发送信号线TXi和第i个竞争控制信号线CIi中的信号共同决定第i个总线接口电路的输出状态。It can be seen from Table 1 that the i-th transmission control signal line HI i is the signal line that controls the transmission of data; when the i-th transmission control signal line HI i is at low level, the i-th bus interface circuit always maintains a "weak pull-up" The state does not change with the change of the signals in the i-th transmission signal line TX i and the i-th contention control signal line CI i . When the i-th transmission control signal line HI i is at high level, the signals in the i-th transmission signal line TX i and the i-th contention control signal line CI i jointly determine the output state of the i-th bus interface circuit.
当第i个发送控制信号线HIi为高电平时,第i个发送信号线TXi中的信号决定第i个总线接口电路处于“上拉”输出或“强下拉”输出。When the i-th transmission control signal line HI i is at a high level, the signal in the i-th transmission signal line TX i determines that the i-th bus interface circuit is in a "pull-up" output or a "strong pull-down" output.
当第i个发送控制信号线HIi为高电平且第i个发送信号线TXi为高电平时,第i个竞争控制信号线CIi中的信号决定第i个总线接口电路处于“弱上拉”输出或“强上拉”输出。When the i-th transmission control signal line HI i is high level and the i-th transmission signal line TX i is high level, the signal in the i-th contention control signal line CI i determines that the i-th bus interface circuit is in the "weak" state. pull-up" output or "strong pull-up" output.
由第i个总线接口电路的原理可知:当总线上第a(a=1,2,...,n)个总线接口电路为“弱上拉”状态时,则总线也为“弱上拉”状态,;当总线上有b个总线接口电路为“弱上拉”输出,且有c个总线接口电路为“强下拉”输出,b+c=n,则总线为“强下拉”状态。From the principle of the i-th bus interface circuit, it can be known that when the a (a=1,2,...,n) bus interface circuit on the bus is in the "weak pull-up" state, the bus is also in the "weak pull-up" state. "state; when b bus interface circuits are "weak pull-up" output on the bus, and c bus interface circuits are "strong pull-down" output, b+c=n, then the bus is in a "strong pull-down" state.
本实施例中,一种基于总线接口电路的总线通信协议,是应用于由n个节点并联设置在总线上所组成的串行总线结构中,第i个节点包括:第i个微控制器和第i个总线接口电路;第i个微控制器和第i个总线接口电路之间通过第i组信号线相连;第i组信号线包括:第i个发送信号线TXi、第i个接收信号线RXi、第i个发送控制信号线HIi和第i个竞争控制信号线CIi;第i个总线接口电路通过第i个数据线Datai与总线相连;1≤i≤n;In this embodiment, a bus communication protocol based on a bus interface circuit is applied to a serial bus structure composed of n nodes connected in parallel on the bus, and the i-th node includes: the i-th microcontroller and The i-th bus interface circuit; the i-th microcontroller and the i-th bus interface circuit are connected through the i-th group of signal lines; the i-th group of signal lines includes: the i-th sending signal line TX i , the i-th receiving signal line The signal line RX i , the i-th transmission control signal line HI i and the i-th competition control signal line CI i ; the i-th bus interface circuit is connected to the bus through the i-th data line Data i ; 1≤i≤n;
如图3所示,总线通信协议规定:总线的信道编码方式采用双极脉冲不归零负逻辑编码,总线具有两种逻辑值,即逻辑“1”,对应总线“上拉”状态和高电平;逻辑“0”,对应总线“强下拉”状态和低电平;As shown in Figure 3, the bus communication protocol stipulates that the channel coding method of the bus adopts bipolar pulse non-return-to-zero negative logic coding, and the bus has two logic values, namely logic "1", corresponding to the bus "pull-up" state and high power Level; logic "0", corresponding to the bus "strong pull-down" state and low level;
定义希望获得向总线发送数据控制权的节点为参与竞争的节点;不希望获得向总线发送数据控制权的节点为未参与竞争的节点。Define the node that wants to obtain the control right to send data to the bus as the node that participates in the competition; the node that does not want to obtain the control right to send data to the bus is the node that does not participate in the competition.
如图5所示,总线通信协议是按如下步骤进行:As shown in Figure 5, the bus communication protocol is carried out in the following steps:
步骤1、定义变量j和k;假设以第i个节点作为发送节点并向总线发送一帧二进制数据,定义一帧二进制数据的位数为M=m+z+l;m≥2且为偶数,m表示一帧二进制数据中数据位的个数;z=1表示一帧二进制数据中起始位的个数为1,起始位为“0”;l=1表示一帧二进制数据中停止位的个数为1,停止位为“1”;如图4所示,第i个节点向总线发送的数据由若干帧二进制数据构成,二进制数据的帧数可变,但至少为二帧;每帧二进制数据之间设有帧间隔时间,帧间隔时间小于每个二进制数据位的发送周期,数据的第一帧二进制数据是第1帧二进制数据,第二帧二进制数据是第2帧二进制数据;Step 1, define variables j and k; assume that the i-th node is used as the sending node and send a frame of binary data to the bus, and define the number of bits of a frame of binary data as M=m+z+l; m≥2 and an even number , m represents the number of data bits in a frame of binary data; z=1 represents that the number of start bits in a frame of binary data is 1, and the start bit is "0"; l=1 represents a stop in a frame of binary data The number of bits is 1, and the stop bit is "1"; as shown in Figure 4, the data sent by the i-th node to the bus is composed of several frames of binary data, and the number of frames of binary data is variable, but at least two frames; There is a frame interval time between each frame of binary data, and the frame interval time is less than the sending period of each binary data bit. The binary data of the first frame of data is the binary data of the first frame, and the binary data of the second frame is the binary data of the second frame. ;
定义总线中的第i个节点的地址IDi为二进制数据,IDi共有m个地址位;又有第z个节点的地址IDz,1≤z≤n,z≠i,则必须满足IDi≠IDz;此时若IDi<IDz,则第i个节点比第z个节点的优先级高;在一次竞争中,有且只有一个节点获得向总线发送数据的控制权,该节点的优先级必然比所有参与竞争的其他节点都高。Define the address ID i of the i-th node in the bus as binary data, ID i has a total of m address bits; and the address ID z of the z-th node, 1≤z≤n, z≠i, must satisfy ID i ≠ ID z ; at this time, if ID i < ID z , the i-th node has a higher priority than the z-th node; in a competition, there is only one node that obtains the control right to send data to the bus, and the node’s The priority must be higher than all other nodes participating in the competition.
则将第i个节点的地址IDi中的m个地址位中的高位封装为第1帧二进制数据、低位封装为第2帧二进制数据;Then set the high value of the m address bits in the address IDi of the i-th node Bit packed as Frame 1 binary data, low Bit packed as frame 2 binary data;
第1帧二进制数据和第2帧二进制数据中的数据位分别是在每个地址位之前的高位上插入二进制码“1”构成;即,The data bits in the binary data of the first frame and the binary data of the second frame are formed by inserting a binary code "1" into the high bit before each address bit; that is,
第1帧二进制数据的数据位:1,IDm-1,1,IDm-2,1,...,1,IDm/2;Data bits of the first frame of binary data: 1, ID m-1 , 1, ID m-2 , 1,..., 1, ID m/2 ;
第2帧二进制数据的数据位:1,IDm/2-1,1,IDm/2-2,1,...,1,ID0;Data bits of the second frame binary data: 1, ID m/2-1 , 1, ID m/2-2 , 1,..., 1, ID 0 ;
第i个节点通过第i个发送信号线TXi发送数据位,定义发送数据位为“1”时,第i个发送信号线TXi为高电平;发送数据位为“0”时,第i个发送信号线TXi为低电平;The i-th node sends data bits through the i-th transmission signal line TX i , and when the transmission data bit is defined as "1", the i-th transmission signal line TX i is at high level; when the transmission data bit is "0", the i-th transmission signal line i transmission signal line TX i is low level;
若仅有第i个节点和第z个节点是参与竞争的节点,在竞争向总线发送数据的控制权时,第i个节点依次向总线发送第i个节点的第1帧二进制数据和第2帧二进制数据,第z个节点依次向总线发送第z个节点的第1帧二进制数据和第2帧二进制数据;若IDi<IDz,则第i个节点比第z个节点的优先级高,故通过将第i个节点的地址IDi与第z个节点地址IDz中的对应地址位逐位比较,最终优先级高的第i个节点胜出,即第i个节点获得向总线发送数据的控制权。If only the i-th node and the z-th node are nodes participating in the competition, when competing for control of sending data to the bus, the i-th node sends the first frame of binary data and the second frame of the i-th node to the bus in turn For binary data, the zth node sends the first frame of binary data and the second frame of binary data of the zth node to the bus in turn; if ID i < ID z , the i-th node has a higher priority than the z-th node, Therefore, by comparing the address ID i of the i-th node with the corresponding address bits in the address ID z of the z-th node bit by bit, the i-th node with the highest priority wins, that is, the i-th node gets the right to send data to the bus. Control.
步骤2、第i个节点中的微控制器将第i个发送控制信号线HIi置为低电平,表示第i个总线接口电路处于“弱上拉”输出,即表1中的1号方式;Step 2. The microcontroller in the i-th node sets the i-th transmission control signal line HI i to low level, indicating that the i-th bus interface circuit is in the "weak pull-up" output, that is, No. 1 in Table 1 Way;
步骤3、初始化j=1;Step 3, initialize j=1;
步骤4、第i个节点中的微控制器在第j个监听周期Tj下,通过第i个接收信号线RXi采集总线的逻辑值Fj并进行判断,由于未向总线发送数据的节点输出均处“弱上拉”状态,则若总线上的所有节点都未向总线发送数据,此时总线的逻辑值为“1”;参见图4,又由于一帧二进制数据的起始位为逻辑“0”,且帧间隔时间小于一个二进制数据位的发送周期,若在一帧二进制数据发送周期中,第i个节点采集总线的逻辑值Fj始终为“1”,则表示在一帧二进制数据的发送周期中没有节点正在向总线发送数据,定义此时总线处于“空闲”状态;否则总线处于“占用”状态。Step 4. The microcontroller in the i-th node collects the logical value F j of the bus through the i-th receiving signal line RX i in the j-th monitoring period T j and makes a judgment. Since the node that does not send data to the bus The output is in the "weak pull-up" state, if all nodes on the bus do not send data to the bus, the logic value of the bus is "1" at this time; see Figure 4, and because the start bit of a frame of binary data is Logic "0", and the frame interval time is less than the sending cycle of a binary data bit, if in a binary data sending cycle of a frame, the logic value F j of the i-th node acquisition bus is always "1", it means that in a frame In the sending cycle of binary data, no node is sending data to the bus, and it is defined that the bus is in the "idle" state at this time; otherwise, the bus is in the "occupied" state.
当Fj=1时,将j+1赋值给j,并判断j>M是否成立,若成立,即在一帧二进制数据发送周期中,第i个节点采集总线的逻辑值Fj始终为“1”,则表示总线处于“空闲”状态,并执行步骤5;否则重复步骤4执行;When F j = 1, assign j+1 to j, and judge whether j>M is true, if true, that is, in a frame of binary data transmission cycle, the logical value F j of the i-th node acquisition bus is always "1", it means that the bus is in the "idle" state, and execute step 5; otherwise, repeat step 4;
当Fj=0时,则表示总线处于“占用”状态;并返回步骤3执行;When F j =0, it means that the bus is in the "occupied"state; and return to step 3 for execution;
步骤5、初始化k=1;Step 5, initializing k=1;
步骤6、初始化j=0;在第j个发送周期Tj的起始时刻,第i个节点中的微控制器将第i个发送控制信号线HIi置为高电平、并将第i个竞争控制信号线CIi和第i个发送信号线TXi置为低电平后,此时第i个总线接口电路处于“强下拉”输出,第i个节点处于表1中的3号方式,等待第j个发送周期Tj的结束时刻;从而完成第k帧二进制数据中的起始位“0”的发送,并令j=1;Step 6. Initialize j=0; at the start moment of the jth sending cycle T j , the microcontroller in the i-th node sets the i-th sending control signal line HI i to a high level, and sets the i-th After the competition control signal line CI i and the i-th transmission signal line TX i are set to low level, the i-th bus interface circuit is in the "strong pull-down" output at this time, and the i-th node is in the No. 3 mode in Table 1 , waiting for the end moment of the jth sending cycle T j ; thereby completing the sending of the start bit "0" in the kth frame binary data, and making j=1;
步骤7、在第j个发送周期Tj的起始时刻,第i个节点中的微控制器分别将第i个发送控制信号线HIi、第i个竞争控制信号线CIi和第i个发送信号线TXi置为高电平,即第i个节点中的微控制器将第k帧二进制数据的数据位中的第m-j-1位的数据通过第i个发送信号线TXi发送到总线上,从而使得总线处于“强上拉”状态,此时第i个节点处于表1中的4号方式;并在第j个发送周期Tj的结束时刻,将第i个竞争控制信号线CIi置为低电平,从而使得第i个总线接口电路处于“弱上拉”状态,完成总线电平状态“预置”,此时第i个节点处于表1中的2号方式;Step 7. At the starting moment of the j-th sending cycle T j , the microcontroller in the i-th node connects the i-th sending control signal line HI i , the i-th competition control signal line CI i and the i-th The transmission signal line TX i is set to a high level, that is, the microcontroller in the i-th node sends the data of the mj-1th bit in the data bits of the k-th frame of binary data through the i-th transmission signal line TX i to On the bus, so that the bus is in a "strong pull-up" state, at this time the i-th node is in the No. 4 mode in Table 1; and at the end of the j-th sending cycle T j , the i-th competition control signal line CI i is set to low level, so that the i-th bus interface circuit is in the "weak pull-up" state, and the bus level state "presetting" is completed. At this time, the i-th node is in the No. 2 mode in Table 1;
步骤7等价于先使第i个一号NPN三极管Qi,1截止且第i个上拉电路中第i个二号NPN三极管Qi,2导通,将第i个数据线Datai的电平状态通过第i个上拉电路中第i个二号NPN三极管Qi,2从+U拉到-U,并使三极管截止,通过第i个五号电阻Ri,5维持第i个数据线Datai的电平状态。步骤7中也可以使第i个总线接口电路从“强下拉”状态直接转变到“弱上拉”状态,即跳过“强上拉”状态,此时等价于将第i个数据线Datai的电平状态通过第i个五号电阻Ri,5从+U拉到-U。Step 7 is equivalent to first turning off the i-th No. 1 NPN transistor Q i,1 and turning on the i-th No. 2 NPN transistor Q i,2 in the i-th pull-up circuit, and turning on the i-th data line Data i The level state is pulled from +U to -U by the i-th No. 2 NPN transistor Q i,2 in the i-th pull-up circuit, and the triode is turned off, and the i-th is maintained by the i-th No. 5 resistor R i,5 The level state of the data line Data i . In step 7, the i-th bus interface circuit can also be directly changed from the "strong pull-down" state to the "weak pull-up" state, that is, the "strong pull-up" state is skipped, which is equivalent to turning the i-th data line Data The level state of i is pulled from +U to -U through the i-th No. 5 resistor R i,5 .
步骤8、在第j+1个发送周期Tj+1的起始时刻,第i个节点中的微控制器将第k帧二进制数据的数据位中的第m-j-1位的数据,即地址位通过第i个发送信号线TXi发送到总线上;若第i个发送信号线TXi为高电平,则表示第i个总线接口电路维持“弱上拉”输出,此时第i个节点处于表1中的2号节点方式;若第i个发送信号线TXi为低电平,则表示第i个总线接口电路处于“强下拉”输出,此时第i个节点处于表1中的3号节点方式,并且第i个总线接口电路也将总线置为“强下拉”状态;此时若总线上第z个节点也是参与竞争的节点,且第z个节点的第z个发送信号线TXz为高电平,即第z个总线接口电路处于“弱上拉”状态,第z个节点处于表1中的2号节点方式,第i个正电源和第z个负电源之间形成通路,但电流被限制在微安级别,也不会产生总线逻辑值错误;Step 8. At the start moment of the j+1th sending cycle T j+1 , the microcontroller in the i-th node transmits the data of the mj-1th bit in the data bits of the k-th frame of binary data, that is, the address bit It is sent to the bus through the i-th transmission signal line TX i ; if the i-th transmission signal line TX i is high level, it means that the i-th bus interface circuit maintains the "weak pull-up" output, at this time the i-th node In the No. 2 node mode in Table 1; if the i-th transmission signal line TX i is low level, it means that the i-th bus interface circuit is in the "strong pull-down" output, and at this time the i-th node is in the No. 3 node mode, and the i-th bus interface circuit also sets the bus to the "strong pull-down"state; at this time, if the z-th node on the bus is also a node participating in the competition, and the z-th transmission signal line of the z-th node TX z is high level, that is, the zth bus interface circuit is in the "weak pull-up" state, the zth node is in the mode of No. 2 node in Table 1, and the ith positive power supply and the zth negative power supply form a access, but the current is limited to the microampere level, and no bus logic value error will occur;
并在第j+1个发送周期Tj+1的中间时刻,第i个节点中的微控制器通过第i个接收信号线RXi读取总线的逻辑值Fj+1并进行判断,And at the middle moment of the j+1th transmission cycle T j+1 , the microcontroller in the i-th node reads the logic value F j+1 of the bus through the i-th receiving signal line RX i and makes a judgment,
当总线的逻辑值Fj+1与第k帧二进制数据的数据位中的第m-j-1位的数据相同时,等待第j+1个发送周期Tj+1的结束时刻,再将j+2赋值给j,并判断j>m-1是否成立;若成立,表明第i个节点的第k帧二进制数据的数据位已经全部发送完成,则在第j个发送周期Tj的起始时刻,第i个节点中的微控制器分别将第i个发送控制信号线HIi、第i个竞争控制信号线CIi和第i个发送信号线TXi置为高电平后,等待第j个发送周期Tj的结束时刻;从而完成第k帧二进制数据中的停止位的发送,再执行步骤9;否则,表示第i个节点无法通过第i个节点的地址IDi地址位判断自己是否具有高优先级,则返回步骤7执行;When the logic value F j+1 of the bus is the same as the data of the mj-1th bit in the data bits of the kth frame binary data, wait for the end of the j+1th sending cycle T j+1 , and then set j+ 2 Assign a value to j, and judge whether j>m-1 is true; if it is true, it indicates that the data bits of the k-th frame binary data of the i-th node have all been sent, and at the beginning of the j-th sending cycle T j , the microcontroller in the i-th node respectively sets the i-th transmission control signal line HI i , the i-th contention control signal line CI i and the i-th transmission signal line TX i to high level, and waits for the j-th The end moment of the first transmission cycle T j ; thus complete the transmission of the stop bit in the kth frame binary data, and then perform step 9; otherwise, it means that the i-th node cannot pass through the address ID i address bit of the i-th node To judge whether you have a high priority, return to step 7 for execution;
当总线的逻辑值Fj+1与第k帧二进制数据的数据位中的第m-j-1位的数据不相同时,则表示存在高于第i个节点优先级的其他节点,第i个节点中的微控制器将第i个发送控制信号线HIi置为低电平,表示第i个总线接口电路处于“弱上拉”输出,此时第i个节点已退出本次竞争,保留其希望向总线发送的数据,完成一次非破坏性总线仲裁;并返回步骤3执行,重新对总线进行监听,准备参与下一次竞争;When the logic value F j+1 of the bus is not the same as the data of the mj-1th bit in the data bits of the k-th frame binary data, it means that there are other nodes with higher priority than the i-th node, and the i-th node The microcontroller in the i-th transmission control signal line HI i is set to low level, indicating that the i-th bus interface circuit is in the "weak pull-up" output. At this time, the i-th node has withdrawn from this competition, and its It is hoped that the data sent to the bus will complete a non-destructive bus arbitration; and return to step 3 to execute, monitor the bus again, and prepare to participate in the next competition;
步骤9、将k+1赋值给k,并判断k>2是否成立,若成立,表明第i个节点在所有参与竞争的节点中具有最高优先级,则表示第i个节点中的微控制器获得向总线发送数据的控制权并通过第i个数据线Datai完成自身的数据发送;并返回步骤2执行;否则,返回步骤6执行。Step 9. Assign k+1 to k, and judge whether k>2 is true. If it is true, it means that the i-th node has the highest priority among all the nodes participating in the competition, and it means that the microcontroller in the i-th node Obtain the control right to send data to the bus and complete its own data sending through the i-th data line Data i ; and return to step 2 for execution; otherwise, return to step 6 for execution.
举例说明:在图6所示的总线竞争实施例中,一帧二进制数据中数据位的个数m=8,一帧二进制数据的位数M=10。地址ID1为01001001(49H)的第1个节点和地址ID2为01000011(43H)的第2个节点同时监听到总线处于“空闲”状态,并同时依次向总线发送其各自的第1帧二进制数据和第2帧二进制数据,即开始一次竞争。第1个节点和第2个节点在发送各自的第1帧二进制数据和第2帧二进制数据的过程中,对发送的每一个地址位,都进行回读和比较。当发送第2帧二进制数据中数据位的第6位,即地址ID的第3位时,节点1发送的是“1”,即发送逻辑“1”,第1个总线接口电路处于“弱上拉”状态;而第2个节点发送的是“0”,即发送逻辑“0”,第1个总线接口电路处于“强下拉”状态;总线处于“强下拉”状态,此时第1个节点和第2个节点从总线读取的逻辑值为“0”,于是就产生了总线访问冲突。因为第1个节点从总线读取的逻辑值“0”与自己发送的逻辑值“1”不同,便会终止对总线的数据发送,第1个总线接口电路维持“弱上拉”状态,转而对总线进行监听或数据接收;而第2个节点会获得向总线发送数据的控制权,通过第2个数据线Datai完成自身的数据发送,数据发送完成后,第2个总线接口电路被置于“弱上拉”状态,转而对总线进行监听或数据接收。To illustrate: in the bus contention embodiment shown in FIG. 6 , the number of data bits in one frame of binary data is m=8, and the number of bits in one frame of binary data is M=10. The first node whose address ID 1 is 01001001 (49H) and the second node whose address ID 2 is 01000011 (43H) detect that the bus is in the "idle" state at the same time, and send their respective first frame binary to the bus in turn. The data and the binary data of the second frame start a competition. During the process of sending the binary data of the first frame and the binary data of the second frame, the first node and the second node read back and compare each address bit sent. When sending the sixth bit of the data bit in the binary data of the second frame, that is, the third bit of the address ID, what node 1 sends is "1", that is, sending logic "1", and the first bus interface circuit is in the "weak upper Pull"state; while the second node sends "0", that is, sends logic "0", the first bus interface circuit is in the "strong pull-down"state; the bus is in the "strong pull-down" state, at this time the first node The logic value read from the bus by the second node and the second node is "0", so a bus access conflict occurs. Because the logic value "0" read by the first node from the bus is different from the logic value "1" sent by itself, it will terminate the data transmission to the bus, and the first bus interface circuit maintains the "weak pull-up" state, and turns to Monitor or receive data on the bus; and the second node will obtain the control right to send data to the bus, complete its own data transmission through the second data line Data i , after the data transmission is completed, the second bus interface circuit is activated Put it in the "weak pull-up" state, and turn to monitor or receive data on the bus.
Claims (3)
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201610247642.0A CN105955905B (en) | 2016-04-18 | 2016-04-18 | A kind of interface circuit and communication protocol based on serial bus structure |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201610247642.0A CN105955905B (en) | 2016-04-18 | 2016-04-18 | A kind of interface circuit and communication protocol based on serial bus structure |
Publications (2)
Publication Number | Publication Date |
---|---|
CN105955905A CN105955905A (en) | 2016-09-21 |
CN105955905B true CN105955905B (en) | 2018-11-06 |
Family
ID=56917715
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN201610247642.0A Expired - Fee Related CN105955905B (en) | 2016-04-18 | 2016-04-18 | A kind of interface circuit and communication protocol based on serial bus structure |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN105955905B (en) |
Families Citing this family (10)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN107168273B (en) * | 2017-07-26 | 2021-05-18 | 安徽博微长安电子有限公司 | Control circuit of intelligent comprehensive display and control system of granary |
US10558604B2 (en) * | 2017-12-20 | 2020-02-11 | Qualcomm Incorporated | Communication interface transaction security |
CN108287800B (en) * | 2017-12-26 | 2019-02-26 | 北京七芯中创科技有限公司 | A kind of bus arbitration system and method based on single bus communication protocol |
CN109726160B (en) * | 2018-12-20 | 2023-05-09 | 苏州路之遥科技股份有限公司 | Single-bus communication signal relay circuit with monitoring function |
CN110968464A (en) * | 2019-11-19 | 2020-04-07 | 中国航空工业集团公司西安航空计算技术研究所 | Multi-machine switching right-robbing method |
CN111314194A (en) * | 2020-04-15 | 2020-06-19 | 联合华芯电子有限公司 | Data transmission system and method based on multi-level logical operation |
CN111343069A (en) * | 2020-04-15 | 2020-06-26 | 联合华芯电子有限公司 | Distributed control communication bus based on robot sensing system and robot |
CN111314193A (en) * | 2020-04-15 | 2020-06-19 | 联合华芯电子有限公司 | Data transmission bus system, device and method |
CN111923606B (en) * | 2020-06-30 | 2022-03-29 | 厦门汉印电子技术有限公司 | Printer and printing method |
CN117425254B (en) * | 2023-12-18 | 2024-02-27 | 深圳市千岩科技有限公司 | Splicing lamps, controllers, light blocks and detection execution, driving methods and devices |
Citations (5)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN1288543A (en) * | 1997-12-18 | 2001-03-21 | 汤姆森许可公司 | High speed data bus driver |
CN104199795A (en) * | 2014-09-15 | 2014-12-10 | 活点信息技术有限公司 | Bus framework |
CN104301191A (en) * | 2013-06-05 | 2015-01-21 | 上海联影医疗科技有限公司 | Bus system |
CN104951421A (en) * | 2015-05-19 | 2015-09-30 | 重庆大学 | Automatic numbering and type recognition method and device for serial bus communication devices |
CN105354159A (en) * | 2015-09-28 | 2016-02-24 | 上海海视电子有限公司 | RS485 distributed bus system based control method |
Family Cites Families (1)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
KR101330066B1 (en) * | 2012-05-31 | 2013-11-18 | 한국해양과학기술원 | Backplane bus structure of communication system and board cognition method using the same |
-
2016
- 2016-04-18 CN CN201610247642.0A patent/CN105955905B/en not_active Expired - Fee Related
Patent Citations (5)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN1288543A (en) * | 1997-12-18 | 2001-03-21 | 汤姆森许可公司 | High speed data bus driver |
CN104301191A (en) * | 2013-06-05 | 2015-01-21 | 上海联影医疗科技有限公司 | Bus system |
CN104199795A (en) * | 2014-09-15 | 2014-12-10 | 活点信息技术有限公司 | Bus framework |
CN104951421A (en) * | 2015-05-19 | 2015-09-30 | 重庆大学 | Automatic numbering and type recognition method and device for serial bus communication devices |
CN105354159A (en) * | 2015-09-28 | 2016-02-24 | 上海海视电子有限公司 | RS485 distributed bus system based control method |
Non-Patent Citations (2)
Title |
---|
基于CAN总线智能建筑监控系统的通信协议设计;王忠 等;《电子科技》;20100715;第23卷(第7期);全文 * |
基于RS-485总线的智能变送器设计;元江博;《中国优秀硕士学位论文全文数据库》;20110815(第8期);全文 * |
Also Published As
Publication number | Publication date |
---|---|
CN105955905A (en) | 2016-09-21 |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
CN105955905B (en) | A kind of interface circuit and communication protocol based on serial bus structure | |
CN101610192B (en) | Communication slave, bus cascading method and system | |
CN105677608A (en) | Multi-master RS485 bus arbitration method and system | |
CN104009946B (en) | A kind of intelligent terminating resistor and control method | |
CN100563117C (en) | A power line chopping communication transceiver circuit | |
CN100480923C (en) | Controller soft realizing method from I2C bus | |
CN103838700A (en) | level multiplexing control serial communication device and communication method thereof | |
CN104301191A (en) | Bus system | |
CN210324188U (en) | Integrated circuit bus IIC master-slave competition automatic switching equipment and system thereof | |
CN109101402A (en) | The monitoring device and server of VR chip on a kind of server master board | |
CN204760040U (en) | Serial ports burns record ware | |
CN109491362B (en) | Multi-bus protocol testing device | |
CN210270888U (en) | Single-bus communication circuit | |
CN206270694U (en) | A CAN bus automatic coding circuit | |
WO2025016185A1 (en) | Can network, can network control method, and energy storage device | |
CN110471882A (en) | A kind of monobus telecommunication circuit and method | |
CN106610911A (en) | Master control electronic device and communication method thereof | |
CN216013989U (en) | Expansion module number identification circuit | |
CN216527159U (en) | Communication isolation circuit and device | |
CN215264472U (en) | Device for realizing communication with programmable controller through IO interface | |
CN113848794A (en) | Configurable remote I/O module based on CANopen | |
CN209358569U (en) | Differential signaling bus circuit | |
CN113411241A (en) | RS485 communication circuit, communication system and air conditioning system | |
CN112073087A (en) | An AC power grid communication circuit, electrical equipment, communication system and method | |
CN218450611U (en) | LED illumination master-slave equipment connection control system |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
C06 | Publication | ||
PB01 | Publication | ||
C10 | Entry into substantive examination | ||
SE01 | Entry into force of request for substantive examination | ||
GR01 | Patent grant | ||
GR01 | Patent grant | ||
TR01 | Transfer of patent right |
Effective date of registration: 20230612 Address after: Intelligent Manufacturing Technology Research Institute of Hefei University of Technology F426-7, No. 369, Garden Route, Baohe Economic Development Zone, Hefei University of Technology, Anhui Province, 230041 Patentee after: Hefei Jiema Intelligent Technology Co.,Ltd. Address before: Tunxi road in Baohe District of Hefei city of Anhui Province, No. 193 230009 Patentee before: Hefei University of Technology |
|
TR01 | Transfer of patent right | ||
CF01 | Termination of patent right due to non-payment of annual fee |
Granted publication date: 20181106 |