RS485-based one-master multi-slave communication method

By using broadcast reading instructions and bitmap mechanism on the RS485 bus, each slave calculates the delay time and sends bit data with different statuses, solving the problems of low communication efficiency and large ineffective overhead in the prior art, and achieving efficient and real-time communication management.

CN119088746APending Publication Date: 2024-12-06CICHUAN KAIWU INFORMATION TECH CO LTD
View PDF 1 Cites 0 Cited by

Patent Information

Application Number
CN202411296641.6
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-09-18
Publication Date
2024-12-06

AI Technical Summary

Technical Problem

The first master-multi-slave RS485 bus communication method in the prior art is inefficient when the number of slaves is large, and it fails to effectively reduce the invalid communication overhead when the slaves have no data to report.

Method used

By setting up the host and multiple slaves on the RS485 bus, the host sends read instructions using broadcast mode, each slave calculates the delay time, and sends different bit data according to whether there is any data that needs to be reported. The host forms a bitmap to determine if it needs to be reported. to reduce invalid communication.

Benefits of technology

Improve communication efficiency, reduce invalid communication overhead, ensure real-time communication, and effectively manage slaves with data that need to be reported even if the number of slaves increases.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119088746A_ABST
    Figure CN119088746A_ABST
Patent Text Reader

Abstract

The invention discloses a one-master multi-slave communication method based on RS485. The method comprises the following steps: arranging a master and two or more slaves on an RS485 bus; the host sends a first reading instruction to all the slaves, and all the slaves start timing after receiving the first reading instruction; each slave computer calculates corresponding delay time; when the delay time arrives, if a corresponding slave computer has data needing to be reported, first-bit data are sent on the RS485 bus, otherwise, silence is kept or second-bit data are sent; the host receives all bit data and forms a bitmap; and the host sends a second reading instruction to the slave needing to report the data according to the bitmap, and receives the corresponding slave data. According to the method, the delay time is calculated through the slave, so that a traditional polling mode is avoided, and the communication efficiency is improved; through the bit data and bitmap mechanism, the host can read the data of the slave in a targeted manner, and the invalid communication overhead is reduced.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the technical field of communication methods, and in particular to a one-master-multiple-slave communication method based on RS485. Background Art

[0002] RS485 bus is a communication protocol widely used in industrial control systems. It has the advantages of strong anti-interference ability, long transmission distance, and multi-point communication. The traditional one-master-multiple-slave RS485 bus usually adopts a polling mechanism, where the host scans the slaves one by one and waits for responses. In this way, the communication efficiency decreases significantly when the number of slaves increases. In addition, for networks where data changes infrequently, there are situations where the slaves have no data to report, which will generate invalid communication overhead. Therefore, it is necessary to study the one-master-multiple-slave communication method based on RS485.

[0003] In the prior art, Chinese patent CN113094321A discloses a RS485 bus communication method based on group calling and time slot allocation. The host connects n slaves through an RS485 bus. The host and different slaves complete the initialization process through point-to-point polling. The host establishes an address list according to the addresses of all slaves received; the host issues a group calling command; the slave responds to the time slot allocation; the slave priority queue sends back; the slave normal queue sends back. This prior art directly uses the existing RS485 bus without any hardware changes. It uses group calling and sequential response to shorten the bus polling cycle, and uses a priority management mechanism to ensure that important and urgent data are transmitted first.

[0004] However, although the above-mentioned prior art has made certain improvements to the RS485 bus communication method, it still adopts a point-to-point polling mechanism. When the number of slaves is large, the communication efficiency is low. In addition, the above-mentioned prior art does not consider the situation where the slave has no data to report, and there is a lot of invalid communication overhead. Summary of the invention

[0005] The present application provides a one-master-multiple-slave communication method based on RS485, which is used to solve the problem that the prior art adopts a point-to-point polling mechanism, and when the number of slaves is large, the communication efficiency is low, and the situation that the slave has no data to report is not considered, resulting in a lot of invalid communication overhead.

[0006] On the one hand, the present application provides a one-master-multiple-slave communication method based on RS485, comprising the following steps: Step 1: Set up a master and two or more slaves on an RS485 bus.

[0007] Step 2: The host sends a first read instruction to all slaves by broadcasting, and all slaves start timing after receiving the first read instruction.

[0008] Step 3: Each slave calculates the corresponding delay time.

[0009] Step 4, when the delay time arrives, if the corresponding slave has data to report, it sends the first bit of data on the RS485 bus; if there is no data to report, it remains silent or sends the second bit of data, and the first bit of data and the second bit of data are bit data with different states.

[0010] Step 5: The host receives all the bit data and forms a bit map with the received bit data.

[0011] Step six: the host sends a second read instruction to the slave that needs to report data according to the bitmap, and receives the corresponding slave data.

[0012] In a possible implementation, each slave has a unique identification number.

[0013] In a possible implementation, in step three, each slave calculates a corresponding delay time according to its own identification number.

[0014] In a possible implementation, the calculation formula of the delay time is as follows:

[0015] in, Indicates A slave, Indicates The delay time corresponding to each slave is Indicates The baud rate of each slave, Indicates The identification number of a slave.

[0016] In a possible implementation, in step 4, the bit data is one-bit data.

[0017] In a possible implementation, in step 4, when the first bit of data is 1, the second bit of data is 0; when the first bit of data is 0, the second bit of data is 1.

[0018] In a possible implementation, in step five, the host forms a bitmap with the received bit data according to the delay time corresponding to each slave.

[0019] In one possible implementation, if in step 4, the slave that has no data to report remains silent, then in step 5, the host sets the first received data at the corresponding data bit according to the delay time corresponding to each slave, and supplements the remaining data bits with the second bit of data to form a bitmap.

[0020] If in step 4, the slave device that has no data to report sends the second bit of data, then in step 5, the host device sets the received first bit of data and second bit of data to the corresponding data bits according to the delay time corresponding to each slave device to form a bitmap.

[0021] A one-master-multiple-slave communication method based on RS485 in this application has the following advantages: By calculating the delay time through the slave, the traditional polling method is avoided and the communication efficiency is improved; through the bit data and bitmap mechanism, the host can read the slave data in a targeted manner, reducing the invalid communication overhead. When the number of slaves increases, the host can still determine the slaves that need to report data through the bitmap mechanism, thereby ensuring the real-time communication. BRIEF DESCRIPTION OF THE DRAWINGS

[0022] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.

[0023] Figure 1 A flow chart of a one-master-multiple-slave communication method based on RS485 provided in an embodiment of the present application. DETAILED DESCRIPTION

[0024] The following will be combined with the drawings in the embodiments of the present application to clearly and completely describe the technical solutions in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application.

[0025] like Figure 1 As shown, the embodiment of the present application provides a one-master-multiple-slave communication method based on RS485, comprising the following steps: Step 1: Set up a master and two or more slaves on an RS485 bus.

[0026] Step 2: The host sends a first read instruction to all slaves by broadcasting, and all slaves start timing after receiving the first read instruction.

[0027] Step 3: Each slave calculates the corresponding delay time.

[0028] Step 4, when the delay time arrives, if the corresponding slave has data to report, it sends the first bit of data on the RS485 bus; if there is no data to report, it remains silent or sends the second bit of data, and the first bit of data and the second bit of data are bit data with different states.

[0029] Step 5: The host receives all the bit data and forms a bit map with the received bit data.

[0030] Step six: the host sends a second read instruction to the slave that needs to report data according to the bitmap, and receives the corresponding slave data.

[0031] Specifically, in this embodiment, one host and ten slaves are arranged on one RS485 bus. In other possible embodiments, other slaves greater than or equal to two may also be arranged.

[0032] Exemplarily, each slave has a unique identification number.

[0033] Specifically, in this embodiment, the identification numbers of the ten slaves are set to 1 to 10. In other possible embodiments, other forms of identification numbers may also be set.

[0034] Specifically, in step 1, after the host and the slave are set, the slave determines its own identification number through self-test and records the baud rate and time slice interval.

[0035] Exemplarily, in step three, each slave calculates the corresponding delay time according to its own identification number.

[0036] Exemplarily, the calculation formula of the delay time is as follows:

[0037] in, Indicates A slave, Indicates The delay time corresponding to each slave is Indicates The baud rate of each slave, Indicates The identification number of a slave.

[0038] Specifically, in this embodiment, it is assumed that the baud rate of each slave is the same, that is, the delay time corresponding to each slave is only related to the identification number. Since in this embodiment, each slave has a unique identification number, the delay time corresponding to each slave is different and unique.

[0039] Exemplarily, in step 4, the bit data is one-bit data.

[0040] Exemplarily, in step four, when the first bit of data is 1, the second bit of data is 0; when the first bit of data is 0, the second bit of data is 1.

[0041] Specifically, in this embodiment, the first bit of data is set to 1, and the second bit of data is set to 0. In other possible embodiments, the first bit of data may be set to 0, and the second bit of data may be set to 1.

[0042] In an embodiment, when the delay time arrives, the slaves that have no data to report remain silent. In other possible embodiments, the slaves that have no data to report may also be configured to send a second bit of data.

[0043] Exemplarily, in step five, the host forms a bitmap with the received bit data according to the delay time corresponding to each slave.

[0044] Exemplarily, if in step 4, the slaves that have no data to report remain silent, then in step 5, the host sets the first received data at the corresponding data bit according to the delay time corresponding to each slave, and supplements the remaining data bits with the second data bit to form a bitmap.

[0045] If in step 4, the slave device that has no data to report sends the second bit of data, then in step 5, the host device sets the received first bit of data and second bit of data to the corresponding data bits according to the delay time corresponding to each slave device to form a bitmap.

[0046] Specifically, in this embodiment, the slaves that have data to report send the first bit of data, which is 1, and the slaves that have no data to report remain silent. Taking the bitmap 0011011001 generated by the host as an example, it can be seen that the 3rd, 4th, 6th, 7th, and 10th slaves send the first bit of data, and the host sets the received first bit of data on the corresponding data bit. The 1st, 2nd, 5th, 8th, and 9th slaves remain silent, and the host supplements the 1st, 2nd, 5th, 8th, and 9th data bits with the second bit of data, and the second data bit is 0. The above bitmap indicates that the 3rd, 4th, 6th, 7th, and 10th slaves have data to report, and the host sends the second read instruction to the 3rd, 4th, 6th, 7th, and 10th slaves according to the above bitmap, and receives the corresponding slave data.

[0047] In a possible embodiment, the one-master-multiple-slave communication method in the present application is compared with the traditional one-master-multiple-slave RS485 bus communication method. According to the communication parameters of 1200bps baud rate and 8N1 data format, when the host sends 10 bytes and waits for 10 bytes, the traditional one-master-multiple-slave RS485 bus communication method polls a slave and needs at least 167ms. When a host and ten slaves are set on an RS485 bus, the time to poll ten slaves needs at least 1.67s, that is, the data refresh rate of each slave is 1.67s, which obviously cannot meet the real-time requirement. And adopting the one-master-multiple-slave communication method in the present application, it is not necessary to poll ten slaves one by one, but to send the first read instruction to all slaves at the same time by broadcasting, and to read the slave data in a targeted manner by bit data and bitmap mechanism, so as to avoid the slaves without data to be reported occupying the communication overhead.

[0048] The embodiment of the present application avoids the traditional polling method by calculating the delay time through the slave, thereby improving the communication efficiency; through the bit data and bitmap mechanism, the host can read the slave data in a targeted manner, reducing the invalid communication overhead. When the number of slaves increases, the host can still determine the slaves that have data to report through the bitmap mechanism, thereby ensuring the real-time communication.

[0049] Although the preferred embodiments of the present application have been described, those skilled in the art may make other changes and modifications to these embodiments once they have learned the basic creative concept. Therefore, the appended claims are intended to be interpreted as including the preferred embodiments and all changes and modifications falling within the scope of the present application.

[0050] Obviously, those skilled in the art can make various changes and modifications to the present application without departing from the spirit and scope of the present application. Thus, if these modifications and variations of the present application fall within the scope of the claims of the present application and their equivalents, the present application is also intended to include these modifications and variations.

Claims

1. A one-master-multiple-slave communication method based on RS485, characterized in that: The following steps are involved: Step 1, setting a host and two or more slaves on an RS485 bus; Step 2: the host sends a first read instruction to all slaves by broadcasting, and all slaves start timing after receiving the first read instruction; Step 3, each slave calculates the corresponding delay time; Step 4, when the delay time arrives, if the corresponding slave has data to report, it sends the first bit of data on the RS485 bus; if there is no data to report, it remains silent or sends the second bit of data, and the first bit of data and the second bit of data are bit data with different states; Step 5: The host receives all the bit data and forms a bit map with the received bit data; Step six: the host sends a second read instruction to the slave that needs to report data according to the bitmap, and receives the corresponding slave data.

2. A one-master-multiple-slave communication method based on RS485 according to claim 1, characterized in that, Each slave has a unique identification number.

3. A one-master-multiple-slave communication method based on RS485 according to claim 2, characterized in that, In step 3, each slave calculates the corresponding delay time according to its own identification number.

4. A one-master-multiple-slave communication method based on RS485 according to claim 3, characterized in that, The calculation formula of the delay time is as follows: in, Indicates A slave, Indicates The delay time corresponding to each slave is Indicates The baud rate of each slave, Indicates The identification number of a slave.

5. A one-master-multiple-slave communication method based on RS485 according to claim 1, characterized in that, In step 4, the bit data is one-bit data.

6. A one-master-multiple-slave communication method based on RS485 according to claim 5, characterized in that: In step 4, when the first bit of data is 1, the second bit of data is 0; when the first bit of data is 0, the second bit of data is 1.

7. A one-master-multiple-slave communication method based on RS485 according to claim 1, characterized in that: In step five, the host forms a bitmap with the received bit data according to the delay time corresponding to each slave.

8. A one-master-multiple-slave communication method based on RS485 according to claim 7, characterized in that: If in step 4, the slaves that have no data to report remain silent, then in step 5, the host sets the first received data bit to the corresponding data bit according to the delay time corresponding to each slave, and supplements the remaining data bits with the second data bit to form a bitmap; If in step 4, the slave device that has no data to report sends the second bit of data, then in step 5, the host device sets the received first bit of data and second bit of data to the corresponding data bits according to the delay time corresponding to each slave device to form a bitmap.

Citation Information

Patent Citations

  • RS485 bus communication method based on group calling and time slot allocation

    CN113094321A