Carries on the long range data transmission using the GSM short note, in some situations is one kind of quite good choice. In many literature introduced the related GSM module function, the use, as well as AT order and so on, but in the practical application also many technical detail must consider. Moreover the correspondence is carries on the complex environment, the GSM module besides receives this system interior effective order, the data, will also receive some other information, the data, like advertisement short note, motion company’s each kind of notice and so on. They will affect the data from following two aspects the normal transmission. At the same time, the time which and the number of times these short note’s length, appears because is stochastic, must receive for guarantee system’s normal work the buffer to establish in a big way, will otherwise possibly cause the buffer the overflow to cause the system collapse; But the MCU resources limit which is used the system, the buffer is generally impossible to establish oversized. On the other hand, as a result of these short note’s frequent appearance, the mailbox very quick will be crowded, like will not be prompt deletes will affect the system normal data transmission inevitably. This article take Motoro1a Corporation’s G20 module as an example, realizes as soon as the detail and the above question’s solution does said that but to between the GSM module and the MCU concrete hardware connection, at order and the short note form and so on no longer gives unnecessary detail.
1 GSM module software and hardware connection several questions
The GSM module has the standard asynchronous serial interface generally, MCU through this serial interface to the GSM module routing directive and the data, also receives the GSM module through it the information and the data.
After GSM module electricity, must first carry on the initialization. Generally speaking, MCU first may transmit a AT order to it “ATEO”, eliminates “returns obviously”, reduces the character which as far as possible the MCU serial port receives; Then transmits at order “CNMI”, establishes the GSM module as “the driving notice pattern”. After like this when the GSM module receives the short note, then on own initiative “CMTI” will inform MCU to the serial port transmitter data, indicated that will have the new short note to arrive. Moreover, but must inspect in the mailbox whether to deposit has the short note. If has, its 11 read-out, then one by one deletes, take maintains in the mailbox as spatial.
After the GSM module starts the work, when receives the short note then on own initiative through the serial port to the MCU transmitter data “CMTI”, after MCU will receive this information, will issue at order “CMGR” the read short note, the GSM module soon this short note for MCU through the serial port transmission, will judge this short note by MCU is in this system’s normal data, advertisement or other information. If is in this system’s normal data, then withdraws in this short note the data, simultaneously issues at order “CGMD” to delete this short note; If is not the normal data, then deletes this short note directly. The MCU transmission short note’s process is as follows: First, MCU transmits at order “CMGS”; Then, waited for the GSM module the permission transmission short note’s response message “>”, after MCU receives the response message, then transmits the data, the GSM module the data by the short note form transmission; Finally, the GSM module issues the short note through the serial port to MCU to transmit the successful or not information. Above process as shown in Figure 1. Information which reads out from the GSM module besides short note itself, but also includes some other information, like SIM card number, date time, each kind of gap/conclusion character and so on. During this process the MCU serial port will receive the mass data frequently, must therefore probably for the serial port establishment enough receive buffer. But because in MCU the RAM resources are limited, to use the resources effectively, may receive the buffer to establish as ring-like, the buffer size should guarantee that can hold a longest short note, in addition other extra message length. As for transmission buffer, direct hypothesis for appropriate size then.
2 realize specifically
In MCU and GSM module through in serial port exchange data process, generally serial port available interrupt mode. The MCU transmission data’s situation is simple, therefore here key point is the MCU serial port receive. As mentioned above, the receive buffer should establish as ring-like, because the MCU memory in fact is the linear structure, therefore the ring-like buffer is realizes through the indicator operation.
When initialization causes the input/to output the indicator (datain/dataout) simultaneously to aim starts the position, this time the buffer is “spatial”. Serial port receive procedure CommIsr() every time puts in 1 rather symbol after the buffer, causes to input the indicator backward to move 1; When moves to most right side, the indicator should circulate moves to buffer’s left side; When the input pen travel to outputs right side the indicator l, the buffer is “full”, this time then cannot put in the character again to the buffer. Short note data reduction program GetShortMsg() takes out 1 character every time from the buffer, outputs pen travel l, the method with inputs the indicator. When outputs, inputs the indicator superposes, the buffer is “spatial”. Every 1 character which the serial port receive interrupt routine will receive in the work puts in the buffer according to the order, but the short note data reduction program takes out each character according to the order from the buffer, both formation “producer and consumer” the relations, as shown in Figure 2.

When work the system master routine Yamagimachi by momentarily inspects in the buffer whether to have the receive data (i.e. inspection buffer whether is “spatial”), but to reduce data reduction program the expenses, may, when the receive procedure receives a complete frame only then uses some kind of signal or the symbol notice master routine carries on, then transfers short note data reduction program processing by the master routine. May know through the analysis, when GSM module transmitter data generally finished with continual two character OxD and OxA, therefore then the MCU serial port receive procedure might when received OxD and 0xA establish the symbol or the sending a letter number, after the data reduction program inspected the symbol, gains, in the analysis buffer short note. In the short note including the transmitting end SIM card number, the data reduction program judges according to the above whether for this system’s valid data, then if reads data. This way already may utilize in “the preceding backstage” the way, may also use in the RTOS way.

The receive buffer’s management involves the data and the function are as follows:


Used the short note using the above method on the MCS-5l series monolithic integrated circuit to realize the data transmission successfully, the system work has been stable, takes the resources to be few, has not presented the phenomenon which the mailbox stopped up.