A serial port automatic addressing communication method and system

Through the combination of serial port automatic addressing communication method and hardware circuit, the cumbersome problem of slave address update in point-to-multipoint serial communication is solved, automatic identification and update of slave address is realized, and communication efficiency and accuracy are improved.

CN118260227BActive Publication Date: 2024-10-11SICHUAN SHUNENG ELECTRIC ENERGY TECH CO LTD +1
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202410491412.3
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-04-23
Publication Date
2024-10-11
Estimated Expiration
2044-04-23

AI Technical Summary

Technical Problem

In a point-to-multipoint serial communication system, the host needs to enter the addresses of all slaves in advance. When new slaves are added or old slaves are removed, manual updates are required. The operation is cumbersome and error-prone, resulting in communication failure.

Method used

The serial port automatic addressing communication method is used, combined with the software addressing process and hardware circuits, to realize automatic collection and update of slave addresses. Through the format and strategy of broadcast addressing messages and response messages, all slave addresses are automatically identified and recorded. , to ensure the accuracy and efficiency of address updates.

Benefits of technology

It realizes automatic update of slave addresses, reduces manual intervention, improves communication efficiency, ensures that all slave addresses are correctly identified and recorded, and newly added or invalid slave addresses can be processed without additional operations.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118260227B_ABST
    Figure CN118260227B_ABST
Patent Text Reader

Abstract

The present invention discloses a serial port automatic addressing communication method and system, which is applied to the host to periodically collect and update the addresses of each slave; including: the host sends a broadcast addressing message from the minimum address upward; all slaves receive the broadcast addressing message, each slave determines whether the current local address is greater than or equal to the addressing start address of the broadcast addressing message, and the satisfied slaves all start to respond at the same time, and use the minimum address slave priority response strategy to reply the slave response message to the host; the host determines whether it is the maximum address, and if so, the automatic addressing and updating address list is ended; if not, the host uses the received slave address + 1 as the new addressing start address, and continues to broadcast the addressing message upward again; this cycle is repeated until there is no more slave response or the slave address is the maximum address, at which time the host exits the cycle and the addressing is ended. The present invention realizes the automatic addressing and collection function of the slave address during serial port point-to-multipoint communication, and automatically updates the valid address list.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The invention relates to the field of serial port communication, and in particular to a serial port automatic addressing communication method and system. Background Art

[0002] In a point-to-multipoint serial communication system, a host communicates with multiple slaves. When the host and the slave communicate, they rely on the address to distinguish which slave to communicate with. Different slaves have different addresses. Usually, before establishing normal communication, all slave addresses need to be entered in advance on the host side before communication can be carried out. Once a new slave is added or an old slave is removed, the slave address needs to be manually entered or deleted. The operation is very cumbersome, and while increasing the workload, it is also easy to cause communication failure due to incorrect address entry.

[0003] In view of this, this application is hereby filed. Summary of the invention

[0004] The technical problem to be solved by the present invention is that in point-to-multipoint serial communication, before establishing normal communication, it is usually necessary to enter all slave addresses in advance on the host side before communication can be carried out. Once a new slave is added or an old slave is removed, it is necessary to manually enter or delete the slave address. The operation is very cumbersome, and while increasing the workload, it is also easy to cause communication failure due to incorrect address entry.

[0005] The present invention aims to provide a serial port automatic addressing communication method and system, which combines software addressing process and hardware circuit to realize the automatic addressing and collection function of slave addresses during serial port point-to-multipoint communication and automatically update the valid address list.

[0006] The present invention is achieved through the following technical solutions:

[0007] In a first aspect, the present invention provides a serial port automatic addressing communication method, which is applied to a host to periodically collect and update the address of each slave; the method comprises:

[0008] The host sends broadcast addressing messages from the smallest address upwards;

[0009] All slaves receive the broadcast addressing message, and each slave determines whether the current local address is greater than or equal to the addressing start address of the broadcast addressing message. The slaves that meet the requirement start the response at the same time, and use the minimum address slave priority response strategy to reply the slave response message to the host;

[0010] The host determines whether it is the maximum address. If so, it ends the automatic addressing and updates the address list. If not, the host uses the received slave address + 1 as the new addressing start address and continues to broadcast the addressing message upwards.

[0011] When the addressing message is broadcast upward again, if there is no slave response, the automatic addressing and address list update will be terminated; if there is a slave response, the slave with the smallest address in the valid address segment will respond first;

[0012] This cycle continues until there is no more slave response or the slave address has reached the maximum address. At this time, the master exits the cycle, addressing ends, all current slaves are addressed, and the master records and updates the slave directory.

[0013] Furthermore, the format of the broadcast addressing message is a message start character, an addressing start address, a control code, a data check code and a message end character;

[0014] The format of the slave machine's response message is the message start character, the local address, the control code, the data check code and the message end character.

[0015] Furthermore, the length of the addressing start address is consistent with the length of the slave address, and the minimum single byte address of the addressing start address and the slave address is 0x00, and the maximum address is 0xFF;

[0016] When the control code is a certain value, the message is a broadcast addressing message or a slave reply message.

[0017] Furthermore, the minimum address slave priority response strategy is based on the principle of 0 priority when multiple slaves respond. When the slave replies to the address, only the one with the smallest address can be received by the host. Other non-minimum address slaves will exit the response when encountering a level conflict during transmission.

[0018] Further, the hardware circuit of the minimum address slave priority response strategy includes a pull-up resistor R1, a pull-up resistor R2, diodes D1-Dn, and XOR gates XOR1-XORn;

[0019] One end of the pull-up resistor R1 is connected to the data transmission pin (TX pin) of the host M1, and the other end of the pull-up resistor R1 is connected to the positive electrode VCC of the system power supply; one end of the pull-up resistor R2 is connected to the data reception pin (RX pin) of the host M1, and the other end of the pull-up resistor R2 is connected to the positive electrode VCC of the system power supply;

[0020] The data receiving pin (RX pin) of the host M1 is connected to the data transmitting pin (TX pin) of the slave S1-Sn through the diode D1-Dn. The data receiving pin (RX pin) of the host M1 is connected to the positive end of each diode D1-Dn, and the data transmitting pin (TX pin) of the slave S1-Sn is connected to the negative end of the corresponding diode D1-Dn.

[0021] The data transmission pin (TX pin) of the master M1 is connected to the data receiving pin (RX pin) of each slave;

[0022] The input pins of each XOR gate XOR1-XORn are connected to the positive and negative electrodes of the diodes respectively, and the output pins of each XOR gate XOR1-XORn are connected to the TX_EN pin of the slave.

[0023] Further, the pull-up resistors R1 and R2 are used to provide a pull-up high level for the data receiving pin (RX pin) and the data transmitting pin (TX pin) of the host M1;

[0024] Diodes D1-Dn are used for unidirectional level isolation to enable each slave of the serial port to send low level 0 first;

[0025] XOR gates XOR1-XORn are used to monitor whether the output level of the slave data transmission pin (TX pin) is consistent with the level received by the data receiving pin (RX pin) of the host M1, so as to realize the exit response mechanism; if they are consistent, the corresponding XOR gate outputs a low level; if they are inconsistent, it outputs a high level and notifies the slave to interrupt the current data transmission.

[0026] Furthermore, the data receiving pin (RX pin) of each slave device adopts a floating input mode to reduce the load current when the data transmitting pin (TX pin) of the host M1 drives the level.

[0027] Furthermore, the method enables all slave addresses to be addressed and collected by the host in order from small to large.

[0028] In a second aspect, the present invention further provides a communication system based on the above-mentioned serial port automatic addressing communication method, the system comprising a host M1, slaves S1-Sn and a minimum address slave priority response circuit;

[0029] The host M1 is used to send broadcast addressing messages from the smallest address upwards and receive slave response messages; and determine whether it is the largest address. If so, the automatic addressing is terminated and the address list is updated; if not, the received slave address + 1 is used as the new addressing start address, and the broadcast addressing message is continued upwards again; this cycle is repeated until there is no slave response or the slave address is the largest address, at which time the cycle is exited, the addressing is terminated, all current slaves are addressed, and the updated slave directory is recorded;

[0030] Slave machines S1-Sn are used to receive broadcast addressing messages. Each slave machine determines whether the current local address is greater than or equal to the addressing start address of the broadcast addressing message. The satisfied slave machines all start to respond at the same time, and use the minimum address slave priority response circuit to reply the slave response message to the host; and when receiving the broadcast addressing message from the host again, if there is no slave machine response, the automatic addressing and address list update is terminated; if there is a slave machine response, the minimum address slave in the valid address segment is given priority to respond;

[0031] The minimum address slave priority response circuit is used for communication between the host M1 and several slaves. Based on the principle of 0 priority when multiple slaves respond, when the slave replies to the address, only the one with the smallest address can be received by the host. Other non-minimum address slaves will exit the response when encountering a level conflict during the transmission.

[0032] Further, the minimum address slave priority response circuit includes a pull-up resistor R1, a pull-up resistor R2, diodes D1-Dn, and XOR gates XOR1-XORn;

[0033] One end of the pull-up resistor R1 is connected to the data transmission pin (TX pin) of the host M1, and the other end of the pull-up resistor R1 is connected to the positive electrode VCC of the system power supply; one end of the pull-up resistor R2 is connected to the data reception pin (RX pin) of the host M1, and the other end of the pull-up resistor R2 is connected to the positive electrode VCC of the system power supply;

[0034] The data receiving pin (RX pin) of the host M1 is also connected to the data transmitting pin (TX pin) of the slave S1-Sn through the diodes D1-Dn. The data receiving pin (RX pin) of the host M1 is connected to the positive terminals of the diodes D1-Dn, and the data transmitting pins (TX pins) of the slaves S1-Sn are connected to the negative terminals of the corresponding diodes D1-Dn.

[0035] The data transmission pin (TX pin) of the master M1 is also connected to the data receiving pin (RX pin) of each slave;

[0036] The input pins of each XOR gate XOR1-XORn are connected to the positive and negative electrodes of the diodes respectively, and the output pins of each XOR gate XOR1-XORn are connected to the TX_EN pin of the slave.

[0037] Compared with the prior art, the present invention has the following advantages and beneficial effects:

[0038] 1. A serial port automatic addressing communication method and system of the present invention, combining software addressing process and hardware circuit, realizes the automatic addressing and collection function of slave addresses during serial port point-to-multipoint communication, and automatically updates the valid address list;

[0039] 2. A serial port automatic addressing communication method and system of the present invention, all slave addresses in the valid address range can be automatically collected and addressed by the host without manual input and intervention;

[0040] 3. A serial port automatic addressing communication method and system of the present invention automatically updates, adds or deletes the addresses of newly added slaves or invalid slaves in the system;

[0041] 4. The present invention provides a serial port automatic addressing communication method and system, with efficient addressing operation. If there are N slaves, the host can address all of them by sending a maximum of N+1 addressing messages. BRIEF DESCRIPTION OF THE DRAWINGS

[0042] The drawings described herein are used to provide a further understanding of the embodiments of the present invention, constitute a part of this application, and do not constitute a limitation of the embodiments of the present invention. In the drawings:

[0043] Figure 1 This is a flow chart of a serial port automatic addressing communication method of the present invention;

[0044] Figure 2 is a structural block diagram of the communication system of the present invention;

[0045] Figure 3 This is a timing diagram of each slave responding to sending an address level in step 2) of embodiment 1 of the present invention;

[0046] Figure 4 This is a timing diagram of the address level sent when the S2 / S3 slave responds in step 3) of embodiment 1 of the present invention;

[0047] Figure 5 This is a timing diagram of the address level sent when the S3 slave responds in step 4) of embodiment 1 of the present invention;

[0048] Figure 6 This is a structural block diagram of the communication system of embodiment 1 of the present invention. DETAILED DESCRIPTION

[0049] Hereinafter, the term "include" or "may include" used in various embodiments of the present invention indicates the presence of the invented function, operation or element, and does not limit the addition of one or more functions, operations or elements. In addition, as used in various embodiments of the present invention, the terms "include", "have" and their cognates are intended only to indicate specific features, numbers, steps, operations, elements, components or combinations of the foregoing items, and should not be understood as first excluding the presence of one or more other features, numbers, steps, operations, elements, components or combinations of the foregoing items or the possibility of adding one or more features, numbers, steps, operations, elements, components or combinations of the foregoing items.

[0050] In various embodiments of the present invention, the expression "or" or "at least one of A or / and B" includes any combination or all combinations of the words listed at the same time. For example, the expression "A or B" or "at least one of A or / and B" may include A, may include B, or may include both A and B.

[0051] The expressions (such as "first", "second", etc.) used in various embodiments of the present invention may modify the various constituent elements in various embodiments, but may not limit the corresponding constituent elements. For example, the above expressions do not limit the order and / or importance of the elements. The above expressions are only used for the purpose of distinguishing an element from other elements. For example, the first user device and the second user device indicate different user devices, although both are user devices. For example, without departing from the scope of various embodiments of the present invention, the first element may be referred to as the second element, and similarly, the second element may also be referred to as the first element.

[0052] It should be noted that if it is described that one component element is “connected” to another component element, the first component element may be directly connected to the second component element, and a third component element may be “connected” between the first component element and the second component element. Conversely, when one component element is “directly connected” to another component element, it can be understood that there is no third component element between the first component element and the second component element.

[0053] The terms used in various embodiments of the present invention are only used for the purpose of describing specific embodiments and are not intended to limit various embodiments of the present invention. As used herein, the singular form is intended to also include the plural form, unless the context clearly indicates otherwise. Unless otherwise limited, all terms used here (including technical terms and scientific terms) have the same meaning as the meaning generally understood by those of ordinary skill in the art to which the various embodiments of the present invention belong. The terms (such as the terms defined in the dictionary generally used) will be interpreted as having the same meaning as the contextual meaning in the relevant technical field and will not be interpreted as having an idealized meaning or an overly formal meaning, unless clearly defined in various embodiments of the present invention.

[0054] In order to make the objectives, technical solutions and advantages of the present invention more clearly understood, the present invention is further described in detail below in conjunction with embodiments and drawings. The exemplary embodiments of the present invention and their description are only used to explain the present invention and are not intended to limit the present invention.

[0055] In point-to-multipoint serial communication, before establishing normal communication, it is usually necessary to enter all slave addresses on the host side in advance before communication can be carried out. Once a new slave is added or an old slave is removed, it is necessary to manually enter or delete the slave address. The operation is very cumbersome, increasing the workload and easily causing communication failure due to incorrect address entry.

[0056] Therefore, based on the above problems, the present invention designs a serial port automatic addressing communication method and system, which combines the software addressing process and the hardware circuit to realize the automatic addressing and collection function of the slave address during serial port point-to-multipoint communication, and automatically updates the valid address list.

[0057] First, at the software protocol layer, the addressing process established between the host and each slave is as follows Figure 1 shown.

[0058] The format of the automatic addressing message (i.e., broadcast addressing message) sent by the host includes but is not limited to Table 1, as follows:

[0059] Table 1 Broadcast addressing message format

[0060]

[0061] The slave response message format includes but is not limited to Table 2, as follows:

[0062] Table 2 Slave response message format

[0063] Message start character Slave Address Control Code Data check code Message end character Customizable Custom length Customizable Customizable Customizable

[0064] in:

[0065] Message start character: The host and slave agree on a fixed value as the message start character.

[0066] Addressing start address: The length is consistent with the slave address length, which can be defined by the host and slave. The minimum single byte address is 0x00 and the maximum address is 0xFF. The high byte is defined in front and the low byte is in the back.

[0067] After receiving the broadcast addressing message from the host, the slave compares the addressing start address value with the current address of the machine and agrees on it:

[0068] If the current slave address ≥ the addressing address, the current slave starts the response;

[0069] If the current slave address is less than the addressing address, the current slave will give up the response.

[0070] Slave address: current slave address, byte length can be customized, high byte first, byte last, single byte value range is 0x00-0xFF.

[0071] Control code: When the control code is a certain value agreed upon by the host and the slave, this message is a broadcast addressing message or a slave reply message.

[0072] Data verification code: The data verification method and length are agreed upon by the host and the slave.

[0073] Message terminator: A fixed value agreed upon by the host and the slave as the message terminator.

[0074] Specifically, the host periodically performs an address acquisition update. When the host sends a broadcast addressing message, it first sets all the addressing start address bytes to the minimum value 0x00 to ensure that all slave addresses are ≥ the current addressing start address. According to the protocol, all slaves will respond to the host. When there are multiple slaves with different addresses, all slaves will respond to the host addressing request at the same time and reply to the local address in the agreed format. The hardware circuit according to the present invention has the characteristic of low level (0) priority transmission (see the hardware circuit description for the specific principle). Therefore, when the slave replies to the address, only the address with the smallest address can be received by the host. According to the characteristics of the hardware circuit, other non-minimum address slaves will encounter a level conflict during the transmission and exit the transmission.

[0075] Therefore, the first slave address received by the host is the smallest address value among all slaves. At this time, the host will use the received slave address + 1 as the new addressing start address and broadcast the addressing message again. In this way, the new addressing start address is greater than the addressed slave address. According to the protocol, the addressed slave will no longer respond. Similarly, the slave with the smallest address among the remaining unaddressed slaves will be addressed. This cycle will continue until no slave responds or the slave address is the maximum address (all address bytes are 0xFF). At this time, the host exits the cycle, the addressing ends, all current slaves will be addressed, and the host records and updates the slave directory.

[0076] Second, hardware circuits, such as Figure 2 shown.

[0077] (1) Principle of 0 priority when multiple slaves respond:

[0078] When the host sends a broadcast addressing message, all slaves receive it at the same time. All slaves set the same delayed response reply parameters in the software program, that is, all slaves will respond to the host at the same time, so that all slaves can send data synchronously. Since the serial port protocol stipulates that the low level is the binary number 0 and the high level is the binary number 1, when multiple slaves respond to send data at the same time, as long as one slave sends 0, the high level on the host data receiving pin (RX pin) will be pulled low. Due to the unidirectional conduction principle of diode Dx, the data sending pins (TX pins) of other slaves cannot affect the low level of the host data receiving pin (RX pin) even if they output 1. The host data receiving pin (RX pin) receives 0, that is, 0 has priority transmission when performing binary bit transmission.

[0079] (2) When multiple slaves respond, the slave with the non-minimum address exits the response mechanism:

[0080] It is agreed that the high bit is transmitted first and the low bit is transmitted later in bit transmission, and the high byte is transmitted first and the low byte is transmitted later in byte transmission. When there are multiple slaves competing for the sending address, if 0 and 1 appear at the same time in the high bit of the slave address, according to the 0 priority principle, the host data receiving pin (RX pin) is 0 low level, and the slave will have the following two situations:

[0081] Case 1: For a slave whose data transmission pin (TX pin) outputs 0, the levels at both ends of the diode are the same and are 0, and the XOR gate circuit connected to it outputs 0 (according to the XOR gate circuit logic). The slave TX_EN pin does not detect a high-level transmission interrupt signal, and the slave continues to send the next bit of data.

[0082] Case 2: For a slave whose data transmission pin (TX pin) outputs 1, the voltage levels at both ends of the diode are different, one end is 1 and the other end is 0, and the output of the XOR gate circuit connected to it is 1 (according to the logic of the XOR gate circuit). The slave MCU program is set to immediately interrupt and exit the current message sending once the TX_EN pin receives the high-level signal 1 output by the XOR gate circuit.

[0083] When the slave address is sent from high to low, the address value gradually decreases, and the slave with a larger address value will quit responding halfway. Only the slave with the smallest address can normally send the message and be addressed by the host. In this way, the non-smallest address slave can quit responding when multiple slaves respond.

[0084] Example 1

[0085] like Figure 1 and Figure 2 As shown, the present invention provides a serial port automatic addressing communication method, which is applied to the host to periodically collect and update the address of each slave; the method comprises:

[0086] The host sends broadcast addressing messages from the smallest address upwards;

[0087] All slaves receive the broadcast addressing message, and each slave determines whether the current local address is greater than or equal to the addressing start address of the broadcast addressing message. The slaves that meet the requirement start the response at the same time, and use the minimum address slave priority response strategy to reply the slave response message to the host;

[0088] The host determines whether it is the maximum address. If so, it ends the automatic addressing and updates the address list. If not, the host uses the received slave address + 1 as the new addressing start address and continues to broadcast the addressing message upwards.

[0089] When the addressing message is broadcast upward again, if there is no slave response, the automatic addressing and address list update will be terminated; if there is a slave response, the slave with the smallest address in the valid address segment will respond first;

[0090] This cycle continues until there is no more slave response or the slave address has reached the maximum address. At this time, the master exits the cycle, addressing ends, all current slaves are addressed, and the master records and updates the slave directory.

[0091] As a further implementation, the format of the broadcast addressing message is a message start character, an addressing start address, a control code, a data check code and a message end character;

[0092] The format of the slave machine's response message is the message start character, the local address, the control code, the data check code and the message end character.

[0093] As a further implementation, the length of the addressing start address is consistent with the length of the slave address, and the minimum single byte address of the addressing start address and the slave address is 0x00 and the maximum address is 0xFF;

[0094] When the control code is a certain value, the message is a broadcast addressing message or a slave reply message.

[0095] As a further implementation, the minimum address slave priority response strategy is based on the principle of 0 priority when multiple slaves respond. When the slave replies to the address, only the one with the smallest address can be received by the host. Other non-minimum address slaves will exit the response when encountering a level conflict during transmission.

[0096] As a further implementation, the hardware circuit of the minimum address slave priority response strategy includes a pull-up resistor R1, a pull-up resistor R2, diodes D1-Dn, and XOR gates XOR1-XORn;

[0097] One end of the pull-up resistor R1 is connected to the data transmission pin (TX pin) of the host M1, and the other end of the pull-up resistor R1 is connected to the positive electrode VCC of the system power supply; one end of the pull-up resistor R2 is connected to the data reception pin (RX pin) of the host M1, and the other end of the pull-up resistor R2 is connected to the positive electrode VCC of the system power supply;

[0098] The data receiving pin (RX pin) of the host M1 is connected to the data transmitting pin (TX pin) of the slave S1-Sn through the diode D1-Dn. The data receiving pin (RX pin) of the host M1 is connected to the positive end of each diode D1-Dn, and the data transmitting pin (TX pin) of the slave S1-Sn is connected to the negative end of the corresponding diode D1-Dn.

[0099] The data transmission pin (TX pin) of the master M1 is connected to the data receiving pin (RX pin) of each slave;

[0100] The input pins of each XOR gate XOR1-XORn are connected to the positive and negative electrodes of the diodes respectively, and the output pins of each XOR gate XOR1-XORn are connected to the TX_EN pin of the slave.

[0101] As a further implementation, the pull-up resistors R1 and R2 are used to provide a pull-up high level for the data receiving pin (RX pin) and the data transmitting pin (TX pin) of the host M1;

[0102] Diodes D1-Dn are used for unidirectional level isolation to enable each slave of the serial port to send low level 0 first;

[0103] XOR gates XOR1-XORn are used to monitor whether the output level of the slave data transmission pin (TX pin) is consistent with the level received by the data receiving pin (RX pin) of the host M1, so as to realize the exit response mechanism; if they are consistent, the corresponding XOR gate outputs a low level; if they are inconsistent, it outputs a high level and notifies the slave to interrupt the current data transmission.

[0104] As a further implementation, the data receiving pin (RX pin) of each slave device adopts a floating input mode to reduce the load current when the data transmitting pin (TX pin) of the host M1 drives the level.

[0105] As a further implementation, the method realizes that all slave addresses are addressed and collected by the host in order from small to large.

[0106] When it comes to specific implementation,

[0107] This embodiment takes a three-slave serial port communication system as an example. Figure 6 As shown; follow the instructions below to see how the system implements the automatic addressing function:

[0108] The host broadcast addressing message format is defined in Table 3, as follows:

[0109] Table 3 Broadcast addressing message format example

[0110] Message start character Addressing start address Control Code Data check code Message end character 0x55 0x00 0x90 CS 0x16

[0111] The definition of the slave addressing response message format is shown in Table 4, as follows:

[0112] Table 4 Slave addressing response message format example

[0113] Message start character Current local address Control Code Data check code Message end character 0x55 0x00-0xFF 0x91 CS 0x16

[0114] The definitions of the slave addresses of S1, S2, and S3 are shown in Table 5, as follows:

[0115] Table 5 Slave address table

[0116] Slave Number S1 S2 S3 Hexadecimal address 0x01 0x02 0x80 Binary Address 0000 0001 0000 0010 1000 0000

[0117] The specific steps are as follows:

[0118] 1) The host sends a broadcast addressing message: 0x55 00 90CS16;

[0119] 2) All slaves receive the host broadcast addressing message, S1 / S2 / S3 slave address ≥ addressing start address 0x00, so S1 / S2 / S3 slaves all start to respond at the same time. The timing diagram of each slave responding to send address level is as follows Figure 3 As shown;

[0120] like Figure 3 As shown, the hardware circuit determines that the low level 0 has the priority to send. When the output level of the slave data sending pin (TX pin) is different from the level of the host data receiving pin (RX pin), the corresponding XOR gate outputs a high level to the slave TX_EN pin. The slave program interrupts the data transmission. Therefore, when the slave S3 sends the bit 7 data, the transmission is terminated due to the high level of the S3_TX_EN pin; when the slave S2 sends the bit 1 data, the transmission is terminated due to the high level of the S2_TX_EN pin; the address data 0x01 sent by the slave S1 is received by the host M1.

[0121] 3) After the host receives the address 0x01 of the slave S1, it changes the addressing start address to 0x01+1, that is, 0x02, and sends the broadcast addressing message 0x55 02 90CS16 again. Only when the address of the S2 / S3 slave is ≥ the addressing start address 0x02 and the address of the S1 slave is < the addressing start address 0x02, according to the protocol, S1 does not respond. When the S2 / S3 slave responds, the address level timing diagram is as follows: Figure 4 As shown:

[0122] Similar to the above step 2), slave S3 exits sending when sending bit 7, and the address data 0x02 sent by slave S2 is received by host M1.

[0123] 4) After the host receives the address 0x02 of the slave S2, it changes the addressing start address to 0x02+1, i.e. 0x03, and sends the broadcast addressing message 0x55 03 90CS16 again. Only the address of the slave S3 is ≥ the addressing start address 0x02. According to the protocol, S1 / S2 does not respond. When the slave S3 responds, the address level timing diagram is as follows: Figure 5 shown.

[0124] The address data 0x08 sent by slave S3 is received by master M1.

[0125] 5) After receiving the address 0x80 of slave S3, the host changes the addressing start address to 0x80+1, i.e. 0x81, and sends the broadcast addressing message 0x55 81 90CS16 again. The slave addresses of S1 / S2 / S3 are less than the addressing start address 0x81. S1 / S2 / S3 do not respond. The host ends this round of addressing after waiting for the response times out. The host M1 obtains the addresses of slaves S1, S2, and S3 in turn.

[0126] The present invention implements the addressing and collection of all slave addresses in ascending order by the host through the above steps 1) to 5).

[0127] Example 2

[0128] like Figure 2 As shown, the difference between this embodiment and embodiment 1 is that this embodiment provides a communication system based on a serial port automatic addressing communication method of embodiment 1, the system includes a host M1, slaves S1-Sn and a minimum address slave priority response circuit; M1 is a communication host, S1 to Sn are slaves, the master and slaves can be in the form of, but not limited to, MCU\FPGA\PC, etc., and the number of slaves can be increased or decreased according to actual needs;

[0129] The host M1 is used to send broadcast addressing messages from the smallest address upwards and receive slave response messages; and determine whether it is the largest address. If so, the automatic addressing is terminated and the address list is updated; if not, the received slave address + 1 is used as the new addressing start address, and the broadcast addressing message is continued upwards again; this cycle is repeated until there is no slave response or the slave address is the largest address, at which time the cycle is exited, the addressing is terminated, all current slaves are addressed, and the updated slave directory is recorded;

[0130] Slave machines S1-Sn are used to receive broadcast addressing messages. Each slave machine determines whether the current local address is greater than or equal to the addressing start address of the broadcast addressing message. The satisfied slave machines all start to respond at the same time, and use the minimum address slave priority response circuit to reply the slave response message to the host; and when receiving the broadcast addressing message from the host again, if there is no slave machine response, the automatic addressing and address list update is terminated; if there is a slave machine response, the minimum address slave in the valid address segment is given priority to respond;

[0131] The minimum address slave priority response circuit is used for communication between the host M1 and several slaves. Based on the principle of 0 priority when multiple slaves respond, when the slave replies to the address, only the one with the smallest address can be received by the host. Other non-minimum address slaves will exit the response when encountering a level conflict during the transmission.

[0132] In this embodiment, Figure 2 As shown, the minimum address slave priority response circuit includes a pull-up resistor R1, a pull-up resistor R2, diodes D1-Dn, and XOR gates XOR1-XORn;

[0133] One end of the pull-up resistor R1 is connected to the data sending pin (TX pin) of the host M1, and the other end of the pull-up resistor R1 is connected to the positive pole of the system power supply VCC; one end of the pull-up resistor R2 is connected to the data receiving pin (RX pin) of the host M1, and the other end of the pull-up resistor R2 is connected to the positive pole of the system power supply VCC; the function of the pull-up resistor R1 and the pull-up resistor R2 is to provide a pull-up high level for the RX and TX pins of M1.

[0134] The data receiving pin (RX pin) of the host M1 is also connected to the data transmitting pin (TX pin) of the slave S1-Sn through the diode D1-Dn. The data receiving pin (RX pin) of the host M1 is connected to the positive end of each diode D1-Dn, and the data transmitting pin (TX pin) of the slave S1-Sn is connected to the negative end of the corresponding diode D1-Dn. The role of the diode in this circuit is level isolation, so that the low level is sent first.

[0135] The data transmission pin (TX pin) of the host M1 is also connected to the data receiving pin (RX pin) of each slave; the RX pin of each slave adopts a floating input mode to reduce the load current when the host TX pin drives the level.

[0136] U4, U5, and U6 are XOR gate circuits of the slave. The input pins of each XOR gate XOR1-XORn are connected to the positive and negative electrodes of the diodes respectively, and the output pins of each XOR gate XOR1-XORn are connected to the TX_EN pin of the slave. The function of the XOR gate in this circuit is to monitor whether the output level of the slave TX pin is consistent with the level received by the host RX pin. If they are consistent, XOR outputs a low level, otherwise it outputs a high level. If they are inconsistent, it outputs a high level to notify the slave to interrupt the current data transmission.

[0137] The present invention implements a unidirectional level isolation by adding a diode between the RX pin of the host and the TX pin of each slave, thereby realizing a low-level 0 priority transmission function of the serial port; in addition, an XOR gate is added at both ends of the diode Dx on the TX pin of the slave to monitor the level difference between the TX pin of the slave and the RX pin of the host, thereby realizing an exit response mechanism.

[0138] Those skilled in the art will appreciate that the embodiments of the present application may be provided as methods, systems, or computer program products. Therefore, the present application may adopt the form of a complete hardware embodiment, a complete software embodiment, or an embodiment in combination with software and hardware. Moreover, the present application may adopt the form of a computer program product implemented in one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) that include computer-usable program code.

[0139] The present application is described with reference to the flowcharts and / or block diagrams of the methods, devices (systems), and computer program products according to the embodiments of the present application. It should be understood that each process and / or box in the flowchart and / or block diagram, as well as the combination of the processes and / or boxes in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to generate a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.

[0140] These computer program instructions may also be stored in a computer readable memory capable of directing a computer or other programmable data processing device to operate in a specific manner, so that the instructions stored in the computer readable memory produce an article of manufacture including an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.

[0141] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operating steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing instructions for implementing the process. Figure 1 A process or multiple processes and / or boxes Figure 1 The steps for the functions specified in one or more boxes.

[0142] The specific implementation methods described above further illustrate the objectives, technical solutions and beneficial effects of the present invention in detail. It should be understood that the above description is only a specific implementation method of the present invention and is not intended to limit the scope of protection of the present invention. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and principles of the present invention should be included in the scope of protection of the present invention.

Claims

1. A serial port automatic addressing communication method, It is characterized in that The method is applied to the host to periodically collect and update the address of each slave; the method includes: The host sends broadcast addressing messages from the smallest address upwards; All slaves receive the broadcast addressing message, and each slave determines whether the current local address is greater than or equal to the addressing start address of the broadcast addressing message. The slaves that meet the condition all start to respond at the same time, and reply the slave response message to the host using the minimum address slave priority response strategy; The host determines whether it is the maximum address. If so, it ends the automatic addressing and updates the address list. If not, the host uses the received slave address + 1 as the new addressing start address and continues to broadcast the addressing message upwards. When the addressing message is broadcast upward again, if there is no slave response, the automatic addressing and address list update will be terminated; if there is a slave response, the slave with the smallest address in the valid address segment will respond first; This cycle continues until there is no more slave response or the slave address is the maximum address. At this time, the master exits the cycle and the addressing ends. All current slaves will be addressed, and the master records and updates the slave directory. The format of the broadcast addressing message is a message start character, an addressing start address, a control code, a data check code and a message end character; The format of the slave machine response message is a message start character, a local machine address, a control code, a data check code and a message end character.

2. A serial port automatic addressing communication method according to claim 1, It is characterized in that The length of the addressing start address is consistent with the length of the slave address. The minimum single byte address of the addressing start address and the slave address is 0x00, and the maximum address is 0xFF.

3. A serial port automatic addressing communication method according to claim 1, It is characterized in that The minimum address slave priority response strategy is based on the principle of 0 priority when multiple slaves respond. When the slave replies to the address, only the one with the smallest address can be received by the host. Other non-minimum address slaves will exit the response when encountering a level conflict during transmission.

4. A serial port automatic addressing communication method according to claim 3, It is characterized in that The hardware circuit of the minimum address slave priority response strategy includes a pull-up resistor R1, a pull-up resistor R2, diodes D1-Dn, and XOR gates XOR1-XORn; One end of the pull-up resistor R1 is connected to the data sending pin of the host M1, and the other end of the pull-up resistor R1 is connected to the positive electrode VCC of the system power supply; one end of the pull-up resistor R2 is connected to the data receiving pin of the host M1, and the other end of the pull-up resistor R2 is connected to the positive electrode VCC of the system power supply; The data receiving pin of the host M1 is connected to the data sending pins of the slaves S1-Sn through diodes D1-Dn, the data receiving pin of the host M1 is connected to the positive terminals of the diodes D1-Dn, and the data sending pins of the slaves S1-Sn are connected to the negative terminals of the corresponding diodes D1-Dn. The data transmission pin of the master M1 is connected to the data receiving pin of each slave; The input pins of each XOR gate XOR1-XORn are connected to the positive and negative electrodes of the corresponding diodes D1-Dn, and the output pins of each XOR gate XOR1-XORn are connected to the TX_EN pin of the slave.

5. A serial port automatic addressing communication method according to claim 4, It is characterized in that The pull-up resistors R1 and R2 are used to provide a pull-up high level for the data receiving pin and the data sending pin of the host M1; The diodes D1-Dn are used for unidirectional level isolation to achieve low level 0 priority transmission of each slave of the serial port; The XOR gates XOR1-XORn are used to monitor whether the output level of the slave data sending pin is consistent with the level received by the data receiving pin of the host M1, so as to realize the exit response mechanism; if they are consistent, the corresponding XOR gate outputs a low level; If they are inconsistent, a high level is output and the slave is notified to interrupt the current data transmission.

6. A serial port automatic addressing communication method according to claim 4, It is characterized in that The data receiving pins of the slave devices adopt a floating input mode to reduce the load current when the data sending pin of the host M1 is driven at a level.

7. A serial port automatic addressing communication method according to claim 1, It is characterized in that This method enables all slave addresses to be addressed and collected by the host in ascending order.

8. A communication system based on a serial port automatic addressing communication method as claimed in any one of claims 1 to 7, It is characterized in that The system includes a host M1, slaves S1-Sn and a minimum address slave priority response circuit; The host M1 is used to send a broadcast addressing message from the smallest address upwards, and receive a slave response message; and determine whether it is the largest address, if so, then end the automatic addressing and update the address list; if not, then take the received slave address + 1 as the new addressing start address, and continue to broadcast the addressing message upwards again; this cycle is repeated until there is no slave response or the slave address is the largest address, then exit the cycle, the addressing is completed, all current slaves will be addressed, and the updated slave directory will be recorded; The slaves S1-Sn are used to receive the broadcast addressing message, and each slave determines whether the current local address is greater than or equal to the addressing start address of the broadcast addressing message, and the slaves that meet the condition all start to respond at the same time, and use the minimum address slave priority response circuit to reply the slave response message to the host; When receiving the broadcast addressing message from the host again, if there is no slave response, the automatic addressing and address list update will be terminated; if there is a slave response, the slave with the smallest address in the valid address segment will respond first; The minimum address slave priority response circuit is used for communication between the host M1 and several slaves. Based on the principle of 0 priority when multiple slaves respond, when the slaves reply with addresses, only the one with the smallest address can be received by the host. Other slaves with non-minimum addresses will exit the response when encountering a level conflict during transmission.

9. The communication system according to claim 8, It is characterized in that The minimum address slave priority response circuit includes a pull-up resistor R1, a pull-up resistor R2, diodes D1-Dn, and XOR gates XOR1-XORn; One end of the pull-up resistor R1 is connected to the data sending pin of the host M1, and the other end of the pull-up resistor R1 is connected to the positive electrode VCC of the system power supply; one end of the pull-up resistor R2 is connected to the data receiving pin of the host M1, and the other end of the pull-up resistor R2 is connected to the positive electrode VCC of the system power supply; The data receiving pin of the host M1 is also connected to the data sending pins of the slaves S1-Sn via diodes D1-Dn. The data receiving pin of the host M1 is connected to the positive terminals of the diodes D1-Dn, and the data sending pins of the slaves S1-Sn are connected to the negative terminals of the corresponding diodes D1-Dn. The data transmission pin of the host M1 is also connected to the data receiving pins of each slave; The input pins of each XOR gate XOR1-XORn are connected to the positive and negative electrodes of the corresponding diodes D1-Dn, and the output pins of each XOR gate XOR1-XORn are connected to the TX_EN pin of the slave.