RS232 and RS485 switching circuit shared by source end and interface end
By designing a shared RS232 and RS485 switching circuit, the problem of limited MCU resources and space for RS232 and RS485 interfaces was solved, realizing the sharing of communication methods and mutual non-interference, improving resource utilization and saving costs.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Utility models(China)
- Current Assignee / Owner
- JIANGSU JIAQING INFORMATION TECH CO LTD
- Filing Date
- 2025-07-22
- Publication Date
- 2026-05-05
AI Technical Summary
In existing technologies, RS232 and RS485 interfaces cause mutual interference in industrial and electronic fields due to differences in voltage and signal definitions, resulting in insufficient allocation of MCU resources and tight structural space, thus increasing project costs.
Design an RS232 and RS485 switching circuit that is shared by the source and interface ends, including an isolation module, an RS232-RS485 communication module, a logic module and a communication switching module. Signal isolation and switching are achieved through isolators and logic chips, while sharing MCU resources.
It achieves the sharing of RS232 and RS485 communication methods, avoids mutual interference, improves MCU resource utilization, and saves structural space and project costs.
Smart Images

Figure CN224203689U_ABST
Abstract
Description
Technical Field
[0001] This utility model relates to the field of interface communication technology, specifically to an RS232 and RS485 switching circuit shared by the source end and the interface end. Background Technology
[0002] RS485 and RS232 are two widely used communication interfaces in the industrial and electronic fields. RS485 is half-duplex differential, using multi-node communication and differential signal output, supporting long-distance multi-point communication; RS232 is full-duplex single-ended, suitable for short-distance point-to-point communication. However, due to the different voltage and signal definitions of the two interfaces, they can interfere with each other. Therefore, most industrial control products are designed with RS232 and RS485 separately, meaning they are designed with either RS232 or RS485 interfaces according to the manufacturer's wishes. However, with increasingly tight MCU resource allocation and structural space, this design becomes a burden. It requires two sets of UARTs at the MCU source end, and each communication output end also needs its own corresponding interface. This not only fails to effectively utilize MCU resources and increases project costs, but also makes it impossible to configure both functions simultaneously under tight structural space. Utility Model Content
[0003] To address the aforementioned issues, this invention provides an RS232 and RS485 switching circuit that shares both the source and interface ends. This circuit allows both RS232 and RS485 communication methods to share the source and interface ends when both are required to function simultaneously. This not only improves MCU resource utilization and saves structural space but also reduces project costs.
[0004] This utility model adopts the following technical solution: an RS232 and RS485 switching circuit shared by the source end and the interface end, comprising:
[0005] An isolation module, connected to a microcontroller (MCU), is used to achieve digital signal isolation.
[0006] An RS232-RS485 communication module is used to implement RS232 and RS485 communication.
[0007] A logic module is connected between the isolation module and the RS232-RS485 communication module to realize RS485 signal transmission and reception;
[0008] The communication switching module is connected to the microcontroller MCU, the RS232-RS485 communication module, and the output module. It is used to realize RS232 or RS485 communication based on the output of the microcontroller MCU and output the data through the output module.
[0009] Further, the isolation module includes an isolator U1, resistors R1 to R4, and capacitors C1 to C2. The isolator U1 uses an NSi8121N1 digital isolation chip. Pin 1 of the isolator U1 is connected to one end of resistors R1, R2, and C2 and then connected to the system voltage of 3.3V. Pin 2 of the isolator U1 is connected to the other end of resistor R2 and then connected to the microcontroller MCU via the UART_RX port. Pin 3 of the isolator U1 is connected to the other end of resistor R1 and then connected to the microcontroller MCU via the UART_TX port. Pin 4 of the isolator U1 is connected to the other end of capacitor C2 and then grounded. Pin 8 of the isolator U1 is connected to one end of capacitor C1 and then connected to the power supply voltage of 5V. Pin 5 of the isolator U1 is connected to the other end of capacitor C1 and then grounded. Pin 7 of the isolator U1 is connected to one end of resistor R4. Pin 6 of the isolator U1 is connected to one end of resistor R3.
[0010] Furthermore, the logic module includes a NOT gate U2, resistors R5 to R6, and a capacitor C3. The NOT gate U2 uses an SGM7SZ00YC5G logic chip. One end of resistor R5 is connected to the other end of resistor R3, and the other end of resistor R5 is connected to pins 1 and 2 of the NOT gate U2. One end of capacitor C3 is connected to pin 3 of the NOT gate U2 and then grounded. The other end of capacitor C3 is connected to pin 5 of the NOT gate U2 and then connected to a 5V power supply. Pin 4 of the NOT gate U2 is connected to one end of resistor R6.
[0011] Furthermore, the RS232-RS485 communication module includes an RS232 transceiver U3, an RS485 transceiver U4, capacitors C4-C9, resistors R7-R12, and TVS diodes D1-D4. The RS232 transceiver U3 uses a TI_MAX3232IPW chip, and the RS485 transceiver U4 uses an SN65HVD3082EDR chip. The other end of resistor R6 is connected to pins 2 and 3 of the RS485 transceiver U4, and the other end of resistor R3 is connected to... Pin 4 of the RS485 transceiver U4 and pin 1 of the RS485 transceiver U4 are connected to a 5V power supply via resistor R7. Pin 8 of the RS485 transceiver U4 is connected to one end of capacitor C9 and one end of resistor R8, and is also connected to a 5V power supply. The other end of capacitor C9 is grounded. Pin 7 of the RS485 transceiver U4 is connected to one end of resistors R9, R10, and R11, and one end of TVS diode D4. Pin 6 of the RS485 transceiver U4 is connected to the other end of resistors R8 and R9. One end of resistor R12 and one end of TVS diode D3 are connected together. Pin 5 of RS485 transceiver U4 is connected to the other end of resistor R10 and the other ends of TVS diodes D3 and D4, and then grounded. Capacitor C4 is connected between pins 1 and 3 of RS232 transceiver U3. Pin 2 of RS232 transceiver U3 is grounded after being connected to capacitor C5. Capacitor C6 is connected between pins 4 and 5 of RS232 transceiver U3. Pin 6 of RS232 transceiver U3 is grounded after being connected to capacitor C7. The RS232 transceiver U3 is connected to ground. Pin 16 is connected to one end of capacitor C13 and then to a 5V power supply. Pin 15 of the RS232 transceiver U3 is connected to the other end of capacitor C13 and one end of TVS diodes D1 and D2 and then to ground. Pin 14 of the RS232 transceiver U3 is connected to the other end of TVS diode D2. Pin 13 of the RS232 transceiver U3 is connected to the other end of TVS diode D1. Pin 11 of the RS232 transceiver U3 is connected to the other end of resistor R3.
[0012] Furthermore, the communication switching module includes an optocoupler U5, relays RL1 and RL2, resistors R13 to R23, transistors Q1 to Q2, Zener diodes D5 and D6; the output module includes an interface CN1. The optocoupler U5 uses a 6N137S-TA1-L chip. Pin 3 of the optocoupler U5 is connected to one end of resistors R13 and R14, and then connected to the microcontroller MCU via port F00_EN. The other end of resistor R14 is grounded. Pin 2 of the optocoupler U5 is connected to one end of resistor R15, and the other end of resistor R13 is connected to resistor R1... The other end of pin 5 is connected to the system voltage of 3.3V. Pin 8 of optocoupler U5 is connected to one end of resistors R16 and R17, which is then connected to the supply voltage of 5V. Pin 7 of optocoupler U5 is connected to the other end of resistor R16. Pin 6 of optocoupler U5 is connected to the other end of resistor R17, and one end of resistors R18 and R19. The other end of resistor R19 is grounded. The other end of resistor R18 is connected to the base of transistor Q1. The emitter of transistor Q1 is grounded. The collector of transistor Q1 is connected to the positive terminal of Zener diode D5 and pin 12 of relay RL1. All pins are connected. Pin 1 of relay RL1 is connected to the negative terminal of Zener diode D5 and then to a 5V power supply. Pins 9 and 4 of relay RL1 are connected to pins 1 and 2 of interface CN1, respectively. Pins 10 and 3 of relay RL1 are connected to pins 14 and 13 of RS232 transceiver U3, respectively. Pins 8 and 5 of relay RL1 are connected to the other ends of resistors R12 and R11, respectively. One end of resistor R20 is connected to pin 6 of optocoupler U5, and the other end of resistor R20 is connected to the base of transistor Q2. The emitter of transistor Q2... The transistor Q2 is grounded. The collector of the transistor Q2 is connected to the positive terminal of the Zener diode D6 and pin 12 of the relay RL2. The negative terminal of the Zener diode D6 is connected to pin 1 of the relay RL2 and then connected to the 5V power supply. Pins 3, 4, and 5 of the relay RL2 are connected to one end of resistors R21, R22, and R23, respectively. The other end of resistor R21 is connected to pin 12 of the RS232 transceiver U3. The other end of resistor R22 is connected to the other end of resistor R4. The other end of resistor R23 is connected to pin 1 of the RS485 transceiver U4.
[0013] Furthermore, the switching circuit also includes a voltage isolation circuit, which is connected to the isolation module, logic module, RS232-RS485 communication module, and communication switching module to provide power. The voltage isolation circuit includes an isolation power supply module U6 and capacitors C10 to C16. The isolation power supply module U6 uses a chip of model F0505S-1WR3. Pin 1 of the isolation power supply module U6 is connected to one end of capacitors C10, C11, and C12 and then connected to a power supply voltage of 5V. Pin 2 of the isolation power supply module U6 is connected to the other end of capacitors C10, C11, and C12 and one end of capacitor C13 and then grounded. Pin 7 of the isolation power supply module U6 is connected to one end of capacitors C14, C15, and C16. Pin 5 of the isolation power supply module U6 is connected to the other end of capacitors C13, C14, C15, and C16 and then grounded.
[0014] The beneficial effects of this utility model are that, through the setting of isolation module, logic module, RS232-RS485 communication module, and communication switching module, it can realize the switching between RS232 and RS485 communication modes. When there is a need for both RS232 and RS485 communication, it allows the two communication modes to share the source end and interface end, which not only avoids mutual interference, but also improves the utilization rate of MCU resources, saves structural space, and reduces project costs, thus having good application value. Attached Figure Description
[0015] Figure 1 This is a structural block diagram of the present invention;
[0016] Figure 2 This is the circuit schematic diagram of the isolation module in this utility model;
[0017] Figure 3 This is a schematic diagram of the connection circuit between the logic module and the RS232-RS485 communication module in this utility model;
[0018] Figure 4 This is a circuit diagram of the communication switching module in this utility model;
[0019] Figure 5 This is the circuit diagram of the voltage isolation module in this utility model. Detailed Implementation
[0020] like Figures 1-5 As shown, this utility model provides an RS232 and RS485 switching circuit that shares a source and interface, comprising:
[0021] An isolation module, connected to a microcontroller (MCU), is used to achieve digital signal isolation.
[0022] An RS232-RS485 communication module is used to implement RS232 and RS485 communication.
[0023] The logic module is connected between the isolation module and the RS232-RS485 communication module to enable RS485 signal transmission and reception.
[0024] The communication switching module is connected to the microcontroller (MCU), the RS232-RS485 communication module, and the output module. It is used to realize RS232 or RS485 communication based on the output of the MCU and output it through the output module.
[0025] The isolation module includes isolator U1, resistors R1 to R4, and capacitors C1 to C2. Isolator U1 uses an NSi8121N1 digital isolation chip. Pin 1 of isolator U1 is connected to one end of resistors R1 and R2, and capacitor C2, and then connected to the system voltage of 3.3V. Pin 2 of isolator U1 is connected to the other end of resistor R2 and then connected to the microcontroller MCU via the UART_RX port. Pin 3 of isolator U1 is connected to the other end of resistor R1 and then connected to the microcontroller MCU via the UART_TX port. Pin 4 of isolator U1 is connected to the other end of capacitor C2 and then grounded. Pin 8 of isolator U1 is connected to one end of capacitor C1 and then connected to the power supply voltage of 5V. Pin 5 of isolator U1 is connected to the other end of capacitor C1 and then grounded. Pin 7 of isolator U1 is connected to one end of resistor R4, and pin 6 of isolator U1 is connected to one end of resistor R3.
[0026] The logic module includes NOT gate U2, resistors R5-R6, and capacitor C3. NOT gate U2 uses the SGM7SZ00YC5G logic chip. One end of resistor R5 is connected to the other end of resistor R3. The other end of resistor R5 is connected to pins 1 and 2 of NOT gate U2. One end of capacitor C3 is connected to pin 3 of NOT gate U2 and then grounded. The other end of capacitor C3 is connected to pin 5 of NOT gate U2 and then connected to the 5V power supply voltage. Pin 4 of NOT gate U2 is connected to one end of resistor R6.
[0027] The RS232-RS485 communication module includes an RS232 transceiver U3, an RS485 transceiver U4, capacitors C4-C9, resistors R7-R12, and TVS diodes D1-D4. The RS232 transceiver U3 uses a TI_MAX3232IPW chip, and the RS485 transceiver U4 uses an SN65HVD3082EDR chip. The other end of resistor R6 is connected to pins 2 and 3 of the RS485 transceiver U4. The other end of resistor R3... The terminal is connected to pin 4 of RS485 transceiver U4. Pin 1 of RS485 transceiver U4 is connected to the 5V supply voltage via resistor R7. Pin 8 of RS485 transceiver U4 is connected to one end of capacitor C9 and one end of resistor R8, and then connected to the 5V supply voltage. The other end of capacitor C9 is grounded. Pin 7 of RS485 transceiver U4 is connected to one end of resistors R9, R10, and R11, and one end of TVS diode D4. Pin 6 of RS485 transceiver U4 is connected to resistors R8 and R9... The other end, one end of resistor R12, and one end of TVS diode D3 are all connected. Pin 5 of RS485 transceiver U4 is connected to the other end of resistor R10, and the other ends of TVS diodes D3 and D4, and then grounded. Capacitor C4 is connected between pins 1 and 3 of RS232 transceiver U3. Pin 2 of RS232 transceiver U3 is grounded after connecting capacitor C5. Capacitor C6 is connected between pins 4 and 5 of RS232 transceiver U3. Pin 6 of RS232 transceiver U3 is grounded after connecting capacitor C7. The RS232 transceiver U3 is grounded. Pin 16 of the RS232 transceiver U3 is connected to one end of capacitor C13 and then to the 5V power supply. Pin 15 of the RS232 transceiver U3 is connected to the other end of capacitor C13 and one end of TVS diodes D1 and D2 and then grounded. Pin 14 of the RS232 transceiver U3 is connected to the other end of TVS diode D2. Pin 13 of the RS232 transceiver U3 is connected to the other end of TVS diode D1. Pin 11 of the RS232 transceiver U3 is connected to the other end of resistor R3.
[0028] The communication switching module includes optocoupler U5, relays RL1 and RL2, resistors R13 to R23, transistors Q1 and Q2, Zener diodes D5 and D6; the output module includes interface CN1, which is shared by RS232 and RS485 communication modes; optocoupler U5 uses a 6N137S-TA1-L chip, pin 3 of optocoupler U5 is connected to one end of resistors R13 and R14, and then connected to the microcontroller MCU via port F00_EN, the other end of resistor R14 is grounded, and pin 2 of optocoupler U5 is connected to resistor R1... One end of resistor R5 is connected to the system voltage of 3.3V. The other end of resistor R13 is connected to the other end of resistor R15, and then connected to the power supply voltage of 5V. Pin 8 of optocoupler U5 is connected to one end of resistors R16 and R17, and then connected to the power supply voltage of 5V. Pin 7 of optocoupler U5 is connected to the other end of resistor R16. Pin 6 of optocoupler U5 is connected to the other end of resistor R17, and one end of resistors R18 and R19. The other end of resistor R19 is grounded. The other end of resistor R18 is connected to the base of transistor Q1. The emitter of transistor Q1 is grounded. The collector of transistor Q1 is connected to the Zener diode. The positive terminal of D5 and pin 12 of relay RL1 are connected together. Pin 1 of relay RL1 is connected to the negative terminal of Zener diode D5 and then connected to a 5V power supply. Pins 9 and 4 of relay RL1 are connected to pins 1 and 2 of interface CN1, respectively. Pins 10 and 3 of relay RL1 are connected to pins 14 and 13 of RS232 transceiver U3, respectively. Pins 8 and 5 of relay RL1 are connected to the other ends of resistors R12 and R11, respectively. One end of resistor R20 is connected to pin 6 of optocoupler U5, and the other end of resistor R20 is connected to the base of transistor Q2. The emitter of transistor Q2 is grounded. The collector of transistor Q2 is connected to the positive terminal of Zener diode D6 and pin 12 of relay RL2. The negative terminal of Zener diode D6 is connected to pin 1 of relay RL2 and then connected to the 5V power supply. Pins 3, 4, and 5 of relay RL2 are connected to one end of resistors R21, R22, and R23 respectively. The other end of resistor R21 is connected to pin 12 of RS232 transceiver U3. The other end of resistor R22 is connected to the other end of resistor R4. The other end of resistor R23 is connected to pin 1 of RS485 transceiver U4.
[0029] The switching circuit also includes a voltage isolation circuit, which is connected to the isolation module, logic module, RS232-RS485 communication module, and communication switching module to provide power. The voltage isolation circuit includes an isolation power supply module U6 and capacitors C10 to C16. The isolation power supply module U6 uses a chip of model F0505S-1WR3. Pin 1 of the isolation power supply module U6 is connected to one end of capacitors C10, C11, and C12 and then connected to the 5V power supply voltage. Pin 2 of the isolation power supply module U6 is connected to the other end of capacitors C10, C11, and C12 and one end of capacitor C13 and then grounded. Pin 7 of the isolation power supply module U6 is connected to one end of capacitors C14, C15, and C16. That is, the 5V power supply voltage in the isolation module, logic module, RS232-RS485 communication module, and communication switching module is provided by the RS232_5V terminal of the voltage isolation circuit. Pin 5 of the isolation power supply module U6 is connected to the other end of capacitors C13, C14, C15, and C16 and then grounded.
[0030] This invention uses the control signal (i.e., port F00_EN) output by a microcontroller MCU to control relays RL1 and RL2 in the communication switching module, thereby switching between RS232 and RS485 communication modes. Both relays RL1 and RL2 are double-pole double-throw monostable HFD3 / 5. Specifically, the network signals (i.e., UART_TX and UART_RX) output by the microcontroller MCU are converted into signals TX and RX using an isolation chip NSi8121N1 to isolate interference. When the microcontroller MCU sends a signal, signal TX is simultaneously connected to the input terminals of RS232 transceiver U3 and RS485 transceiver U4. Since RS485 transceiver U4 is in half-duplex communication mode, signal TX passes through NOT gate U2 and is controlled by control signal 485_DE to control the transmission and reception of RS485 transceiver U4.
[0031] The working principle for switching between RS232 and RS485 communication modes is as follows:
[0032] The signal at port F00_EN is isolated from interference by optocoupler U5 and then controls the relay accordingly. When the signal at port F00_EN is low, optocoupler U5 is turned on, and the secondary signal 485_232_EN of the optocoupler is low. Therefore, the transistor Q1 controlled by the secondary signal 485_232_EN of the optocoupler is not turned on, and the relay RL1 does not operate. Pins 3 and 10 of the relay RL1 (which are the normally closed contacts of the relay RL1) are connected to interface CN1 through pins 4 and 9 of the relay RL1. At this time, the external communication mode is RS232.
[0033] When the signal at port F00_EN is high, optocoupler U5 is not conducting, and the secondary signal 485_232_EN of the optocoupler is high. Then, the transistor Q1 controlled by the secondary signal 485_232_EN of the optocoupler is conducting, and then the relay RL1 is activated. Pins 5 and 8 of the relay RL1 (which are the normally open contacts of the relay RL1) are connected to interface CN1 through pins 4 and 9 of the relay RL1. At this time, the external communication mode is RS485.
[0034] The switching between RS232 and RS485 communication modes is shown in Table 1 below:
[0035] F00_EN 485_232_EN model L L RS232 H H RS485
[0036] In addition, after the communication method is determined, the corresponding communication signal also needs to be fed back to the microcontroller MCU. The MCU's receiving signal RX corresponds to the output terminal of RS232 transceiver U3 (i.e., 232_RX) and the output terminal of RS485 transceiver U4 (i.e., 485_RX). To prevent interference between signals 232_RX and 485_RX, signal RX is also connected to pin 4 of relay RL2 (i.e., common terminal COM1). The output terminal of RS232 transceiver U3 (i.e., 232_RX) is connected to pin 3 of relay RL2 (the normally closed contact terminal of relay RL2), and the output terminal of RS485 transceiver U4 (i.e., 485_RX) is connected to pin 5 of relay RL2 (the normally open contact terminal of relay RL2). The specific implementation principle is as follows:
[0037] When the signal at port F00 EN is low, optocoupler U5 is turned on, the secondary signal 485232EN of the optocoupler is low, the transistor Q2 controlled by the secondary signal 485_232_EN of the optocoupler is not turned on, the relay RL2 does not operate, the output terminal (i.e. 232_RX) of RS232 transceiver U3 is shorted to pin 4 of relay RL2, at this time the signal fed back to the microcontroller MCU is the signal sent by RS232 transceiver U3, thus achieving the purpose of providing the microcontroller MCU with the output signal of RS232 transceiver U3;
[0038] When the signal at port F00_EN is high, optocoupler U5 is not conducting, and the secondary signal 485_232_EN of the optocoupler is high. Then, the transistor Q2 controlled by the secondary signal 485_232_EN of the optocoupler is conducting, and then the relay RL2 is activated. The output terminal of RS485 transceiver U4 (i.e., 485_RX) and pin 4 of relay RL2 are shorted. At this time, the signal sent to the microcontroller MCU is the signal sent from RS485 transceiver U4, thus achieving the purpose of sending the output signal of RS485 transceiver U4 to the microcontroller MCU.
[0039] Feedback on RS232 and RS485 communication methods is shown in Table 2 below:
[0040] F00_EN 485_232_EN MCU receiver RX L L The RS232 chip's input 232_RX H H RS485 chip input 485_RX
[0041] In summary, ports UART_RX and UART_TX are the source terminals of the microcontroller (MCU), enabling signal transmission and reception. This patent achieves signal transmission and reception through the same set of ports. When implementing RS232 or RS485 communication, both are output through interface CN1. Thus, this patent satisfies the simultaneous requirements of RS232 and RS485, allowing both communication methods to share the source and interface terminals. This not only avoids mutual interference but also improves MCU resource utilization, saves structural space, and reduces project costs.
[0042] It will be apparent to those skilled in the art that this invention is not limited to the details of the exemplary embodiments described above, and that it can be implemented in other specific forms without departing from the spirit or essential characteristics of this invention. Therefore, the embodiments should be considered illustrative and non-limiting in all respects, and the scope of this invention is defined by the appended claims rather than the foregoing description. Thus, it is intended that all variations falling within the meaning and scope of equivalents of the claims be included within this invention. No reference numerals in the claims should be construed as limiting the scope of the claims.
[0043] Furthermore, it should be understood that although this specification describes embodiments, not every embodiment contains only one independent technical solution. This narrative style is merely for clarity. Those skilled in the art should consider the specification as a whole, and the technical solutions in each embodiment can also be appropriately combined to form other embodiments that can be understood by those skilled in the art.
Claims
1. A switching circuit for RS232 and RS485 shared by the source and interface ends, characterized in that: include: An isolation module, connected to a microcontroller (MCU), is used to achieve digital signal isolation. An RS232-RS485 communication module is used to implement RS232 and RS485 communication. A logic module is connected between the isolation module and the RS232-RS485 communication module to realize RS485 signal transmission and reception; The communication switching module is connected to the microcontroller MCU, the RS232-RS485 communication module, and the output module. It is used to realize RS232 or RS485 communication based on the output of the microcontroller MCU and output the data through the output module.
2. The RS232 and RS485 switching circuit shared by the source and interface ends according to claim 1, characterized in that: The isolation module includes an isolator U1, resistors R1 to R4, and capacitors C1 to C2. The isolator U1 uses an NSi8121N1 digital isolation chip. Pin 1 of the isolator U1 is connected to one end of each of resistors R1, R2, and C2 and then connected to the system voltage of 3.3V. Pin 2 of the isolator U1 is connected to the other end of resistor R2 and then connected to the microcontroller MCU via the UART_RX port. Pin 3 of the isolator U1 is connected to the other end of resistor R1 and then connected to the microcontroller MCU via the UART_TX port. Pin 4 of the isolator U1 is connected to the other end of capacitor C2 and then grounded. Pin 8 of the isolator U1 is connected to one end of capacitor C1 and then connected to the power supply voltage of 5V. Pin 5 of the isolator U1 is connected to the other end of capacitor C1 and then grounded. Pin 7 of the isolator U1 is connected to one end of resistor R4, and pin 6 of the isolator U1 is connected to one end of resistor R3.
3. The RS232 and RS485 switching circuit shared by the source and interface ends according to claim 2, characterized in that: The logic module includes a NOT gate U2, resistors R5-R6, and a capacitor C3. The NOT gate U2 uses an SGM7SZ00YC5G logic chip. One end of resistor R5 is connected to the other end of resistor R3. The other end of resistor R5 is connected to pins 1 and 2 of the NOT gate U2. One end of capacitor C3 is connected to pin 3 of the NOT gate U2 and then grounded. The other end of capacitor C3 is connected to pin 5 of the NOT gate U2 and then connected to a 5V power supply. Pin 4 of the NOT gate U2 is connected to one end of resistor R6.
4. The RS232 and RS485 switching circuit shared by the source and interface ends according to claim 3, characterized in that: The RS232-RS485 communication module includes an RS232 transceiver U3, an RS485 transceiver U4, capacitors C4-C9, resistors R7-R12, and TVS diodes D1-D4. The RS232 transceiver U3 uses a TI MAX3232IPW chip, and the RS485 transceiver U4 uses an SN65HVD3082EDR chip. One end of resistor R6 is connected to pins 2 and 3 of the RS485 transceiver U4, and the other end of resistor R3 is connected to pin 4 of the RS485 transceiver U4. Pin 1 of the RS485 transceiver U4 is connected to a 5V power supply via resistor R7. Pin 8 of the RS485 transceiver U4 is connected to capacitors C4-C9. One end of capacitor C9 and one end of resistor R8 are connected to a 5V power supply. The other end of capacitor C9 is grounded. Pin 7 of RS485 transceiver U4 is connected to one end of resistors R9, R10, and R11, and one end of TVS diode D4. Pin 6 of RS485 transceiver U4 is connected to the other ends of resistors R8 and R9, one end of resistor R12, and one end of TVS diode D3. Pin 5 of RS485 transceiver U4 is connected to resistor R... The other end of 10, and the other ends of TVS diodes D3 and D4 are all connected to ground; capacitor C4 is connected between pins 1 and 3 of RS232 transceiver U3; pin 2 of RS232 transceiver U3 is grounded after being connected to capacitor C5; capacitor C6 is connected between pins 4 and 5 of RS232 transceiver U3; pin 6 of RS232 transceiver U3 is grounded after being connected to capacitor C7; pin 16 of RS232 transceiver U3 is connected to capacitor C5. One end of C13 is connected to a 5V power supply. Pin 15 of the RS232 transceiver U3 is connected to the other end of capacitor C13 and one end of TVS diodes D1 and D2, and then grounded. Pin 14 of the RS232 transceiver U3 is connected to the other end of TVS diode D2. Pin 13 of the RS232 transceiver U3 is connected to the other end of TVS diode D1. Pin 11 of the RS232 transceiver U3 is connected to the other end of resistor R3.
5. The RS232 and RS485 switching circuit shared by the source and interface ends according to claim 4, characterized in that: The communication switching module includes an optocoupler U5, relays RL1 and RL2, resistors R13 to R23, transistors Q1 to Q2, Zener diodes D5 and D6; the output module includes an interface CN1. The optocoupler U5 uses a 6N137S-TA1-L chip. Pin 3 of the optocoupler U5 is connected to one end of resistors R13 and R14, and then connected to the microcontroller MCU via port F00_EN. The other end of resistor R14 is grounded. Pin 2 of the optocoupler U5 is connected to one end of resistor R15, and the other end of resistor R13 is connected to the other end of resistor R15. After the terminals are connected, the system voltage is 3.3V. Pin 8 of the optocoupler U5 is connected to one end of resistors R16 and R17, and then connected to the power supply voltage of 5V. Pin 7 of the optocoupler U5 is connected to the other end of resistor R16. Pin 6 of the optocoupler U5 is connected to the other end of resistor R17, and one end of resistors R18 and R19. The other end of resistor R19 is grounded. The other end of resistor R18 is connected to the base of transistor Q1. The emitter of transistor Q1 is grounded. The collector of transistor Q1 is connected to the positive terminal of Zener diode D5 and pin 12 of relay RL1. The relay RL1 is connected to the negative terminal of the Zener diode D5 and then to a 5V power supply. Pins 9 and 4 of the relay RL1 are connected to pins 1 and 2 of the interface CN1, respectively. Pins 10 and 3 of the relay RL1 are connected to pins 14 and 13 of the RS232 transceiver U3, respectively. Pins 8 and 5 of the relay RL1 are connected to the other ends of resistors R12 and R11, respectively. One end of resistor R20 is connected to pin 6 of the optocoupler U5, and the other end of resistor R20 is connected to the base of transistor Q2. The emitter of transistor Q2... The transistor Q2 is grounded. The collector of the transistor Q2 is connected to the positive terminal of the Zener diode D6 and pin 12 of the relay RL2. The negative terminal of the Zener diode D6 is connected to pin 1 of the relay RL2 and then connected to the power supply voltage of 5V. Pins 3, 4, and 5 of the relay RL2 are connected to one end of resistors R21, R22, and R23, respectively. The other end of resistor R21 is connected to pin 12 of the RS232 transceiver U3. The other end of resistor R22 is connected to the other end of resistor R4. The other end of resistor R23 is connected to pin 1 of the RS485 transceiver U4.
6. The RS232 and RS485 switching circuit shared by the source and interface ends according to claim 1, characterized in that: The switching circuit also includes a voltage isolation circuit, which is connected to the isolation module, logic module, RS232-RS485 communication module, and communication switching module to provide power. The voltage isolation circuit includes an isolation power supply module U6 and capacitors C10 to C16. The isolation power supply module U6 uses a chip of model F0505S-1WR3. Pin 1 of the isolation power supply module U6 is connected to one end of capacitors C10, C11, and C12 and then connected to a power supply voltage of 5V. Pin 2 of the isolation power supply module U6 is connected to the other end of capacitors C10, C11, and C12 and one end of capacitor C13 and then grounded. Pin 7 of the isolation power supply module U6 is connected to one end of capacitors C14, C15, and C16. Pin 5 of the isolation power supply module U6 is connected to the other end of capacitors C13, C14, C15, and C16 and then grounded.