At present, in the application fields such as industrial control, the communication interface of most devices conforms to the RS-232 communication standard. The data transmission radius of the RS-232 communication method is very limited, far from meeting the needs of remote transmission, and cannot communicate directly with the Internet. In response to the above problems, in system design, the third method is generally used to effectively improve the serial port device to communicate with the Internet: (1) Update the original system, use new products that can access the Internet, or redesign all or part of the original system. This method may fundamentally solve the problem of system connection to the Internet, but it is costly and has a long cycle ; (2) Use RS-232-Internet protocol converter on the original equipment to achieve Internet access.
This article mainly describes the second method, that is, how to use the PlCl8F66J6O microcontroller to extract the data packets sent by the Internet and send them to the user's device through the serial port to achieve the purpose of remote control.
1. Overview The demo board of the Ethernet-RS-232 protocol converter implemented by the PIC 18F66J60 controller is shown in the figure below . It has the following features: (1) The single chip completes the protocol conversion function, greatly reducing the system cost and complexity. (2) The module size is only half the size of a credit card, and the power consumption is less than 1W, which is convenient for integration into system equipment. (3) The ETORS232 has an internal integrated TCP/IP protocol stack. Users can connect their products to the Ethernet without programming the TCP/IP protocol. (4) IOMEthernet interface, the maximum baud rate is 115200b/s. (5) Supports dynamic (DHCP) or static IP address acquisition. (6) Supports three different network connection modes: TCPSERVER mode, TCPCLIENT mode and UDP mode. (7) You can easily use the Windows application NetConfig to view and configure network parameters. 2. Hardware Design 2.1 PIC18F66J60 MCU The PIC18F66J60 chip is a new Ethernet microcontroller launched by Micro Chip Company, which has excellent computing performance, rich function set and very competitive price advantage. The PICI8F66J60 microcontroller includes a series of serial communication peripherals: 2 independent enhanced USARTs and 2 master SSP modules, which can operate in SP1 and 12CTM (master and slave) modes; the general I/0 port includes a reconfigurable 8-bit parallel slave port for communication between processors; all devices in this series include 2 capture/compare/ PWM ( CCP ) modules and 3 (au) enhanced CCP (ECCP (modules), which can conveniently and flexibly implement control applications. At the same time, the microcontroller can use up to 4 different time bases to perform operations on different projects. Among them, each of the 3 ECCP modules can provide 4 PWM outputs, that is, a total of 12 PWM signals can be provided. The ECCP module also provides many other functions, such as polarity selection, programmable dead zone delay, automatic shutdown and restart, and half-bridge and full-bridge output modes. The PICl8F66J6O series microcontroller has an embedded Ethernet controller module. It is a complete connection solution that fully implements the media access control and physical layer transceiver modules. Only two pulse transformers and some passive components are needed to connect the microcontroller directly to the Ethernet. The Ethernet module structure is shown in the figure below. It contains the following five main functional modules: (1) PHY transceiver module: encodes and decodes analog data on the transmission twisted pair interface , and sends and receives through the network. (2) MAC module: implements MAC logic that complies with the IEEE802.3 specification and provides MIIM (Media Independent Interface Management) for controlling PHY. (3) Independent 8KB RAM buffer: used to store data packets that have been received and are to be sent. (4) Arbiter: controls access to the RAM buffer when the microcontroller core, DMA , transmit and receive modules issue requests. (5) Register interface: serves as a decoder for commands and internal status signals between the Ethernet module and the microcontroller special function registers (SFR). The Ethernet module of the microcontroller complies with all the provisions of IEEE802.3 for 10-BaseT connection of twisted pair network. It implements some packet filtering mechanisms to limit incoming packets. It also provides a built-in DMA module for fast data throughput, hardware IP checksum calculation, and two LED outputs for indicating link and network activities. 2.2 Hardware Circuit Design The hardware structure block diagram of the ETORS232 protocol converter is shown in the figure below, where the Ethernet interface and serial port are made into a Demo board, and the microcontroller and LDO form a module, which is connected to the Demo board to form the entire system to complete the communication. The system is embedded with TCP/IP protocol building. After the system is running, the microcontroller runs the TCPflP protocol stack of Microchip. When the communication serial port receives data, the microcontroller receives the data and converts it into Ethernet data format and outputs it from Ethernet; when Ethernet receives data, the microcontroller receives the data and extracts the valid data in the data packet and outputs it from the serial port. The system schematic diagram is shown in the figure below. The internal analog circuit of the Ethernet module requires an external resistor R4 to be connected between the RBIAS port of the microcontroller and the ground . This resistor will affect the amplitude of the TPOUT+/TPOUT- pin signal. When PCB routing, it should be as close to the microprocessor as possible and avoid being adjacent to the signal trace to prevent noise from coupling into the pin and affecting the sending operation. When connecting the T PIN +/TPIN- and TPOUT+/TPOUT- pins, a 1:1 center-tapped pulse transformer for Ethernet operation needs to be connected. When the Ethernet module is enabled, a continuous current will flow into the TPOUT+/TPOUT- pin. When the transceiver module is sending data, changing the relative current size of TPOUT+/TPOUT- will generate a differential voltage on the Ethernet cable . Two additional resistors and one capacitor are required for both the sending and receiving interfaces to minimize signal reflections. 3. Software Design The system operating mode is shown in the following table.
TCPSERVER mode | The module is assigned a unique IP address and port address. When the system is powered on, the module works in the monitoring state to check whether there is a remote host sending a data packet requesting a connection to itself. If a valid connection request is received, the module responds to the host. |
TCPCLIENT mode | The module actively sends a connection request to the remote host address and sends an address resolution packet according to the remote host address in the memory. When the host exists, it sends a connection request data packet to it. At this time, if the host works in TCP SERVER mode, it responds to the request sent from the module and establishes a connection. |
UDP Mode | UDP mode has higher efficiency and faster speed than TCP mode. In this mode, there is no need to establish a connection request and response, and it directly performs two-way data transmission. |
The software flow chart is shown in the figure below. The description of each state is as follows: (1) SM_APP_INIT: Starting state, initialization, and entering the relevant state according to the parameter settings. (2) SM_APP_ARP_ASK: Sending an address resolution packet to the remote host according to the network address corresponding to the IP address request. (3) SM_APP_ARP_RESOLVE: Accepting the address resolution packet sent by the remote host and setting the network address of the remote host. (4) SM_APP_UDP_SOCK-ET: Establishing a UDP connection. (5) SM_APP_UDP: Receive and send data in the UDP connection mode. (6) SM_APP_TCP_SERV-ER_SOCKET: Establishing a TCP connection in the TCPSERV-ER mode and being in the listening state. (7) SM_APP_TCP_SERVER: Receive and send data in the TCPSERVER connection mode. (8) SM_APP_TCP_CLIENT_SOCKET: Establishing a TCP connection in the TCPCLIENT mode and sending a connection request to the host. (9)SM_APP_TCP_CLIENT: Receive and send data in TCPCLIENT connection mode. (10)SM_APP_ERROR: Empty state, used for debugging the program. 4. Application Introduction 4.1 Main Parameters 1OM Ethernet network type; 1.5KV isolation protection; RJ45 interface type. (1) Serial communication port parameters: Signal connection lines are RxD, TxD and GND; Data communication format is 8 data bits, no parity bit, 1 stop bit; Transmission rate is 1200b/s-115.2K/s, (2) Network characteristics: Support ICMP, ARP, IP, TCP, UDP and DHCP protocols; Has UDP, TCPServer, TCPClient operation modes. (3) Power supply parameters: Input voltage is 5V±5%DC, maximum input current is 200mA. (4) Mechanical characteristics: Dimensions: 80mm×36mm×15mm. 4.2 Parameter configuration method The system uses NetConfig application software to configure the module parameters. After NetConfig is running, it will first search for the module on the network in broadcast mode. When the module is found, the user can configure its connection mode, MAC address, IP address, port address, remote host IP address, remote host port address, serial port speed, and whether DHCP is valid. The default parameters are shown in the following table.
project | Default parameter configuration | illustrate |
Module Name | ETORS232_000 | 16-character module description, no spaces allowed |
Connection Mode | UDP | There are three modes to choose from: UDP; TCPServer; TCPClient |
MAC Address | 0.4.163.0.0.1 | The MAC address of the demo board can only modify the last three digits. |
DHCP Service | prohibit | Select Enable or Disable based on the actual network situation. |
IP address | 192.168.0.100 | When DHCP is invalid, this menu is valid. is the IP address of the module. |
Subnet Mask | 255.255.255.0 | When DHCP is invalid, this menu is valid. is the subnet mask of the module. |
Gateway IP address | 192.168.0.10 | When DHCP is invalid, this menu is valid. It is the gateway IP address of the module. |
Port Address | 2001 | This menu is valid in UDP and TCP Server modes. |
Remote host address | 192.168.0.1 | This menu is valid in UDP and TCP Client modes. |
Remote host port address | 2002 | This menu is valid in TCPClient mode. |
Serial port rate | 9600 | 1200;2400;4800;9600;19200;38400;57600;115200. |
4.3 Implementation of the communication process (1) Intranet access Connect one end of the DEMO board to the user device and the other end to the remote host via a network cable. Run the TCP&UDP test tool on the remote host and make corresponding settings on the debugging software according to the module parameters to communicate. For example, when performing UDP communication on the intranet, the TCP&UDP test tool must run in UDP mode, and the target IP and communication port, the local IP and communication port must be consistent with the parameters configured in the module; after power-on, the power indicator (LED3) is always on; when establishing a connection, the connection indicator (LED2) is always on; during communication, the data transmission and reception indicator (LED1) flashes. (2) External network access When the module runs in TCPCLIENT mode, enable the module's DHCP function and automatically assign the module IP and port number through the router; in the network, the remote host requires a fixed IP value and runs in TCP SEVER mode, and then the two sides establish communication. The port address is the label for process communication. When transmitting data from the source host to the destination host, it is necessary to use the IP address and network address. The ultimate goal of Internet communication is to enable one process to communicate with another process. The port is the address used by the process. When communicating over the Internet, the remote host runs in server mode. After the module is powered on, it is always in listening mode and can automatically obtain the IP address and port address of the remote host requesting to connect. (3) Demo board AD and general I/O control function The PICl8F66J6O microcontroller has 64 pins and has a rich number of general I/O ports and AD ports. When using this module, it is not necessary to expand other chips to complete the control other than communication. Short-circuit the two pins RB3 and RB2 on the Demo board with a short-circuit block to enable the control function of the Demo board's AD and general I/0 ports. At this time, run the TCP&UDP test tool to send data to the Demo board. Every time a byte is sent, the AD value collected in the receiving data area of the TCP&UDP test tool will be displayed in the receiving area; adjusting the potentiometer can change the collected voltage value, and the voltage range is 0V~3.3V. RBO and RB1 on the demo board are reserved general I/O ports. Start the TCP&UDP test tool, enter 1 in the sending area, and LEDC will light up after sending; enter 2, and LEDD will light up after sending. 4.4 Application Scope (1) Industrial automation: measurement, transmission equipment, etc. (2) Health care equipment: life indicator monitors, etc. (3) Building automation/building security systems: card reading systems, fire safety, etc. (4) Information appliance systems: network water heaters, network refrigerators, etc. (5) Sales network terminal systems: POS machines, etc. The Ethernet-RS-232 protocol converter implemented by the PIC18F66J6O microcontroller realizes the protocol conversion function with an 8-bit machine. Compared with similar products on the market, it has the characteristics of lower cost, lower power consumption and superior performance. Users can use it to easily realize the network connection function of embedded devices without having to understand complex network knowledge and TCP/IP protocols, saving development time, enabling products to be put on the market faster, and enhancing competitiveness. The high integration of the PIC18F66J6O microcontroller reduces the use of peripheral devices, saves PCB board space, and reduces production costs. In actual use, just install this module in the controlled device to complete the seamless connection between the original device and Ethernet, thus forming a new network control system and realizing network automation control.
Previous article:Design and production of PIC microcontroller 12F629 burner circuit
Next article:PIC microcontroller serial port debugging program
- Popular Resources
- Popular amplifiers
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- LED chemical incompatibility test to see which chemicals LEDs can be used with
- Application of ARM9 hardware coprocessor on WinCE embedded motherboard
- What are the key points for selecting rotor flowmeter?
- LM317 high power charger circuit
- A brief analysis of Embest's application and development of embedded medical devices
- Single-phase RC protection circuit
- stm32 PVD programmable voltage monitor
- Introduction and measurement of edge trigger and level trigger of 51 single chip microcomputer
- Improved design of Linux system software shell protection technology
- What to do if the ABB robot protection device stops
- Allegro MicroSystems Introduces Advanced Magnetic and Inductive Position Sensing Solutions at Electronica 2024
- Car key in the left hand, liveness detection radar in the right hand, UWB is imperative for cars!
- After a decade of rapid development, domestic CIS has entered the market
- Aegis Dagger Battery + Thor EM-i Super Hybrid, Geely New Energy has thrown out two "king bombs"
- A brief discussion on functional safety - fault, error, and failure
- In the smart car 2.0 cycle, these core industry chains are facing major opportunities!
- The United States and Japan are developing new batteries. CATL faces challenges? How should China's new energy battery industry respond?
- Murata launches high-precision 6-axis inertial sensor for automobiles
- Ford patents pre-charge alarm to help save costs and respond to emergencies
- New real-time microcontroller system from Texas Instruments enables smarter processing in automotive and industrial applications
- Analog PID
- Suddenly I want to ask myself
- Explain in layman's terms how computers work
- Hardware Knowledge Trio
- Chip Replacement
- After-class review | Highlights of ADI power supply expert training course
- Newbie help: What is the difference between AT89C51 and C52 in protues?
- dynamic
- EEWORLD University Hall----Live Replay: Infineon Intelligent Motor Drive Solution
- Should I switch from MCU to Linux? Come in and see what the experts say