An adaptive RS232 and RS485 interface circuit
By designing the interface circuit of adaptive RS232 and RS485, the identification module and communication switching module are used to realize automatic identification and switching of interfaces, solving the problems of low degree of automation and high cost in the existing technology, and achieving low technical risks and low Cost and high automation interface management.
Patent Information
- Application Number
- CN202311161792.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-09-08
- Publication Date
- 2025-02-14
- Estimated Expiration
- 2043-09-08
AI Technical Summary
In the prior art, the RS232 and RS485 interfaces have low automation, high cost, and require professional operation, which poses technical risks.
An adaptive interface circuit of RS232 and RS485 is designed, including connectors, communication switching modules, identification modules, active control selection modules, RS232 interface communication modules, RS485 interface communication modules and logic control circuits. The interface type is identified through the identification module. And use the communication switching module to achieve automatic switching.
It realizes automatic identification and automatic switching of the RS232 and RS485 interfaces, reduces hardware costs, reduces manual intervention, improves the degree of automation, reduces technical and management risks, and has a low cost and meets domestic controllable requirements.
Smart Images

Figure CN117271416B_ABST
Abstract
Description
Technical Field
[0001] The invention relates to the technical field of interface communication, and in particular to an adaptive RS232 and RS485 interface circuit. Background Art
[0002] With the development of "strong smart grid", more and more communication, monitoring and control equipment are appearing in the secondary system of distribution network. These equipment usually need to be connected to DTU (distribution automation station terminal) through RS232 or RS485. DTU processes their data and sends it to the main distribution network station through optical fiber, network, wireless network, etc. There are many types of these equipment, such as: 4G module, Bluetooth module, GPS, encryption module, partial discharge monitor, mechanical property monitor, temperature and humidity controller, power module, human-machine interaction panel, etc. There is no unified interface standard for these devices at present. They are usually designed as RS232 or RS485 interfaces according to the manufacturer's wishes. In addition, the types and manufacturers of these equipment required by each municipal bureau are different. DTU is a standard product, which requires the number of communication interfaces of DTU to be as large as possible, but the position of UART port and panel terminal of DTU itself is limited and cannot be increased indefinitely. Therefore, in the "GBT 35732-2017 Technical Specifications for Intelligent Terminals for Distribution Automation", Section 7.6.1 stipulates that "IDTU should have no less than 4 RS-232 / 485 interfaces". Therefore, the industry usually designs the communication ports for multiplexing, and the interface type can be switched to RS232 or RS485 by manual jumper. This method makes the best use of hardware resources and improves utilization.
[0003] However, this switching method requires opening the device box and pulling out the board for configuration, which has certain technical risks, so it requires professionals to operate, and each configuration needs to perform the above operation once, and the degree of automation is not high. On the market, Analog Devices has a chip LTC2873 that can meet the above requirements, but it is not only expensive, but also contrary to the current trend of domestically produced independent control.
[0004] Therefore, a highly automated, low-tech risk, low-cost, domestically controllable solution is needed to realize automatic identification and automatic switching between RS232 and RS485. Summary of the invention
[0005] The invention provides an adaptive RS232 and RS485 interface circuit, which mainly solves the problems of low automation and high cost in the prior art, simplifies hardware cost, reduces manual intervention, completes automatic identification and automatic switching of RS232 and RS485 communication modes, and has the advantages of high automation, low technical risk, low cost, domestic controllability, flexible control, high reliability, etc.
[0006] The present invention achieves the above-mentioned purpose through the following technical solutions:
[0007] An adaptive RS232 and RS485 interface circuit comprises a connector, a communication switching module, an identification module, an active control selection module, an RS232 interface communication module, an RS485 interface communication module, and a logic control circuit. The connector is arranged at a physical interface for accessing an external communication device. The identification module is connected to the connector and is used to identify the physical interface type of the external communication device and control the communication switching module to switch the interface communication module according to the identification result. The communication switching module is respectively connected to the RS232 interface communication module and the RS485 interface communication module, and uses an analog switch to select a channel to complete the automatic switching of the RS232 or RS485 communication mode. The active control selection module is respectively connected to the communication switching module and a single-chip microcomputer module, and controls the communication switching module through a photoelectric coupler by outputting high and low levels of the single-chip microcomputer module. The logic control circuit is respectively connected to the RS232 interface communication module and the RS485 interface communication module using a logic AND gate chip, and the output pin of the logic control circuit is connected to the single-chip microcomputer module.
[0008] According to the adaptive RS232 and RS485 interface circuit provided by the present invention, the connector includes a three-wire RS232 or a two-wire RS485 standard interface, which is defined as RS485-A / RS232-TXD, RS485-B / RS232-RXD, and GND. It can be seen that the present invention reuses the communication lines of RS485 and RS232, saves the number of connectors, and reduces the area occupied by the connectors.
[0009] According to an adaptive RS232 and RS485 interface circuit provided by the present invention, the communication switching module includes an electronic switching switch, the normally closed contacts NO1 and NO2 of the electronic switching switch are respectively connected to the A and B pins of the RS485 interface communication module; the normally open contacts NC1 and NC2 of the electronic switching switch are respectively connected to the TXD and RXD pins of the RS232 interface communication module; the common contacts COM1 and COM2 of the electronic switching switch are connected to the output to communicate with the external device;
[0010] The electronic switch has two switch control pins CTRL1 and CTRL2. When the level is high, the two COMs of the electronic switch are connected to NO respectively; when the level is low, the two COMs of the electronic switch are connected to NC respectively.
[0011] According to an adaptive RS232 and RS485 interface circuit provided by the present invention, the identification module includes a comparator, a delay control circuit, a reference voltage, a control circuit, and a differential-common mode conversion circuit. The in-phase input pin of the comparator is connected to the reference voltage, the inverting input pin of the comparator is connected to RS232-RXD / RS485-B, the output pin of the comparator is connected to the delay control circuit, and the delay control circuit is connected to the control circuit.
[0012] According to an adaptive RS232 and RS485 interface circuit provided by the present invention, the delay control circuit includes a resistor R14, a resistor R15, a diode D2, a capacitor C3, a resistor R16 and a transistor Q2, the first end of the resistor R14 is connected to the output pin of the comparator, the second end of the resistor R14 is connected to the first end of the resistor R15 and the positive electrode of the diode D2, the second end of the resistor R15 is connected to the negative electrode of the diode D2 and then to the first end of the resistor R16 and the first end of the capacitor C3, the second end of the resistor R16 is connected to the base of the transistor Q2, and the collector of the transistor Q2 is connected to the communication switching module.
[0013] According to an adaptive RS232 and RS485 interface circuit provided by the present invention, the active control module includes a first photocoupler and a second photocoupler, the input pin of the first photocoupler is connected to RS485_TAG, the input pin of the second photocoupler is connected to RS232_TAG, the CTRL pin of the electronic switching switch is connected between the output pin of the first photocoupler and the output pin of the second photocoupler, a resistor R3 is connected to the COM1 pin of the electronic switching switch, and a resistor R7 is connected to the COM2 pin of the electronic switching switch, which are used to convert the differential level of RS485 into a common mode voltage.
[0014] According to an adaptive RS232 and RS485 interface circuit provided by the present invention, when the voltage of RS232-RXD / RS485-B is greater than -A value, the output pin of the comparator outputs -B value, and when the voltage of RS232-RXD / RS485-B is less than -A, the output pin of the comparator outputs +B value;
[0015] Therefore, the positive or negative value of the output pin of the comparator is used to express whether the voltage of RS232-RXD / RS485-B is less than -AV, which provides a basis for the next step of signal processing.
[0016] According to an adaptive RS232 and RS485 interface circuit provided by the present invention, when the output pin of the comparator outputs a +B value, the capacitor C3 is charged. Since the diode D2 is connected in parallel with the resistor R16, the diode D2 is forward-conducted at this time, and the charging constant of the capacitor C3 is expressed as formula (1):
[0017] t1=R14×C3 (1)
[0018] The voltage of capacitor C3 begins to rise. When the voltage across capacitor C3 exceeds the voltage of the B pole of transistor Q2, the C and E poles of transistor Q2 gradually turn on. When formula (2) is satisfied, transistor Q2 is completely saturated and the C pole is approximately grounded, which causes the CTRL1 and CTRL2 pins of the electronic switch to be grounded through the seventh resistor. The electronic switch switches the communication interface from RS485 to RS232:
[0019]
[0020] According to an adaptive RS232 and RS485 interface circuit provided by the present invention, when the output pin of the comparator outputs a -B value, the capacitor voltage is higher than the comparator output voltage, and the capacitor C3 is discharged through the resistor R14 and the resistor R15, so the discharge constant of the capacitor C3 is expressed as formula (3):
[0021] t2= (R14+R15) × C3 (3)
[0022] The voltage of capacitor C3 begins to drop, and the base current flowing through transistor Q2 begins to decrease. Since the voltage of the CTRL pin of the electronic switch is considered to be high when it is greater than 1.4V, when formula (4) is satisfied, the electronic switch switches the communication interface from RS232 to RS485:
[0023]
[0024] According to the adaptive RS232 and RS485 interface circuit provided by the present invention, the priority of the active selection module is higher than the priority of the automatic switching.
[0025] It can be seen that compared with the prior art, the present invention has the following beneficial effects:
[0026] 1. The present invention can realize automatic identification and automatic switching between RS232 interface and RS485 interface.
[0027] 2. The connectors of the present invention can be shared, and there is no need to use two sets of connectors. Compared with the traditional 485 port to 485 or 232 to 232, the present invention adopts a multiplexing design, that is, it can connect to 232 or 485, saving the number of connectors and reducing the area occupied by the connectors.
[0028] 2. The present invention can configure a fixed interface type or use automatic identification through remote operation and maintenance tools, thereby improving the automation level of the power system;
[0029] 3. The present invention can realize hot plug and play and non-stop operation when replacing external devices, and no longer needs to disassemble the equipment, further reducing technical and management risks;
[0030] 4. RS232 and RS485 of the present invention share one set of CPU resources, which can reduce CPU resource occupancy and save CPU pin resources;
[0031] 5. All components of the present invention are independently controllable, do not rely on imports, and do not require some additional expensive dedicated chips. The cost can be well controlled, the cost is relatively low, the system complexity is reduced, and co-line interference is eliminated. It meets the customer's flexible configuration needs and provides protection for the construction of smart grids.
[0032] The present invention is further described in detail below in conjunction with the accompanying drawings and specific embodiments. BRIEF DESCRIPTION OF THE DRAWINGS
[0033] Figure 1 The present invention is a schematic diagram of an adaptive RS232 and RS485 interface circuit embodiment.
[0034] Figure 2 The invention discloses a circuit principle diagram of an adaptive RS232 and RS485 interface circuit embodiment.
[0035] Figure 3 The invention discloses a specific hardware circuit schematic diagram of an adaptive RS232 and RS485 interface circuit embodiment.
[0036] Figure 4 The present invention is a simulation circuit principle diagram of an identification circuit in an embodiment of an adaptive RS232 and RS485 interface circuit.
[0037] Figure 5 The invention discloses a circuit principle diagram of an RS232 connection mode in an embodiment of an adaptive RS232 and RS485 interface circuit.
[0038] Figure 6 The invention discloses a circuit principle diagram of an RS485 connection mode in an embodiment of an adaptive RS232 and RS485 interface circuit.
[0039] Figure 7It is a schematic diagram of the voltage range of RS232-RXD / RS485-B when all combinations of communication interface types appearing with external devices in an embodiment of an adaptive RS232 and RS485 interface circuit of the present invention.
[0040] Figure 8 The present invention discloses an RS485-RS232 simulation waveform diagram of an identification circuit in an embodiment of an adaptive RS232 and RS485 interface circuit.
[0041] Fig. 9 The present invention discloses an RS232-RS485 simulation waveform diagram of an identification circuit in an embodiment of an adaptive RS232 and RS485 interface circuit. DETAILED DESCRIPTION
[0042] In order to make the purpose, technical solution and advantages of the embodiment of the present invention clearer, the technical solution of the embodiment of the present invention will be clearly and completely described below in conjunction with the drawings of the embodiment of the present invention. Obviously, the described embodiment is a part of the embodiment of the present invention, not all of the embodiments. Based on the described embodiment of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0043] See also Figures 1 to 3 The present embodiment provides an adaptive RS232 and RS485 interface circuit, comprising: a connector, a communication switching module, an identification module, an active control selection module, an RS232 interface communication module, an RS485 interface communication module, and a logic control circuit. The connector is arranged at a physical interface for accessing an external communication device. The identification module is connected to the connector and is used to identify the physical interface type of the external communication device, and control the communication switching module to switch the interface communication module according to the identification result. The communication switching module is respectively connected to the RS232 interface communication module and the RS485 interface communication module, and uses an analog switch to select the channel to complete the automatic switching of RS232 or RS485 communication mode. The active control selection module is respectively connected to the communication switching module and the single-chip microcomputer module, and the communication switching module is controlled by a photoelectric coupler by outputting high and low levels of the single-chip microcomputer module. The logic control circuit is respectively connected to the RS232 interface communication module and the RS485 interface communication module using a logic and gate chip, and the output pin of the logic control circuit is connected to the single-chip microcomputer module.
[0044] It should be noted that the RS232 or RS485 communication module of this embodiment is a universal interface chip, namely, the RS232 interface chip U4 and the RS485 interface chip U2, which are used to convert the TTL level into the RS232 level or the RS485 level.
[0045] In this embodiment, the connector includes a three-wire RS232 or a two-wire RS485 standard interface, which is defined as RS485-A / RS232-TXD, RS485-B / RS232-RXD, and GND. It can be seen that the connector of this embodiment is a physical interface for communicating with other external devices. According to the interface type of the external device, a three-wire RS232 or a two-wire RS485 standard interface can be selected for wiring, and its terminals are defined as RS485-A / RS232-TXD, RS485-B / RS232-RXD, and GND. This embodiment reuses the communication lines of RS485 and RS232, saves the number of connectors, and reduces the area occupied by the connectors.
[0046] The communication switching module of this embodiment is a control element, which is used to select between the RS232 interface chip U4 and the RS485 interface chip U2, and completely separate the two interface chips, using the RS485 interface by default. Its manifestation is a double-pole double-throw relay or electronic switch. Specifically, the communication switching module includes an electronic switching switch U1, and the normally closed contacts NO1 and NO2 of the electronic switching switch U1 are respectively connected to the A and B pins of the RS485 interface chip U2; the normally open contacts NC1 and NC2 of the electronic switching switch U1 are respectively connected to the TXD and RXD pins of the RS232 interface chip U4; the common contacts COM1 and COM2 of the electronic switching switch U1 are connected to the output to communicate with external devices;
[0047] The electronic switch U1 has two switch control pins CTRL1 and CTRL2. When the level is high, the two COMs of the electronic switch U1 are connected to NO respectively; when the level is low, the two COMs of the electronic switch U1 are connected to NC respectively.
[0048] The function of the identification module of this embodiment is to identify the physical interface type of the external communication device. According to the identification result, if it is consistent with the current interface type of the local device, no action is taken. If it is inconsistent with the current interface type, then after a delay of a period of time, the communication switching module is controlled to switch the communication interface chip.
[0049] Specifically, the identification module includes a comparator U6, a delay control circuit, a reference voltage, a control circuit, and a differential-common mode conversion circuit. The in-phase input pin of the comparator U6 is connected to the reference voltage, the inverting input pin of the comparator U6 is connected to RS232-RXD / RS485-B, the output pin of the comparator U6 is connected to the delay control circuit, and the delay control circuit is connected to the control circuit. Among them, the setting of the delay time of this embodiment is mainly because the waveforms of the communication lines are both high and low. What we need is to be able to recognize the external level changes and communicate normally without changing the interface type when there is data, so a delay for a period of time is required. Of course, to prevent misjudgment and mistriggering due to external electromagnetic interference, which may lead to system failure, this delay time can be set through component configuration to meet different needs.
[0050] In this embodiment, the delay control circuit includes a resistor R14, a resistor R15, a diode D2, a capacitor C3, a resistor R16 and a transistor Q2. The first end of the resistor R14 is connected to the output pin of the comparator U6, the second end of the resistor R14 is connected to the first end of the resistor R15 and the positive electrode of the diode D2, the second end of the resistor R15 is connected to the negative electrode of the diode D2 and then to the first end of the resistor R16 and the first end of the capacitor C3, the second end of the capacitor C3 is grounded, the second end of the resistor R16 is connected to the base of the transistor Q2, and the collector of the transistor Q2 is connected to the communication switching module.
[0051] In this embodiment, the priority of the active selection module is higher than the priority of the automatic switching. In some cases, there is a need for remote maintenance, and the operation and maintenance tools will be used to configure the communication interface type of the DTU through remote communication. It is necessary for the MCU to directly control the communication switching module to define whether the local communication interface is adaptive or one of RS232 or RS485. The priority of the active control module in this embodiment is the highest. When the local communication interface is defined as RS232 or RS485, the identification module no longer controls the communication switching module.
[0052] Specifically, the active control module includes a photocoupler U7 and a photocoupler U8, the input pin of the photocoupler U7 is connected to RS485_TAG, the input pin of the photocoupler U8 is connected to RS232_TAG, the CTRL pin of the electronic switching switch U1 is connected between the output pin of the photocoupler U7 and the output pin of the photocoupler U8, a resistor R3 is connected to the COM1 pin of the electronic switching switch U1, and a resistor R7 is connected to the COM2 pin of the electronic switching switch U1, which are used to convert the differential level of RS485 into a common mode voltage.
[0053] In this embodiment, the UART port of the single-chip module is directional and needs to be connected to two interface chips at the same time. The sending pin (TXD) of the UART port of the single-chip module can be directly connected to the receiving pin (RXD) of the RS232 interface chip U4 and the RS485 interface chip U2. However, the sending pins of the two interface chips need to be operated with a logic "AND" before they can be connected to the receiving pin (RXD) of the UART port of the single-chip. This can be achieved by using a logic control circuit or two switching diodes.
[0054] Preferably, a digital isolator U3 is connected between the logic control circuit and the single-chip microcomputer module.
[0055] In actual applications, industrial RS232 communication implements full-duplex serial communication and point-to-point transmission, which requires three wires for physical connection, namely, transmit (TXD), receive (RXD), and ground (GND). The level of logic "1" is specified to be -5V to -15V, and the level of logic "0" is -5V to -15V, but in fact the maximum range that the receiver can recognize is -3V to -15V, -3V to -15V.
[0056] Industrial RS485 communication implements half-duplex, multi-point transmission, requiring two wires for physical connection, namely A and B, and performing differential transmission. It is stipulated that the voltage between AB is +2V~+6V to represent logic "1", and the voltage between AB is -2V~-6V to represent logic "0".
[0057] In this embodiment, two communication modes are distinguished: first, it is necessary to find the characteristics of the typical differences between the two, and then ensure that the level signal sent by the circuit of this embodiment will not interfere with the detection result. Therefore, this embodiment relies on detecting the signal receiving end of the local machine to perform single-ended detection.
[0058] Because RS232 is three wires, the working grounds of the communication parts of the two communicating devices are connected, so the two working grounds are at the same potential, such as Figure 5 As shown, the voltage value of TXD and RXD to the ground can be directly detected; RS485 is a differential signal, and the two working grounds are not equipotential, such as Figure 6 As shown, the two input data lines need to be grounded through two resistors, so that the differential voltage of RS485 can be converted into a common-mode voltage to the ground. For the circuit of this embodiment, if the external interface is RS485, the voltage of RS485-B / RS232-RXD to the ground is half of the AB voltage, that is, ±1 to ±3V.
[0059] like Figure 7As shown, the voltage range of RS232-RXD / RS485-B when all combinations of the interface circuit of this embodiment and the communication interface types that may appear in the external device are listed. From this, a conclusion can be drawn: no matter what communication interface state the local device is currently in, the level of RS232-RXD / RS485-B will fall within the range of -3 to -15V only when the external device interface is RS232.
[0060] Therefore, as long as the level of RS232-RXD / RS485-B is continuously less than -3V for a period of time, it can be determined that the external connection is the RS232 interface; but when the level of RS232-RXD / RS485-B is higher than -3V, it may be because RS232 sent a logic "1", not necessarily the interface converted to RS485, so delayed debouncing processing is required. In actual applications, there will not be frequent switching of communication interfaces, and the timeliness requirements are not so high. In order to minimize the misjudgment caused by external EMC interference and other factors, this recognition time can be set to milliseconds.
[0061] The communication switching module of this embodiment uses an electronic switching switch U1 as a switching element. Compared with relays, it has a fast response time, small size and long life. It has two sets of conversion contacts. Because the system uses RS485 by default, the normally closed contacts (NO1, NO2) of the electronic switching switch U1 are respectively connected to the A and B pins of the RS485 interface chip U2; the normally open contacts (NC1, NC2) of the electronic switching switch U1 are connected to the TXD and RXD pins of the RS232 interface chip U4; the common contacts (COM1, COM2) of the electronic switching switch U1 are connected to the output to communicate with external devices.
[0062] The electronic switch U1 has two switching control pins CTRL1 and CTRL2. When the level is high, the two COMs are connected to NO; when the level is low, the two COMs are connected to NC, thereby obtaining the following logical relationship, as shown in Table (1):
[0063] CTRL1 COM1 CTRL1 COM2 Interface Type H NO1 H NO2 RS485 L NC1 L NC2 RS232 (1)
[0065] like Figure 7 As shown, when the voltage of RS232-RXD / RS485-B is greater than -A value, the output pin of comparator U6 outputs -B value, and when the voltage of RS232-RXD / RS485-B is less than -A, the output pin of comparator U6 outputs +B value;
[0066] Therefore, the positive and negative values of the output pin of comparator U6 are used to express whether the voltage of RS232-RXD / RS485-B is less than -AV, providing a basis for the next step of signal processing.
[0067] When the output pin of the comparator U6 outputs the +B value, the capacitor C3 is charged. Since the diode D2 is connected in parallel with the resistor R16, the diode D2 is forward-conducted at this time, and the charging constant of the capacitor C3 is expressed as formula (1):
[0068] t1=R14×C3 (1)
[0069] The voltage of capacitor C3 begins to rise. When the voltage across capacitor C3 exceeds the voltage of the B pole of transistor Q2, the C and E poles of transistor Q2 are gradually turned on. When formula (2) is satisfied, transistor Q2 is completely saturated and the C pole is grounded, which causes the CTRL1 and CTRL2 pins of the electronic switch U1 to be grounded through the seventh resistor. The electronic switch U1 switches the communication interface from RS485 to RS232:
[0070]
[0071] When the output pin of the comparator U6 outputs a -B value, the capacitor C3 is discharged through the resistors R14 and R15, so the discharge constant of the capacitor C3 is expressed as formula (3):
[0072] t2= (R14+R15) × C3 (3)
[0073] The voltage of capacitor C3 begins to drop, and the base current flowing through transistor Q2 begins to decrease. Since the voltage of the CTRL pin of the electronic switch U1 is greater than 1.4V, it is considered to be a high level. Therefore, when formula (4) is satisfied, the electronic switch U1 switches the communication interface from RS232 to RS485:
[0074]
[0075] In this embodiment, the A value is 3V and the B value is 12V.
[0076] In a specific application, for the identification module of this embodiment:
[0077] The RS232-TXD / RS485-A and RS232-RXD / RS485-B of the external device interface are respectively connected to the ground with a pull-down resistor R3 and R7. The comparator U6 is powered by ±12V and compares the voltage of RS232-RXD / RS485-B with the reference voltage -3V. The in-phase input terminal of the comparator U6 is connected to the reference voltage -3V, and its inverting input terminal is connected to RS232-RXD / RS485-B. When the voltage of RS232-RXD / RS485-B is greater than -3V, the output pin 1 of the comparator U6 outputs -12V. On the contrary, when this voltage is less than -3V, the output pin 1 of the comparator U6 outputs +12V. Therefore, the positive and negative of the output pin of U1 can be used to express whether the voltage of RS232-RXD / RS485-B is less than -3V, providing a basis for the next step of signal processing.
[0078] For the steady-state level: R14, R15, D2, C3, R16, and Q2 form a delay control circuit. When the pin 1 of the comparator U6 outputs +12V, the capacitor C3 is charged through R14-|D2 / R15|. Since the diode D2 is connected in parallel with the resistor R15, the diode D2 is forward-conducted at this time, so the charging constant of the capacitor C3 is approximately the above formula (1).
[0079] Then, the voltage of capacitor C3 starts to rise. When the voltage across capacitor C3 exceeds the voltage of transistor Q2's B pole by 0.7V, transistor Q2's CE pole gradually turns on. When the following conditions are met, transistor Q2 is fully saturated and C pole is approximately grounded, which causes the CTRL1 and CTRL2 pins of the electronic switch U1 to be grounded through resistor R5. The electronic switch U1 switches the local communication interface from RS485 to RS232, as shown in the above formula (2).
[0080] When the pin 1 of the electronic switch U1 outputs -12V, the capacitor C3 is discharged through the resistors R4 and R5, so the discharge constant of the capacitor C3 is approximately the above formula (3).
[0081] The voltage of capacitor C3 begins to drop, and the base current flowing through transistor Q2 begins to decrease. Since the voltage of the CTRL pin of the electronic switch U1 is greater than 1.4V, it is considered to be a high level. Therefore, when the following conditions are met, the electronic switch U1 switches the communication interface of the machine from RS232 to RS485, as shown in the above formula (4):
[0082] In fact, RS232 is a steady-state level only when there is no data. When there is data transmission, the data line is in a state of changing positive and negative voltages, and the distribution range of high and low levels is different depending on the data being sent. If the charge and discharge time of the RC delay is consistent, then when the high-level duty cycle of the data line is greater than 50%, the circuit can never switch to the RS232 interface, and even if it has switched to the RS232 state, it will slowly switch back to the RS485 interface.
[0083] Therefore, in the circuit of this embodiment, R14, R15, D2, and C3 form an unbalanced charge and discharge RC circuit design, where R15>R14. During charging, R15 is bypassed by D2. According to formula (1) and formula (3), t2>t1, thereby ensuring reliable operation of the circuit. The simulation schematic diagram of the identification circuit of this embodiment is shown in FIG. Figure 4 shown.
[0084] RS485 and RS232 are simulated using 10KHz and 50% duty cycle. The simulation waveform is as follows: Figure 8 , Fig. 9 As shown in the figure, when the external device interface switches between RS485 and RS232, the time required is 80ms and 122ms respectively.
[0085] The active control module of this embodiment uses two photocouplers U7 and U8 as control elements, and uses the GPIO control pin of the MCU to control the high and low levels of RS485_TAG and RS232_TAG. Figure 1 In any case, the level priority of the photoelectric couplers U7 and U8 is always higher than the control of the transistor Q2 in the identification module. Once at least one of the photoelectric couplers U7 and U8 is in a valid state, the identification module is in an invalid state.
[0086] The high and low levels of RS485_TAG and RS232_TAG satisfy the following logical relationship, as shown in Table (2):
[0087] RS485_TAG RS232_TAG Interface Type H L RS232 H H Automatic identification L L RS232 L H RS485 (2)
[0089] In summary, the present invention can realize automatic identification and automatic switching of RS232 interface and RS485 interface; the connector of the present invention can be shared, and there is no need to use two groups of connectors. Compared with the traditional 485 port to 485 or 232 to 232, the present invention adopts a multiplexing design, that is, it can connect 232 or 485, saving the number of connectors and reducing the area occupied by the connector; the present invention can configure a fixed interface type or use automatic identification through a remote operation and maintenance tool, thereby improving the automation level of the power system; the present invention can realize hot plug and play and non-stop operation when replacing external equipment, and there is no need to disassemble the equipment, further reducing technical and management risks; the RS232 and RS485 of the present invention share one group of CPU resources, which can reduce the CPU resource occupation and save CPU pin resources; all components of the present invention are independently controllable, do not rely on imports, do not need some additional relatively expensive special chips, can well control costs, the cost is relatively low, reduce system complexity, eliminate co-line interference, meet customers' flexible configuration needs, and provide guarantee for the construction of smart grids.
[0090] It should be understood that the embodiments described above are only illustrative. The embodiments described in this embodiment can be implemented in hardware, software, firmware, middleware, microcode or any combination thereof. For hardware implementation, the processing unit can be implemented in one or more application-specific integrated circuits (ASICs), digital signal processors (DSPs), digital signal processing devices (DSPDs), programmable logic devices (PLDs), field programmable gate arrays (FPGAs), processors, controllers, microcontrollers, microprocessors and / or other electronic units designed to perform the functions herein or combinations thereof.
[0091] The above-mentioned embodiments are only preferred embodiments of the present invention and cannot be used to limit the scope of protection of the present invention. Any non-substantial changes and substitutions made by technicians in this field on the basis of the present invention shall fall within the scope of protection required by the present invention.
Claims
1. An adaptive RS232 and RS485 interface circuit, characterized in that: include: A connector, a communication switching module, an identification module, an active control selection module, an RS232 interface communication module, an RS485 interface communication module, and a logic control circuit. The connector is arranged at a physical interface for accessing an external communication device. The identification module is connected to the connector and is used to identify the physical interface type of the external communication device, and control the communication switching module to switch the interface communication module according to the identification result. The communication switching module is respectively connected to the RS232 interface communication module and the RS485 interface communication module, and uses an analog switch to select a channel to complete the automatic switching of the RS232 or RS485 communication mode. The active control selection module is respectively connected to the communication switching module and the single-chip microcomputer module, and controls the communication switching module through a photoelectric coupler by outputting high and low levels of the single-chip microcomputer module. The logic control circuit is respectively connected to the RS232 interface communication module and the RS485 interface communication module using a logic and gate chip, and the output pin of the logic control circuit is connected to the single-chip microcomputer module. The identification module includes a comparator, a delay control circuit, a reference voltage, a control circuit, and a differential-common mode conversion circuit, wherein the in-phase input pin of the comparator is connected to the reference voltage, the inverting input pin of the comparator is connected to RS232-RXD / RS485-B, the output pin of the comparator is connected to the delay control circuit, and the delay control circuit is connected to the control circuit; The terminals of the connector include a three-wire RS232 or a two-wire RS485 standard interface, which is defined as RS485-A / RS232-TXD, RS485-B / RS232-RXD, and GND; The delay control circuit includes a resistor R14, a resistor R15, a diode D2, a capacitor C3, a resistor R16 and a transistor Q2, wherein the first end of the resistor R14 is connected to the output pin of the comparator, the second end of the resistor R14 is connected to the first end of the resistor R15 and the positive electrode of the diode D2, the second end of the resistor R15 is connected to the negative electrode of the diode D2 and then to the first end of the resistor R16 and the first end of the capacitor C3, the second end of the resistor R16 is connected to the base of the transistor Q2, and the collector of the transistor Q2 is connected to the communication switching module; The priority of the active control selection module is higher than the priority of the automatic switching.
2. The circuit according to claim 1, characterized in that: The communication switching module includes an electronic switching switch, the normally closed contacts NO1 and NO2 of the electronic switching switch are respectively connected to the A and B pins of the RS485 interface communication module; the normally open contacts NC1 and NC2 of the electronic switching switch are respectively connected to the TXD and RXD pins of the RS232 interface communication module; the common contacts COM1 and COM2 of the electronic switching switch are connected to the output to communicate with the external device; The electronic switch has two switch control pins CTRL1 and CTRL2. When the level is high, the two COMs of the electronic switch are connected to NO respectively; when the level is low, the two COMs of the electronic switch are connected to NC respectively.
3. The circuit according to claim 2, characterized in that: The active control selection module includes a first photocoupler and a second photocoupler, the input pin of the first photocoupler is connected to RS485_TAG, the input pin of the second photocoupler is connected to RS232_TAG, the CTRL pin of the electronic switching switch is connected between the output pin of the first photocoupler and the output pin of the second photocoupler, a resistor R3 is connected to the COM1 pin of the electronic switching switch, and a resistor R7 is connected to the COM2 pin of the electronic switching switch, which are used to convert the differential level of RS485 into a common mode voltage.
4. The circuit according to claim 1, characterized in that: When the voltage of RS232-RXD / RS485-B is greater than -A value, the output pin of the comparator outputs -B value at this time; when the voltage of RS232-RXD / RS485-B is less than -A, the output pin of the comparator outputs +B value at this time; Therefore, the positive or negative value of the output pin of the comparator is used to express whether the voltage of RS232-RXD / RS485-B is less than -AV, which provides a basis for the next step of signal processing.
5. The circuit according to claim 4, characterized in that: When the output pin of the comparator outputs a +B value, the capacitor C3 is charged. Since the diode D2 is connected in parallel with the resistor R16, the diode D2 is forward-conducted at this time, and the charging constant of the capacitor C3 is expressed as formula (1): (1) The voltage of capacitor C3 begins to rise. When the voltage across capacitor C3 exceeds the voltage of the B pole of transistor Q2, the C and E poles of transistor Q2 gradually turn on. When formula (2) is satisfied, transistor Q2 is completely saturated and the C pole is approximately grounded, which causes the CTRL1 and CTRL2 pins of the electronic switch to be grounded through the seventh resistor. The electronic switch switches the communication interface from RS485 to RS232: (2) 6. The circuit according to claim 5, characterized in that: When the output pin of the comparator outputs the -B value, the capacitor voltage is higher than the comparator output voltage, and the capacitor C3 is discharged through the resistors R14 and R15. Therefore, the discharge constant of the capacitor C3 is expressed as formula (3): The voltage of capacitor C3 begins to drop, and the base current flowing through transistor Q2 begins to decrease. Since the voltage of the CTRL pin of the electronic switch is considered to be high when it is greater than 1.4V, when formula (4) is satisfied, the electronic switch switches the communication interface from RS232 to RS485: (4)。
Citation Information
Patent Citations
Data gathering and liquid crystal display device
CN101149599A
Communication interface conversion circuit
CN211319205U
Cited By
Automatic identification and expansion communication method based on RS485 interface
CN120371755A