Summary of the invention
The technical assignment of the technical problem to be solved in the present invention and proposition is that prior art scheme is improved and improved, half competitive mode RS-485 bus multi-master communication system and method for work thereof is provided, to realize the information mutual communication that gets final product between many host nodes, improve the object of communication speed.For this reason, the present invention takes following technical scheme.
Half competitive mode RS-485 bus multi-master communication system, comprise the host node be located in bus and multiple from node, it is characterized in that: described host node is connected with bus by first interface chip, described is connected with bus by the second interface chip from node, described is provided with input and receives from node transmitted signal end and from node the same OR circuit that signal end is connected from node, the two-way D type rising edge trigger being connected with same OR circuit output, input and two-way D type rising edge trigger output and the OR circuit being connected from node transmitted signal end, OR circuit output, from node, receiving signal end is connected with the second interface chip, between the cathode output end of the second interface chip and positive source, establish the first resistance, between the cathode output end of the second interface chip and earth terminal, establish the second resistance, transmitted signal end, the reception signal end of described host node are directly connected with first interface chip, the reception signal pins of first interface chip is joined by pull-up resistor and power supply, and the reception of first interface chip and transmission Enable Pin pin are by pull down resistor ground connection.From the transmitted signal end of node with receive the signal end signal consequential signal of competing through same OR circuit after, when identical, competition results signal be high, represents to send successfully, during difference, competition results signal is low, expression sends unsuccessfully; When competition results signal is while being low, the output of two-way D type rising edge trigger is set to 1, is output as 1, the second interface chip and stops sending data after OR circuit; When bus is during in idle condition, from node transmitted signal end and reception signal end, be height, competition results signal is high, processor sends data from the transmitted signal end of node, at first trailing edge, two-way D type rising edge trigger is output as 0, now or door output by transmitted signal end signal, determined, when transmitted signal end signal is 0, the second interface chip is to bus output 0, when transmitted signal end signal is 1, the second interface chip is in accepting state, and bus is maintained 1 state by the first resistance and the second resistance.In bus contention process, due to multiple, from node, to bus, send data simultaneously, when having " 0 ", " 1 " simultaneously, can produce conflict, can cause from node interface and damage, when serious, can cause bus paralysis, for avoiding bus collision, adopt the similar Lou mode of output of opening when node interface designs, from node interface, only to bus, export " 0 " signal, " 1 " signal keeps by first, second resistance mating in bus, with this, avoids from internodal data collision.Pull down resistor guarantee first interface chip when idle condition in accepting state, discharge bus control right, can receive data from bus, simultaneously when needs send data to bus, by first interface chip enable end is drawn high, make first interface chip in transmission state, can send data to bus, now, first interface chip does not receive the data in bus, pull-up resistor is guaranteed to receive signal and is always high level, for without data mode.When host node with from node, send while conflict, each node has the retransmission mechanism of makeing mistakes, and detects to conflict exit transmission from node, host node sends because detecting conflict always, until send successfully.Owing to thering is monitor function from node, host node is had precedence over from node, and adopt competition mechanism between node.Guaranteeing, under the preferential prerequisite of host node, to improve the transmission speed from node.The present invention sets about from hardware, and sent data are carried out to monitoring reception, and working stability, reliability are high, and speed is faster.
As the further of technique scheme improved and supplemented, the present invention also comprises following additional technical feature.
From node transmitted signal end, after not circuit, be connected with the CLK pin of two-way D type rising edge trigger.
Half competitive mode RS-485 bus multi-master communication system works method, is characterized in that comprising the following steps:
1) allly in bus from node, monitor all the time bus, when data in bus exceed break period, set the byte transmission time, think that bus is in idle condition, what now need to send data starts competition bus from node; When bus is busy, the node that need to send data was waited for until the bus free time;
2) during competition bus, what send data first sends address information to bus from node, and and take position as unit carries out hardware conflicts detection, if when synchronization has " 1 " " 0 " to send conflict, bus only sends " 0 " signal, what send data monitors from node the data that bus is transmitted, if different from sent data,, for to compete unsuccessfully, exit competition, stop sending;
3) competition successfully obtains general line control from node, can start to send data, if the Transmission time exceedes the byte of setting, discharges bus;
4) when host node with from node, send while conflict, from node, have the retransmission mechanism of makeing mistakes, from node, detect that conflict exits transmission, host node sends because detecting conflict always, until send successfully, assurance host node preferentially sends data, without time delay, retransmits.And in native system, adopt hardware conflicts detection mode, and take position, be unit, once produce conflict, a side of failure exits automatically, a side of controlled power can continue to send data, guarantees that this secondary data correctly sends.Therefore, native system has more direct collision detection and escape mechanism, and guarantees that host node can preferentially send data simultaneously, without delayed retransmission.
Beneficial effect: the technical program is by the improvement to RS-485 control mode, realized information mutual communication instant between many host nodes, control mode is simple and reliable, avoided from internodal bus collision, having very high practical is worth, guaranteeing, under the preferential prerequisite of host node, to improve the transmission speed from node.
Embodiment
Below in conjunction with Figure of description, technical scheme of the present invention is described in further detail.
As Fig. 3, 4, shown in 5, the present invention includes the host node be located in bus and multiple from node, described host node is connected with bus by first interface chip U0, described is connected with bus by the second interface chip U2 from node, described is provided with input and receives from node transmitted signal end TXD and from node the same OR circuit U4 that signal end RXD is connected from node, the two-way D type rising edge trigger U3A being connected with same OR circuit U4 output, the OR circuit U1 that input is connected with two-way D type rising edge trigger U3A output and from node transmitted signal end TXD, OR circuit U1 output, from node, receiving signal end RXD is connected with the second interface chip U2, between the cathode output end of the second interface chip U2 and positive source, establish the first resistance R 2, between the cathode output end of the second interface chip U2 and earth terminal, establish the second resistance R 3, transmitted signal end TXD, the reception signal end RXD of described host node are directly connected with first interface chip U0, the reception signal pins RO of first interface chip joins by pull-up resistor R1 and power supply, and Enable Pin pin/RE, the DE of the reception of first interface chip and transmission is by pull down resistor R0 ground connection.From node transmitted signal end TXD, after not circuit U5, be connected with the CLK pin of two-way D type rising edge trigger U3A.From the transmitted signal end TXD and reception signal and the consequential signal FAIL that competes after same OR circuit U4 of node, when identical, competition results signal FAIL is high, represents to send successfully, and when different, competition results signal FAIL is low, and expression sends unsuccessfully, when competition results signal FAIL is while being low, two-way D type rising edge trigger U3A output is set to 1, is output as 1, the second interface chip U2 and stops sending data after OR circuit U1, when bus is during in idle condition, from node transmitted signal end TXD and reception signal end RXD, be height, competition results signal FAIL is high, processor sends data from the transmitted signal end TXD of node, at first trailing edge, two-way D type rising edge trigger U3A is output as 0, now or door output by transmitted signal end TXD signal deciding, when transmitted signal end TXD signal is 0, the second interface chip U2 is to bus output 0, when transmitted signal end TXD signal is 1, the second interface chip U2 is in accepting state, bus maintains 1 by the first resistance R 2 and the second resistance R 3.Pull down resistor R2 guarantee first interface chip U1 when idle condition in accepting state, discharge bus control right, simultaneously can receive data from bus.When needs send data to bus, by DIR is drawn high, make first interface chip U1 in transmission state, can send data to bus.Now, first interface chip U1 does not receive the data in bus, and pull-up resistor R1 guarantees to receive signal RXD and is always high level, for without data mode.
Half competitive mode RS-485 bus multi-master communication system control method, comprises the following steps:
1) allly in bus from node, monitor all the time bus, when data in bus exceed break period, set the byte transmission time, think that bus is in idle condition, what now need to send data starts competition bus from node; When bus is busy, the node that need to send data was waited for until the bus free time;
2) during competition bus, what send data first sends address information to bus from node, and and take position as unit carries out hardware conflicts detection, if synchronization has " 1 " " 0 " to send when conflict, bus only sends " 0 " signal, what send data monitors from node the data that bus is transmitted, if, different from sent data, for to compete unsuccessfully, exit competition, stop sending;
3) competition successfully obtains general line control from node, can start to send data, if the Transmission time exceedes the byte of setting, discharges bus;
4) when host node with from node, send while conflict, from node, have the retransmission mechanism of makeing mistakes, from node, detect to conflict and exit transmission, host node sends because detecting conflict always, until send successfully, guarantee that host node preferentially sends data, without time delay, retransmit.
Half competitive mode RS-485 bus multi-master communication system and method for work thereof shown in above Fig. 3,4,5 are specific embodiments of the invention; the outstanding substantive distinguishing features of the present invention and marked improvement have been embodied; can be according to actual use needs; under enlightenment of the present invention; it is carried out to the equivalent modifications of the aspects such as shape, structure, all at the row of the protection range of this programme.