Вы находитесь на странице: 1из 12

GSM

The aim of the project is to design an embedded wireless device that can control and monitor other devices and inform the status to the user. This controller is extremely handy at places where we have to control some devices but no wired connection is available. To implement this, a GSM modem is connected to a programmed microcontroller which would receive the SMS from a reference cell phone. It will extracted the received SMS and changed to microcontrollerpreferred format. We have selected GSM because the ubiquity of its standard makes international roaming very common between mobile phone operators, enabling subscribers to use their phones in many parts of the world. AT commands were used for controlling the functionality of modem.

GSM modems:
A GSM modem is a wireless modem that works with a GSM wireless network. A wireless modem behaves like a dial-up modem. The main difference between them is that a dial-up modem sends and receives data through a fixed telephone line while a wireless modem sends and receives data through radio waves. There are several types of modems out there. Some shown below:

Fig: Wavecom fastrack Supreme GSM Modem

Fig:SIMCom

Fig: Telit GM862-QUAD GSM Modem

We will choose the module later. First introduce you with "AT command".

What is AT Command?
AT commands are instructions used to control a modem. AT is the abbreviation of ATtention. Every command line starts with "AT" or "at" and the command is terminated by a carriage return ("Enter" key in keyboard). That's why modem commands are called AT commands. Note that the starting "AT" is the prefix that informs the modem about the start of a command line. It is not part of the AT command name. For example, +CMGS is the actual AT command name in AT+CMGS. The general syntax of AT commands is straightforward. The syntax rules are provided below.

Syntax rule 1 All command lines must start with "AT" and end with a carriage return character ("Enter" key in keyboard). In a terminal program like HyperTerminal of Microsoft Windows, you can press the Enter key on the keyboard to output a carriage return character. The ASCII value of carriage return is 13 and string value is "\r".

Syntax rule 2 A strings is enclosed between double quotes. Example: To read all SMS messages from message storage in SMS text mode (at this time you do not need to know what SMS text mode is. More information will be provided later in this SMS tutorial), you need to assign the string "ALL" to the AT command, like this:

AT+CMGL="ALL"

Syntax rule 3 Information responses and result codes always start and end with a carriage return character and a linefeed character.

Example: After sending the command line "AT+CGMI " to the mobile device, the mobile device should return a response similar to this: LF CR Nokia LF CR LF CR OK LF CR The first line is the information response of the AT command and the second line is the final result code. CR and LF represent a carriage return character and a linefeed character (ASCII = 10; string = \n) respectively. The final result code "OK" marks the end of the response. It indicates no more data will be sent from the mobile device to the PC. When a terminal program such as HyperTerminal of Microsoft Windows sees a carriage return character, it moves the cursor to the beginning of the current line. When it sees a linefeed character, it moves the cursor to the same position on the next line.

(Note: CR = '\r'

LF = '\n')

Case Sensitivity of AT Commands


In the SMS specification, all AT commands are in uppercase letters. However, many GSM/GPRS modems and mobile phones allow you to type AT commands in either uppercase or lowercase letters. For example, on Nokia 6021, AT commands are case-insensitive and the following two command lines are equivalent:

AT+CMGL

at+cmgl

The ETSI GSM 07.07 (3GPP TS 27.007) specifies AT commands. The AT command list can be found in their website. However, as my application limited to SMS, only the SMS related AT commands were explained below.

AT commands related to SMS


1) ATE0 Turn off echo This command is used to determine whether or not the modem echoes characters received by an external application. For example if you send the following command: "AT", then modem will simply reply: "OK". But if echo is turn on then it will reply:

LF CR AT LF CR LF CR OK LF CR It will reply first what he receive and then the response. It should be off for less traffic.

2) AT+CNMI New message indication This command selects how modem will behave when a new SMS will come. See AT command sheet for more explanation of the parameters.

We will use above configuration (AT+CNMI=2,1,0,0). When new msg received, module send following string:

CMTI: "SM",1
This mean, a new msg received which is stored in SIM memory (SM) and this msg's index number is 1.

3) AT+CPMS Preferred Message Storage This command allows the message storage area to be selected (for reading, writing, etc).If you want to know what memory storage your modem supports, then write:

AT+CPMS = ?
(*by giving "=?" after any AT command you can find what parameter your modem supports)

If you need to know what your modem's default storage, write:

AT+CPMS?
(*by giving "?" after any AT command you can find default parameter) As I am going to use SIM memory, so AT command will be:

AT+CPMS = "SM"
Also you can use: SM: SMS message storage in SIM (default) BM: CBM message storage (in volatile memory). SR: Status Report message storage

4) AT+CMGF - Text Mode This command is to select in which mode you handle msg. There are two types: PDU mode and Text mode. PDU mode is a little complex, I bet you dont want to know about it. So I prefer Text mode, which is AT+CMGF=1;

5) AT+CMGR Read Message This command allows the application to read stored messages.

6) AT+CMGD Delete Message This command is used to delete one or several messages from preferred message storage.

7) AT+CMGS Send Message This command is for sending SMS. Write: AT+CMGS="phone number"

Example: AT+CMGS=+8801911193901 After that a prompt(>) will return from modem. Then simply type your msg and at the end enter a "Ctrl-Z" character (ASCII 26). Your msg will be send with OK confirmation. The text can contain all existing characters except "Ctrl-Z" and "ESC" (ASCII 27).

7) AT+IPR Baud Rate

In wavecom the default baud rate is 152000bps, whereas in Telit it is 9600bps. Not all microcontroller support that much speed. So before use any module read datasheet carefully. To check your module's baud rate write:

AT+IPR?
To set your preferable baud rate, write:

AT+IPR = 9600
But if you now restart your module, the default baud rate it had earlier, will set again. So if you want to change your module's baud rate permanently, after change the baud rate, you have to save it in the module. The AT command for it is:

AT&W
This command save all the configuration it has, at the time of this code execute.
(Note: At the end of all AT command you should send Carriage Return (CR) and some module also need Line Feed (LF) character with CR.)

AT commands related to call

1) ATD calling a number This command is used to make the GSM calling any number and write as shown

ATDxxxxxxxxxxxxx; Where xxxxxxxxxxx is the number that you want to call


2) ATA-call answer This command is used to answer any coming call to the GSM

3) ATH-hanging up This command is used to hang up any coming call to the GSM 4) AT+CLIP

This command allows the GSM to send the number of the calling persons when receiving a new call .If you want to know what is its allowable values, then write:

AT+CLIP = ?
(*by giving "=?" after any AT command you can find what parameter your modem supports)

If you need to know what your modem's default, write:

AT+CLIP?
(*by giving "?" after any AT command you can find default parameter) As I want to show the persons numbers, so AT command will be:

AT+CLIP = 1
Also you can use: 1: show the number of any received calling 0: don't show the number of any received calling

That is the end of AT commands explanation.

I used following configuration for my project: ATE0 // Echo off

AT+IPR = 9600 // Set baud rate AT+CLIP = 1 // show the number of any received calls AT+CMGF=1 // Text Mode

AT+CNMI=2,1,0,0,0 // Identification of new sms AT+CPMS="SM","SM","SM" // Message Stored in SIM AT&W // Save all the configuration

Before you connect your MCU with GSM modem you need to check theses commands manually. You can sending these commands to GSM modem from PC by some 'Terminal' software. I'll discuss two of them. If you have Windows XP OS, then by default you have 'Hyper Terminal' software. If you don't have then you can also download it. Also check this. Though I prefer 'MikroC's USART Terminal' which comes with 'MikroC Pro For AVR' compiler.

HyperTerminal
Connect your your module with PC's serial port (if your PC don't have serial port then you can use serial to usb converter. Open 'Device Manager'. Expand the category 'Ports', you will see your device is there. Note the com port it is attached with . Open 'Hyper Terminal'.

Give any name. In the Connect To dialog box, choose the COM port that GSM modem is connecting to. Then click the OK button.

The Properties dialog box comes out. Enter the port settings (8bits, baudrate-9600, Flow control - none, parity-none, stop bit - one) (not as pic shows) for your GSM modem. Then click the OK button.

Type "AT" in the main window and press Enter. A response "OK" should be returned from the GSM modem. Type "AT+CPIN?" in the main window. The AT command "AT+CPIN?" is used to query whether the mobile phone or GSM/GPRS modem is waiting for a PIN (personal identification number, i.e. password). If the response is "+CPIN: READY", it means the SIM card does not require a PIN and it is ready for use. If your SIM card requires a PIN, you need to set the PIN with the AT command "AT+CPIN=".

If you get the responses above, your GSM modem is working properly. You can start typing your own AT commands to control the GSM modem.

MikroC's Hyper Terminal

Open MikroC compiler. From the 'Tools' menu, go to 'USART Terminal'. Set all the setting as mentioned earlier. Set 'New Line Settings' as 'CR+LF' (or whatever your module supports). And then at the left top section tick 'Append New Line', so that whenever you press 'Send', CR and LF will be send with at the end of your AT command. Now you can check other AT commands.

If you have any doubts or thinking please let me know. Thank you.

In the next part I'll explain the hardware and in the third part the code. Till then happy programming.

Вам также может понравиться