There are HTTP, SOCKET and other types in the network settings. SOCKET is a socket specification established on the transport layer protocol (mainly TCP and UDP), which defines the specification for communication between two computers (also a programming specification). If two computers use a channel to communicate, then the two ends of the channel are two sockets. The socket shields the difference between the underlying communication software and the specific operating system, making it possible to communicate between any two computers that have installed the TCP protocol software and have implemented the socket specification.

There are HTTP, SOCKET and other types in the network settings. SOCKET is a socket specification established on the transport layer protocol (mainly TCP and UDP), which defines the specification for communication between two computers (also a programming specification). If two computers use a channel to communicate, then the two ends of the channel are two sockets. The socket shields the difference between the underlying communication software and the specific operating system, making it possible to communicate between any two computers that have installed the TCP protocol software and have implemented the socket specification.

1 System composition

The composition of the system is shown in Figure 1. The system uses the existing GPRS network, and the single-chip microcomputer controls the GPRS module through the serial port to realize the SOCKET communication.

Computer communication design based on AT89C52 single chip microcomputer and LT8030 to realize socket specification

The description of each part of the system is as follows:

① The single-chip microcomputer uses AT89C52, which has a serial port;

② GPRS module. This article takes the GPRS module LT8030 developed by Lishida Information Technology Co., Ltd. as an example. LT8030 is embedded with a complete TCP/IP protocol stack, including TCP, UDP, FTP, SOCKET, Telnet, POP3, SMTP, HTTP, etc., providing users with a simpler network interface. The GPRS technology adopted by the LT8030 provides seamless coverage, is always online, and is billed according to the flow rate. It is closely integrated with the actual problems encountered in the product application field, and comprehensive optimization and upgrades are carried out to make product development easier and faster. It adopts a standard RS232 interface, and users can control the module through the UART port of a single-chip microcomputer or other CPUs and use the corresponding AT commands to achieve the purpose of making their products easy to enter the GPRS network.

③ Server. Establishing SOCKET connection must have an IP address of the public network, so it is necessary to ensure that the server center computer is connected to the Internet and obtains the public network IP address. Before the single-chip microcomputer controls the GPRS module, the server side needs to run the SOCKET port* program (this * program is generally a ready-made), and set it to the state of *, and the port number must also be set, such as port: 1024.

2 Connection of MCU and GPRS module

The single-chip microcomputer and GPRS module generally adopt serial asynchronous communication interface, and the communication speed can be set, usually 9600 bps. When the RS232 cable is used for connection, the reliability of data transmission is better. The one-chip computer is connected with the GPRS module through the level conversion circuit, the circuit is relatively simple, the circuit schematic diagram is shown as in Fig. 2. The involved chip MAX232 is used for level conversion between the serial communication interface and the 232 communication interface.

Computer communication design based on AT89C52 single chip microcomputer and LT8030 to realize socket specification

T1IN, T2IN, R1OUT, R2OUT of MAX232 are pins connected to TTL/CMOS level; T1OUT, T2OUT, R1IN, R2IN are pins connected to RS232 level. The T1IN and T2IN pins of TTL/CMOS level should be connected to the serial transmission pin TXD of AT89C52; R1OUT and R2OUT should be connected to the serial reception pin RXD of AT89C52. Correspondingly, T1OUT and T2OUT of RS232 level should be connected to the receiving end RXD of the GPRS module; R1IN and R2IN should be connected to the sending end TXD of the GPRS module.

Now choose one of them to send/receive, R1OUT connects to AT89C52 RXD, T1IN connects to AT89C52 TXD, T1OUT connects to RXD of GPRS module, R1IN connects to TXD of GPRS module. Because MAX232 has drive capability, so no external drive circuit is needed.

3 Command to establish SOCKET connection

The following describes some AT commands used in SOCKET communication.

3.1 Basic settings

① GPRS ISP code.

AT+IISP1=*99***1# //Nationwide

② Login user name.

AT+IUSRN=WAP//GPRS network login name

③ Login password.

AT+IPWD=WAP// GPRS network login password

④ MODEM type.

AT+IMTYP=2 //Define GPRS MODEM

⑤ Initialize the command.

AT+IMIS=”AT+CGDCONT=1, ip, CMNET”

⑥ * Device.

AT+IDNS1=211.136.18.171

//DNS server address, nationally applicable

⑦ Extension code (XRC).

AT+IXRC=0

3.2 SOCKET settings

① Establish a TCP communication.

AT+ISTCP: 218.66.16.173, 1024

Establish a SOCKET connection, 218.66.16.173 is the IP address of the application service center computer (the actual address is determined by the actual situation), and 1024 is the port number (the port number is determined by the center SOCKET port* program setting). If the connection is successful, LT8030 returns I/xxx. xxx is the handle number of this socket connection in LT8030. The center* program will Display the IP address of the connected terminal. If the connection fails, LT8030 returns I/ERROR (xxx). xxx is the error code.

② Send data.

AT+ISSND%: xxx

Send data, xxx is the handle, the character length to be sent, and the data to be sent. After the transmission is successful, the data sent by the terminal can be seen at the center. Data below 5K can be sent at most once.

③ Query SOCKET status.

AT+ISST: xxx

Query SOCKET status, xxx is the handle. LT8030 returns to I/. If = 000, it means that the port is connected normally; if ≥ 1, LT8030 receives the number of bytes stored in Buffer from the center through this port; if <0, SOCKET is wrong.

④ Receive data.

AT+ISRCV: xxx

xxx is the handle. This instruction will read the data that LT8030 received from the center through this handle and stored in the Buffer; the Buffer can store up to 30K of data.

⑤ Close SOCKET channel.

AT+ISCLS: xxx

Close SOCKET channel, xxx is the handle.

4 Program design

According to the agreement of the communication protocol between the MCU and the GPRS module, the MCU serial port is set to mode 1, the baud rate is 9 600 bps, 8 UART, 1 start bit, 1 stop bit, and no parity. After power-on, first send the basic setting commands to the GPRS module, that is, ISP code, user name and user password frame, etc. The ISP code must be “*99***1#”, the user name and user password can be set arbitrarily, but not Is empty. Before using the LT8030 GPRS Internet access function, these parameters must be set correctly. Once the parameters are set, they will be stored permanently, and there is no need to reset them in the future (the above settings are the default parameters of the LT8030C when it leaves the factory). Then send the SOCKET setting frame to the GPRS module, if successful, the point-to-point communication environment has been established, and then call to send the data frame.

After power on, the program runs in the main function and the microcontroller initializes. Initialization includes setting the serial port working mode, baud rate, and initializing variable parameters and flag bits.

Concluding remarks

With the advancement of computer and communication technology, the production of today’s society is developing in the direction of high efficiency, accuracy and stability. This puts forward higher requirements on the real-time, reliability and information volume of data transmission. For this reason, we introduce the use of GPRS The module realizes the system of SOCKET communication. This article uses the GPRS module LT8030 with embedded TCP/IP protocol, realizes the control of the LT8030 on the 8-bit microcontroller AT89C52, and realizes the GPRS-based SOCKET communication function, with fewer peripheral components, simple circuits, and low system costs. advantage.

The Links:   IAUX61H LM170E03-TLL1 IGBTMODULE