A Solution of MCU-based Internet Access Based on GPRS

Microcontroller microcontrollers are widely used in various industrial and civil embedded systems due to their small size, low power consumption, and ease of use. With the rise and popularity of the Internet, microcontrollers have made their way through the Internet. It makes sense to send data. Currently, there are two kinds of solutions for the microcontroller to access the Internet: one is to use a microcontroller to drive the network card and connect to the Internet through Ethernet; the other is to make the microcontroller directly drive the modem (MODEM) to dial the ISP through the telephone line. Internet access. The disadvantage of these two schemes is that they all use wired networks and cannot be used in remote areas or mobile systems.

Aiming at this problem, this paper proposes a solution of MCU accessing the Internet based on GPRS, that is, implementing PPP protocol in MCU and connecting to the Internet through GPRS wireless network to realize Internet access. The advantages of this solution are: 1 wide coverage, suitable for a large number of remote areas; 2 wireless Internet access, suitable for mobile targets; 3 use of inexpensive microcontrollers to achieve simple, low cost; 4 easy installation and easy maintenance.

GPRS module

GPRS technology and its features

GPRS (General Packet Radio Service) is an abbreviation of General Packet Radio Service. It is a packet switched data bearing and transmission method developed on the basis of GSM. Compared with the original GSM, GPRS has a very obvious advantage in the bearer and support of data services: through the multiplexing of multiple GSM time slots, the supported data transmission rate is higher, and the theoretical peak value is 115kb/s; different networks Users share the same set of GPRS channels, but channel resources are only occupied when a certain user needs to send or receive data. In this way, multi-user service reuse enables more efficient use of wireless network channel resources, and is particularly suitable for bursty and frequent small-traffic data transmissions, and is well adapted to the bursty nature of data services; GPRS charging methods are more flexible. It can support billing according to data traffic. Unlike wireless application protocol (WAP) technology, GPRS can provide users with transparent IP channels at any time, and can directly access all sites and resources in the Internet; and adopts channel multiplexing technology. A GPRS user can always be online. In addition, GPRS can also support voice calls while data transmission is in progress. Compared with short message and other wireless data communication services, GPRS has a relatively obvious price advantage. At present, China's mobile launch of GPRS Internet access business is only 3 cents per kilobyte, and users can according to their own needs, monthly rent, monthly and other forms to further reduce the cost of GPRS communications.

Therefore, the use of GPRS for remote data transmission is very economical and practical, especially for remote areas and portable devices that do not easily have line networks.

Hardware connection and GPRS module settings

Data transmission via the GPRS network generally requires the use of a GPRS module. At present, the GPRS module generally refers to a GSM module with a GPRS function and can use the GPRS network for data communication.

Among the more popular ones are the WISMO series from the French Wave company and the S series from the Siemens company. WAVECOM's WISMO module is simple, easy to use and very powerful

Among them GPRS module and one-chip computer carry on the communication through the serial port, the communication speed can reach 115 200b/ s at the fastest. The communication protocol between the module and the controller is the AT command set, most of which are in accordance with the protocol "AT command set for GSM Mobile Equipment (ME) (GSM 07.07 version 6.4.0 Release 1997)", but there are also some of them that are Wavecom themselves. Defined AT commands. In addition to the serial port transmission (TX), serial port reception (RX), there are some hardware handshake signals between the microcontroller and the GPRS module, such as DTR, CTS, DCD and so on.

In order to simplify the control of the microcontroller, the hardware design should not use all the hardware handshake signals, but use only the Data Carrier Detect (DCD) and Data Terminal Ready (DTR) signals.

The DCD signal can detect whether the GPRS module is in a data transmission state or in an AT command transmission state.

The DTR signal is used to inform the GPRS module that the transmission work has ended.

After the hardware connection is completed, the GPRS module must be set before the GPRS access operation. The main setup work is:

1 Set the communication baud rate. You can use AT+IPR=38400 command to set baud rate to 38 400b/s or other suitable baud rate. The default communication speed is 9600b/s.

2 Set the access gateway and set the GPRS access gateway to Monternet through the AT+CGD CONT=1, “IP”, and “CMNET” commands.

3 Set the category of mobile terminal and set the category of mobile terminal to Class B by AT+CGCLASS=“B”, that is, monitor multiple services at the same time; but only one service can be run, that is, only GPRS can be used at the same time, or Uses GSM voice communications.

4 Test whether the GPRS service is enabled and use the AT+CGACT=1,1 command to activate the GPRS function. If you return OK, the GPRS connection is successful; if you return ERROR, it means that GPRS fails. In this case, check whether the GPRS service of the SIM card has been opened and whether the antenna of the GPRS module is correctly installed.

China Mobile established a number of gateway support nodes (GGSNs) equivalent to ISPs between GPRS and Internet to connect GPRS networks to external Internet networks. The GPRS module can dial the “*99***1#” to log in to the IP address dynamically allocated to the Internet by the GGSN. During this period, the communication between the GPRS module and the gateway must comply with the Point to Point Protocol (PPP), in which the user name and password are all empty during authentication. After logging in using the PPP protocol, you can connect to the Internet through the GGSN.

The overall structure of the software

All the code in the program is preferably written in C language and uses a layered structure. From the bottom to the top, they are the serial port driver layer, the GPRS module driver layer, the PPP protocol layer, the IP protocol layer, the UDP protocol layer, and the application layer. The implementation of the upper-level function needs to be applied to the underlying function, and the task of the underlying function is to provide services for the upper-level function, and finally complete the application-level task—transmitting data.

Driver writing

The first is the serial port driver layer. It implements such functions as opening the serial port, closing the serial port, reading serial data, and writing serial data. Then, write the GPRS module driver functions on the basis of these serial functions. The one-chip computer controls GPRS module through the serial port, carries on dialing, setting up and so on operation. The method of control is to use the AT command.

After controlling the GPRS module to dial the login number "*99***1#" of Monternet GGSN, the GPRS module will go online (On-Line). At this point, all the data sent by the microcontroller to the serial port is transparently transmitted to the GGSN, and the GGSN's answer is also returned to the serial port of the microcontroller.

After the data transfer is completed, the MCU needs to notify the GPRS module to end the session and switch back to the normal command mode from the online mode. This can be done by setting the DTR line high. At the same time, if the line is disconnected due to an abnormality, the CD line will return to a normal low level, so in the online mode it is also necessary to constantly detect whether the CD line is at a high level. Based on these operations, you can write GPRS driver functions: Initialize the GPRS module function, dial function, disconnect function, and check if the function is online.

These underlying driver functions will make it easier to write upper-level protocols. More importantly, it provides us with a driver abstraction layer. When the underlying hardware changes, only the underlying driver functions need to be changed, and the code of the upper function remains unchanged.

Implementation of PPP Protocol

Since Monternet's GGSN follows the PPP protocol when communicating with the GPRS module, a part of the PPP protocol must also be implemented in the microcontroller to talk to it. After dialing, the GPRS module first negotiates the communication link with the GPRS gateway, that is, negotiates various link parameter configurations from point to point. The negotiation process complies with LCP (Link Control Protocol), PAP (Password Authentication Protocol), and IPCP (Internet Protocol Control Protocol) protocols. The LCP protocol is used to establish, construct and test the link connection; the PAP protocol is used to process the password verification part; the IPCP protocol is used to set the network protocol environment and allocate the IP address. The negotiation mechanism is implemented using a finite state machine model. Once the negotiation is complete, the link has been created, and the IP address has been allocated for IP packet transmission according to the negotiated standards. According to different applications, IP packets can carry UDP packets, and can also be TCP or ICMP packets. This system uses UDP packets to transmit data information. After the data transmission is completed, the MCU sends an LCP disconnect message to the GGSN to terminate the network connection.

PPP frame structure (figure omitted). The serial port interrupt receiving program of the one-chip computer first judges whether there is a complete PPP package with the start and end character of the package, and check the content of the PPP package to determine the integrity and correctness of the data package. Then enter the PPP message parsing module in the main loop.

Login GGSN process

One of the difficulties of the system is the process of the single-chip computer logging on the GPRS gateway (GGSN) and negotiating with the gateway through the LCP, PAP, and IPCP protocols. The LCP, PAP, and IPCP protocols have similar frame structures. The most commonly used are Request (REQ), Acknowledge (ACK), and Deny (NAK) frames. Both the MCU and the GGSN negotiate on the one hand, and either party can send a REQ frame to request some aspect of the preparation. The other party thinks that the configuration is unacceptable and it will respond to the NAK frame. If it can, it responds to the ACK frame. In order to save resources, we only deal with these three kinds of data frames, and other link problems are solved by the MCU under the control of the program.

The negotiation process is roughly described as follows: After a successful dial-up connection, the GGSN will first return a PAP REQ data frame. We send an empty LCP REQ frame to enforce the protocol negotiation phase. Subsequently, the GGSN sends the LCP setup frame, we reject all settings and request authentication mode. GGSN chooses CHAP or PAP authentication. We only accept PAP. Then, PAP authentication user name and password process, in the GPRS user name and password are empty, if successful, GGSN will return IPCP packets to assign a dynamic IP address. At this point, the negotiation process with the GGSN is completed. The state transition of the negotiation process is shown in Figure 4.

After the negotiation is completed, it enters the IP datagram communication phase. At this time, all the PPP messages sent from the MCU to the GGSN will be sent to the corresponding IP address in the Internet. And all the messages sent from the remote to the MCU IP address will be sent to the MCU via the GPRS network. This completes the data transmission between the SCM and the remote host over the Internet.

Office Teaching Projector

The selection of teaching projectors, with rich and bright colors, high-resolution projectors, and high-brightness laser light sources, can meet the needs of various large and medium-sized indoor teaching scenarios in schools, and provide teachers with good projection interactive teaching.

office projector,office presentation projector,good office projector,office classroom projector,4k teaching projector

Shenzhen Happybate Trading Co.,LTD , https://www.happybateprojector.com