Technology and application of single chip microcomputer controlling GSM mobile phone

Publisher:phi31Latest update time:2011-11-24 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

Because the wireless network coverage of mobile phones is wide and the performance of information transmission is stable and reliable, the mobile phone as a carrier of information transmission combined with the single-chip microcomputer to form an application system has strong vitality and broad application space, especially in the fields of remote data transmission and remote monitoring, it has attracted the attention of electronic design application engineers. Some professional publications have also introduced some articles on this aspect. However, due to the complex control instructions of mobile phones and the cumbersome data format, engineering and technical personnel often encounter many difficulties when designing the hardware and software interface between single-chip microcomputers and mobile phones, and sometimes there is no information to check. In the process of completing the development of a project, the author conducted a large number of tests and experiments on several mobile phones, and on this basis, summarized some regular conclusions. For this conclusion, engineering designers can use it immediately, which greatly shortens the research and development cycle. Now it is published and is willing to share with the majority of electronic designers.

1 Hardware interface technology

Most of the popular mobile phones on the market now have data ports and basically support AT control commands related to GSM short messages (GSM-SMS-AT commands). Mobile phones receive commands in serial mode through the data port and output data to the outside. In theory, the hardware interface is completed by finding the RxD, TxD and GND pins in the data port and connecting them to the serial port of the microcontroller.

However, in reality, due to the different brands and models of mobile phones, the RxD, TxD and GND pins are not consistent, and it is sometimes not easy to find these three wires; moreover, the level of the mobile phone data port is neither RS232 level nor TTL level, and it cannot be directly connected to the serial port of the microcontroller powered by 5V. The simplest and most reliable method is to use the mobile phone's data cable to establish a hardware connection between the microcontroller and the mobile phone. The mobile phone data cable is specially designed for connecting to the 9-pin serial port of the PC. The signal level is the standard RS232 level. As long as the serial port of the microcontroller is also converted to the RS232 level, it can be easily connected. The definition of the 9-pin serial port pin is fixed, that is, pin 2 is TxD (mobile phone sends), pin 3 is RxD (mobile phone receives), and pin 5 is GND. In this way, no matter what model of mobile phone is connected to the microcontroller, it becomes a fixed connection, and there is no need to know the specific definition of the mobile phone data port signal. The connection circuit between the two through the data cable is shown in Figure 1.

It should be noted that the power supply mode of the internal level conversion chip of different mobile phone data cables is different. Some are powered directly by the mobile phone; some are powered by stealing the current of certain pins (usually pins 4, 6, 7, and 8) of the PC serial port and then providing it after internal rectification, filtering and voltage stabilization. The method of judgment is to plug one end of the data cable into the data port of the mobile phone and measure the voltage between pins 2 and 5 at the other end. If there is a voltage of about 7V, it is the former. If no voltage can be measured, it is the latter. For the latter, the microcontroller needs to provide a +5V voltage to any pin of pins 4, 6, 7, and 8, as shown by the dotted line in Figure 1.

2 Software interface technology and control principle

The software interface between the microcontroller and the mobile phone is actually the control technology of the microcontroller controlling the mobile phone through AT commands related to GSM short messages, such as reading the content of the mobile phone's short messages, deleting the content of short messages, and listing the unread short messages in the mobile phone. For the functional description of AT commands, please refer to the article content of references [1, 2], which will not be repeated here. However, executing an instruction is not as simple as described in some materials. In fact, the execution process of the instruction requires the microcontroller and the mobile phone to interact and respond to each other. There are strict regulations on the number of bytes sent or received each time. The two must realize data exchange according to these regulations, otherwise, the communication will fail. After repeated tests on several mobile phones, the author summarized some rules, as listed in Table 1.

[page]

Several issues are explained as follows.

① All AT command symbols, constants, PDu data packets, etc. are transmitted in ASCII encoding. For example, the ASCII encoding of "A" is 41H, the AscII encoding of "T" is 54H, and the AscII encoding of the number "0" is 30H.

② For the MCU to control the mobile phone, the short message working mode of the mobile phone must be set to PDu format, which can be completed through the command AT+cMGF=O.

③ After the MCU sends each command to the mobile phone, it must end with a carriage return character, and the ASCII code of the carriage return is 0DH. For example, the MCU sends the command "AT+CMGF=0" to the mobile phone, and its ASCII code sequence is "41H, 54H, 2BH, 42H, 4DH, 47H, 46H, 3DH, 30H, 0DH". The last byte 0DH is the carriage return character, indicating that the command ends. If there is no carriage return character, the mobile phone will not recognize this command.

④ When the mobile phone receives a complete AT command, it does not execute the command immediately, but first sends out the entire ASCII code sequence of the AT command just received (including 0DH), and then sends an ASCII code of a carriage return and line feed, that is, 0DH and 0AH, and finally executes the command.

⑤ When the mobile phone transmits the short message content to the single-chip microcomputer, the content of its PDu data packet is data represented in hexadecimal, but it does not directly transmit the hexadecimal data to the single-chip microcomputer, but still sends each hexadecimal number in AscII encoding. In this way, the two-byte hexadecimal number becomes a 4-byte ASCII code. However, the data byte length part in the PDU data packet is still the actual byte length, not the byte length converted into AscII code. This should be paid special attention to during programming, otherwise the received data will be incomplete. After the single-chip microcomputer receives the PDU data packet data, it must be restored to hexadecimal data. The algorithm is as follows: Let a be the received ASCII code and b be the converted hexadecimal number. If a<39H, then b=a-30H; if a>39H, then b=a-30H-07H, and finally merge the two numbers into one byte.

⑥ The number of bytes of the PDU data packet that the mobile phone responds to the MCU does not include the first 9 bytes of data (SMS service center address), but when transmitting the PDU data packet to the MCU, these 9 bytes of data are included. For example, if the length of the PDU data responded by the mobile phone is 50, and the hexadecimal data actually transmitted to the MCU is 59 bytes, the ASCII code is 2×59 bytes, so the MCU must receive the PDU data as 2×59 bytes.

3 Application Examples

The author has developed a project using the above principles and interface technology: a highway display guidance system. The LED display screen installed on the highway displays the vehicle traffic situation and weather conditions in the road ahead in real time, reminding and guiding drivers to drive correctly.

The use of this system has eliminated many potential traffic accident hazards to a certain extent, thus ensuring the smooth flow of roads and the safety of people's lives and property. The system consists of a control center and several display screens. The control center sends the latest information to each display screen in real time. To build a communication link between the control center and the display terminal, the traditional method is either to lay optical cables in a wired manner or to build a dedicated wireless network in a wireless manner. Due to the particularity of the highway, the distance between the control center and the display terminal is usually very far, and both solutions require a lot of money and a huge construction workload. If the GSM public wireless transmission network is used, the technical solution of the control center sending the display information to the display terminal in the form of short messages has many advantages such as small investment, convenient construction, reliable operation, and low operating costs.

In the control center, the microcomputer edits the short message and sends it out through the mobile phone. In the display terminal, the single-chip microcomputer reads the short message from the mobile phone and displays it on the LED display. The core technology of the project is the interface between the single-chip microcomputer and the mobile phone and the encoding of Chinese character information in the PDU data packet. Because the Chinese characters in the short message are just a code, the single-chip microcomputer application system converts the code into Chinese character dot matrix data, and the Chinese character font must be configured. According to the GSM07.05 protocol, the Chinese character encoding in the short message is Unicode encoding. If a Unicode-encoded Chinese character font is constructed, it is indeed a tedious task. Therefore, when designing the single-chip microcomputer application system, the following two technical measures are adopted.

① The character library configured in the single-chip system is the Chinese character library of GB-2312 encoding, that is, the location code Chinese character library, which can be downloaded for free on the Internet and solidified into the Flash storage chip. Of course, the premise of doing so is that the Chinese character encoding in the PDU data packet must be the Chinese character internal code rather than the Unicode encoding.

② When the control center edits the PDU data packet data, it adopts the custom data mode. Among them, the data representing Chinese characters can directly use the machine code of Chinese characters, eliminating the pain of converting the machine code into Unicode encoding. Practice has proved that this is feasible.

The advantages of adopting the above technical measures are: first, it eliminates the need for mutual conversion between the two codes; second, it ensures the confidentiality of the data, and users outside the system cannot receive it, and even if they do, they cannot display it.

After the project was successfully developed and put into use, since the display terminal only receives but does not send, there is almost no operating cost. The sending end (control center) can adopt a monthly rental method, which can also reduce the operating cost to a minimum. Therefore, the project has received satisfactory evaluations from users.

Reference address:Technology and application of single chip microcomputer controlling GSM mobile phone

Previous article:The role of crystal oscillator in single chip microcomputer
Next article:Circular Gray Code VHDL Source 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号