Monday, December 27, 2021

The solution to the problem of the design of the hardware and software interface between the single-chip computer and the mobile phone

Almost all mobile phones currently on the market have data export, and basically support AT control commands (GSM-SMS-AT commands) related to GSM short messages. External output data. Theoretically speaking, the hardware interface is completed by finding out the corresponding connections between the RxD, TxD and GND pins in the data port and the serial port of the microcontroller.

Author: Li Yanhua, Chen Huiming

Because of the wide coverage of the wireless network of mobile phones and stable and reliable performance in information transmission, the mobile phone is used as the carrier of information transmission and combined with the microcontroller to form an application system with strong vitality and broad application space, especially in remote data Fields such as transmission and remote monitoring are even more concerned by Electronic design application engineers. Some professional publications also introduce some articles on this aspect. However, due to the complicated control instructions of mobile phones and the cumbersome data format, engineers and technicians often encounter many difficulties when designing the hardware and software interface between the MCU and the mobile phone, and sometimes there is no information. Can be checked. In the process of completing the development of a project, a large number of tests and experiments were carried out on several mobile phones, and some conclusions with regularity were concluded on this basis. This conclusion can be used by engineering designers, which greatly shortens the research and development. Cycle, now publish it, and would like to share it with the majority of electronic designers.

1 Hardware interface technology

Almost all mobile phones currently on the market have data export, and basically support AT control commands (GSM-SMS-AT commands) related to GSM short messages. External output data. Theoretically speaking, the hardware interface is completed by finding out the corresponding connections between the RxD, TxD and GND pins in the data port and the serial port of the microcontroller.

However, in fact, due to different brands, the RxD, TxD, and GND pins of different models of mobile phones are not the same. Sometimes it is not easy to find these three wires; besides, the level of the data port of the mobile phone is neither RS232 level nor TTL level. It is not directly connected to the serial port of the MCU powered by 5V. The simplest and most reliable method is to use the data cable of the mobile phone to establish the hardware connection between the MCU and the mobile phone. The mobile phone data line is specially designed to connect 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 single-chip microcomputer is also converted to the Rs 2 3 2 level, it can be easily connected. The 9-pin serial port pin definition is fixed, that is, pin 2 is TxD (mobile phone sending), pin 3 is RxD (mobile phone receiving), and pin 5 is GND. In this way, no matter what type of mobile phone is connected to the single-chip microcomputer, 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 line is shown in Figure 1.

The solution to the problem of the design of the hardware and software interface between the single-chip computer and the mobile phone

It should be noted that the power supply mode of the internal level conversion chip of different mobile phone data lines is different, some are directly powered by the mobile phone; some are stealing some pins of the PC serial port (usually 4, 6, 7, 8 pins) The current is provided after internal rectification, filtering, and 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, and if the voltage cannot be measured, it is the latter. The latter requires the microcontroller to provide a +5V voltage for any of the 4, 6, 7, and 8 pins, as shown by the dotted line in Figure 1.

2 Software interface technology and control principle

The software interface between the single-chip microcomputer and the mobile phone is actually the control technology of the single-chip microcomputer controlling the mobile phone through AT commands related to GSM short messages, such as reading the content of the short message of the mobile phone, deleting the content of the short message, and listing the unread short messages in the mobile phone. For the description of the function of the AT command, please refer to the content of the reference[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 of the instructions requires the interactive response between the microcontroller and the mobile phone. There are strict regulations on the number of bytes sent or received each time, and the two must implement data exchange according to these regulations. Otherwise, the communication will fail. After repeated tests on several mobile phones, the author summed up some rules, as listed in Table 1.

The solution to the problem of the design of the hardware and software interface between the single-chip computer and the mobile phone

Several issues are explained as follows.

①All AT commands’ command symbols, constants, PDu data packets, etc. are transmitted in the form of ASCII encoding. For example, the ASCII encoding of “A” is 41H, the AscII encoding of “T” is 54H, and the number “0,,” is AsCII encoding. For 30H and so on.

②The single-chip microcomputer controls the work of the mobile phone, and the short message working mode of the mobile phone must be set to the PDu format, which is completed by the command AT+cMGF=O.

③After the single-chip microcomputer sends each instruction to the mobile phone, the carriage return character must be used as the end of the instruction, and the ASCII code of the carriage return is 0DH. For example, when the MCU sends the command “AT+CMGF=0” to the mobile phone, the ASCII code sequence is “41H, 54H, 2BH, 42H, 4DH, 47H, 46H, 3DH, 30H, 0DH”, and the last byte 0DH is The carriage return character means the end of this instruction. If there is no carriage return character, the mobile phone will not recognize this instruction.

④ When the mobile phone receives a complete AT command, the mobile phone does not execute this command immediately, but first sends out all the ASCII code sequences of the AT command just received (including 0DH), and then sends a carriage return The ASCII code of the character and the newline character, that is, 0DH and 0AH, and finally execute the instruction.

⑤When the mobile phone transmits the content of the short message to the single chip microcomputer, the content of its PDu data packet is the data expressed in hexadecimal, but it does not directly transmit the hexadecimal data to the single chip, but still puts each bit of hexadecimal The number is sent in AscII code. In this way, a two-byte hexadecimal number becomes a 4-byte ASCII code. However, the data byte length in the PDU data packet is still the actual byte length, not the byte length of the AscII code. This should be paid special attention to during programming, otherwise, the received data will be incomplete. After the one-chip computer 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, b is the converted hexadecimal number. If a39H, 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 microcontroller does not include the first 9 bytes of data (the address of the SMS service center), but when the PDU data packet is transmitted to the microcontroller, it includes these 9 bytes of data. For example, if the length of the PDU data that the mobile phone responds to is 50, and the hexadecimal data actually sent to the microcontroller is 59 bytes, and the ASCII code is 2×59 bytes, the microcontroller must receive the PDU data in 2×59 bytes. .

3 Application examples

A project was developed using the above-mentioned principles and interface technology: a highway Display and guidance system. The LED display installed on the highway displays the traffic situation and weather conditions of the road ahead in real time, reminding and guiding the driver to drive correctly.

The use of this system has eliminated many hidden dangers of traffic accidents 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 construct the communication link between the control center and the display terminal, the traditional method is either to lay the optical cable and realize it in a wired way, or to construct a dedicated wireless network to realize it in a wireless way. Because of the particularity of the highway, the distance between the control center and the display terminal is usually very long, and both schemes must invest a lot of money and huge construction workload. If the GSM public wireless transmission network is adopted, and the control center sends the display information to the display terminal in the form of short messages, it has many advantages such as small investment, convenient construction, reliable work, and low operating cost.

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

①The font library configured by the single-chip microcomputer system is a GB-2312-encoded Chinese character library, that is, a location code Chinese character library, which can be downloaded for free on the Internet and can be cured into the Flash memory chip. Of course, the prerequisite for this 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 a self-defined data method. Among them, the data representing Chinese characters can be directly taken from the machine internal code of the Chinese character, which eliminates the pain of converting the machine internal code to Unicode. Practice has proved that this is feasible.

The advantages of adopting the above technical measures are that one is that the mutual conversion of the two codes is eliminated; the other is that the confidentiality of the data is ensured, and the users in the system cannot receive it, even if it is received, it cannot be displayed.

After the project was successfully developed and put into use, because the display terminal only received but not sent, there was almost no operating cost. The sending end (control center) can be rented monthly, and operating costs can be reduced to a minimum. Therefore, the project has received satisfactory evaluation from users.

The Links:   KCS3224ASTT-X9 CM300DY-12HE

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.