Ethernet-RS-232 Protocol Converter Based on PIC18F66J60

Publisher:czc天天Latest update time:2017-12-04 Source: eefocusKeywords:PIC18F66J60 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

  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 modeThe 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 modeThe 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 ModeUDP 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.

projectDefault parameter configurationillustrate
Module NameETORS232_00016-character module description, no spaces allowed
Connection ModeUDPThere are three modes to choose from: UDP; TCPServer; TCPClient
MAC Address0.4.163.0.0.1The MAC address of the demo board can only modify the last three digits.
DHCP ServiceprohibitSelect Enable or Disable based on the actual network situation.
IP address192.168.0.100When DHCP is invalid, this menu is valid. is the IP address of the module.
Subnet Mask255.255.255.0When DHCP is invalid, this menu is valid. is the subnet mask of the module.
Gateway IP address192.168.0.10When DHCP is invalid, this menu is valid. It is the gateway IP address of the module.
Port Address2001This menu is valid in UDP and TCP Server modes.
Remote host address192.168.0.1This menu is valid in UDP and TCP Client modes.
Remote host port address2002This menu is valid in TCPClient mode.
Serial port rate96001200;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.


Keywords:PIC18F66J60 Reference address:Ethernet-RS-232 Protocol Converter Based on PIC18F66J60

Previous article:Design and production of PIC microcontroller 12F629 burner circuit
Next article:PIC microcontroller serial port debugging program

Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号