27-02-2013, 02:24 PM
AVR323: Interfacing GSM modems
Interfacing GSM.pdf (Size: 247.61 KB / Downloads: 17)
Features
• Interface to GSM modems.
• Implementation of AT-Command set.
• PDU string compression and decompression.
• SMS transmission, how to send and receive.
Introduction
The GSM net used by cell phones provides a low cost, long range, wireless communication channel for applications that need connectivity rather than high data rates. Machinery such as industrial refrigerators and freezers, HVAC, vending machines, vehicle service etc. could benefit from being connected to a GSM system.
Take a given example. A garage offers a very special package to their customers. Based on the mechanics knowledge and the given vehicle, tailored service intervals can be specified. A part of the service agreement is installation of a GSM modem in the vehicle. An onboard service application can then notify the garage when the vehicle approaches its service interval. The garage will schedule an appointment and inform the customer.
The customer will benefit from a reliable and well-serviced vehicle at a minimum cost. The garage on the other hand can provide excellent customer support, vehicle statistics, efficient work scheduling, and minimum stocks.
This application note describes how to use an AVR to control a GSM modem in a cellular phone. The interface between modem and host is a textual protocol called Hayes AT-Commands. These commands enable phone setup, dialing, text messaging etc. This particular application connects an AVR Butterfly and Siemens® M65 cellular phone using a RS232 based data cable. Most cellular phones could be used, except Nokia® phones using F or M-bus.
Theory of operation
The protocol used by GSM modems for setup and control is based on the Hayes AT-Command set. The GSM modem specific commands are adapted to the services offered by a GSM modem such as: text messaging, calling a given Phone number, deleting memory locations etc. Since the main objective for this application note is to show how to send and receive text messages, only a subset of the AT-Command set needs to be implemented.
The European Telecommunication Standard Institute (ETSI) GSM 07.05 defines the AT-Command interface for GSM compatible modems. From this document some selected commands are chosen, and presented briefly in this section. This command subset will enable the modem to send and receive SMS messages. For further details, please consult GSM 07.05.
New Message Indication (AT+CNMI)
“AT+CNMI” configures how the modem signals arrival of new messages to the connected terminal device and how they are stored in the modem. This feature is useful when it comes to reading new messages. Instead of polling the modem periodically for arrival of new messages, “AT+CNMI” can tell when a new message has arrived. The AVR will catch such indication, and set a flag. This ensures that the modem only takes up CPU resources when necessary.
Message format(AT+CMGF)
The “AT+CMGF” command is used to set input and output format of SMS messages. Two modes are available:
• PDU mode: reading and sending SMS is done in a special encoded format.
• Text mode: reading and sending SMS is done in plain text.
PDU mode is described later in section 2.2. This compressed format saves message payload and is default on most modems. PDU mode is implemented in the source code for this application note, it is possible to use text mode to reduce code footprint if the connected modem supports this.
In text mode header fields as sender address, message length, validation period etc. can be read out in plain text together with the sent message.
Send Message(AT+CMGS)
This command enables the user to send SMS messages. Section 2.2.3 describes how to build such messages. How to include user defined text and recipient telephone number. After the user defined fields are set, the message can be compressed and sent using the “AT+CMGS” command. An example usage of “AT+CMGS” is given in section 2.2.3.
PDU format explained
There are two ways of sending and receiving SMS messages: by text mode and by PDU (Protocol Description Unit) mode. By default most phones and modems are setup to send SMS messages using a special compression format (PDU-mode).
Some modems supports text-mode, in which any information and the message itself can be read as plain text. Note however that not all phones and modems support text-mode.
Building and sending a message in PDU mode
The SMS message, as specified by the ETSI organization, can be up to 160 septets long. The maximal user payload is then restricted to 140 octets, together with additional fields in the PDU protocol. These additional fields are crucial since they contain information about receivers-address, address length, validity-period, type of address, data coding scheme, protocol identifier etc.
A message sent from modem to a service center is called an SMS-SUBMIT message. Table 2-12 shows how to build such messages. To avoid any problems with manufacturer specific meta-data, the modem is set to do this using the “00” option. Rest of the protocol stack is defined according to GSM 03.40.