Sunteți pe pagina 1din 13

SIM900 SMS and Call Commands

http://www.raviyp.com/embedded/182-sim900-sms-call-commands
This article describes the AT commands for reading, sending and deleting SMS from the SIM900 GSM
modem inbox. Before you send any SMS or CALL command to the SIM900 modem via the UART interface
after power up, wait for the CALL READY message from the SIM900.

The CALL READY message from the SIM900 indicates that the modem is powered up and has acquired a
valid network. Next thing is to make sure you have set the SIM900 into TEXT mode by sending the
command AT+CMGF=1; followed by a carriage return(\r\n).
If you are facing any problem with respect to modem not responding to commands read my previous article
to solve it.. it applies to SIM900 problems too.

Reading a SMS message from the Inbox:

To read the first SMS from the inbox send the command AT+CMGR=1 followed by \r\n. The modem will
reply with the text of the first SMS in the inbox along with senders mobile number and date and time.

To read the second SMS from the inbox send the command AT+CMGR=2 followed by \r\n. The modem will
reply with the text of the second SMS in the inbox along with senders mobile number and date and time.

... and so on. The maximum number of SMS messages in the inbox depends on the SIMCARD you have put
in the modem.

To read all the SMS messages from the inbox send the command AT+CMGL=ALL followed by \r\n. The
modem will reply with the text, senders number, timestamp of the all the messages in the inbox in one shot.

Sending SMS message from SIM900:

To send SMS from SIM900 send the command AT+CMGS=9900243245 followed by /r/n and then the
message text and then the ascii code of Ctrl^Z character which is 0x1A

ex: To send "Hello" to 9900243245 mobile number


1

AT+CMGS=9900243245 followed by \r\n


Hello
Ctrl^Z ascii code 0x1A followed by \r\n (Ascii code for \n is 0x0A and Ascii code for \r is 0x0D)

Deleting a SMS message from the Inbox:

To delete the first message from the inbox send the command AT+CMGD=1 followed by \r\n. The modem
will delete the first message in the inbox.

To delete the second message from the inbox send the command AT+CMGD=2 followed by \r\n. The modem
will delete the second message in the inbox.

... and so on. The maximum number of messages in the inbox depends on the SIMCARD you have put in the
modem.

Calling to a number using SIM900:

To call to a number send the command ATD followed by the mobile number and carriage return ,

To call the mobile number 9900243245 send the command as,


ATD9900243245 \r\n

Hanging up a call in SIM900:

To hang up a ringing call or a call in progress send the command ATH; followed by carriage return

ATH\r\n

Recieving a call in SIM900:

To receive a ringing call, Send the command ATA; followed by carriage return

ATA\r\n

Finding the number of the incoming call in SIM900:


2

To get the number of the incoming call you need to enable the Caller Line Identification in SIM900.

To enable the incoming caller line identification issue the command AT+CLIP=1 followed by carriage return

AT+CLIP=1\r\n
Once you issue this command, any incoming call will be notified in the following format,
RING
+CLIP:+9916258273
Here +9916259273 is the number of the incoming call.

GSMHandling Received SMS


This post is intended to illustrate the received SMS by a GSM module like SIM900.AT commands to handle the
received SMS are explained in detail.
We shall use a SIM900 module on RS232 breakout board & an USB-UART converter board to connect it to the PC.
Following is the setup to test received SMS using SIM900.

A terminal software like PUTTY is used to read out the COM port where GSM is connected to PC through USBUART board.
As you connect the USB-UART board to PC ,the PC allots a COM port which can be seen under
Devicemanager.Open the PUTTY terminal & set this to read the serial port.

Open the Putty terminal & type in AT .If your modem settings & connections are fine you get an OK response from
the modem.
Preferred Storage Area
To select the Storage area for SMS type in
AT+CPMS command .This sets the Preferred Message Storage area.
To know the Message areas supported by our GSM ,enter the AT command
AT+CPMS=?

As seen above ,our modem returns all 3 message storage areas as SM , which refers to the Message storage area on the
SIM card.
The first SM specifies the message storage area that will be used while Reading or Deleting SMS.
The second SM specifies the area that will be used when sending SMS from message storage or writing SMS to
storage.
The third SM specifies the preferred message storage area for storing newly received SMS.
In our case ,SM is the preferredstorage area for all SMS functions , Read , Send & Receive.
The other storage areas are ME (storage area on GSM Modem/Mobile phone) , MT (read from all storage
area associated with GSM), BM (incoming Broadcast message storage area) , SR (status report) & TA (Terminal
adapter )
To know the SMS Service center address (SMSC)
AT+CSCA?
The mobile network operators service center number will be displayed.

The number 145 in +CSCA is the address type .145 refers to International number starting with +.
SMS Modes
The next AT command
AT+CSMS=?
reports the SMS modes supported by the GSM. 0 is for Text mode & 1 is for Protocol Data Unit
(PDU)mode.Our modem reports (0,1) supporting both SMS modes.
To check if your modem supports the text mode, you can try the following command:
AT+CMGF=1
If the modem responds with OK this text mode is supported. It is possible to send only simple text messages in this
mode.
To know the current message format use the command
AT+CMGF?
Reading Messages from Storage Area

To read messages from SIM storage type in


AT+CPMS=SM

The Modem responds with + CPMS: followed by Used space & Maximum space.
In our modem there are currently 2 messages in memory (used space ) & maximum storage capacity is for 30
messages.
To list out all messages in the SM storage type in
AT+CMGL=ALL
The modem responds with a list of all messages in the storage area.

+CMGL: 1 is the Memory Index number used to read or delete message


REC READ is the status message.If the message is not Read it shows REC UNREAD
+91xxx is the phone number from where the message originated.
, Next column is the reference number of the message.Generally this field is empty.
13/09/19 is the Date & time of received SMS in yy/mm/dd,hh:mm : ss format
Finally the actual message in text format is displayed.
To list out a particular message , use the CMGR command with the index number of the message to be read.
AT+CMGR=2 to list the message at index 2
AT+CMGR=4 to list the message at index 4

Deleting Messages
To delete a message use CMGD command with the index number of message to be deleted.
AT+CMGD=1 to delete the message at index 1.

You can issue the command AT+CMGL=ALL to see that the message at index 1 is deleted.
To delete all the messages in the storage area there is no such command like AT+CMGD=ALL.
Use the following notation to delete all messages.
AT+CMGD=1,4
1 is the Index value & 4 is the flag value
To know the index & flag values allowed
AT+CMGD=?

1 to 30 can be assigned to index parameter & all five flag values from 0 to 4 are supported.
By default flag value is 0 which means Delete message at location <index>
Flag value 1 Delete all READ messages ,ignoring value of index.
Flag value 2 Delete all READ & SEND messages.
7

Flag value 3 Delete all Read,Sent & Unsent messages.


Flag value 4 Delete all messages.

You can see from above screen shot that all messages are deleted after issuing AT+CMGD=1,4.
AT+CNMI New message indication to Terminal Equipment TE.
Selects procedure how receiving of new messages from the network is indicated to the TE.
The following command sets the indicators for receiving an SMS message.
AT+CNMI=1,1,0,0,0 Set the new message indicators.
AT+CNMI=<mode>,<mt>,<bm>,<ds>,<bfr>
<mode>=1 discard unsolicited result codes indication when TA TE link is reserved.
=2 controls processing of unsolicited result codes & forward them directly to Terminal Equipment TE
<mt>=1 SMS-DELIVERs are delivered to the SIM and routed using unsolicited code.
<bm>=0 no cell broadcast message indications are routed to the TE.
<ds>=0 no SMS-STATUS-REPORTs are routed.
<bfr>=0 Terminal Adapter ( TA) buffer of unsolicited result codes defined within this command is flushed to the TE
(Terminal equipment).
The following command saves the SMS settings. Once the SMS commands have been saved, the initialization
commands do not need to be sent again until they are changed.
AT+CSAS
toSave SMS settings. This may take up to 10 seconds.

Embedded C code for the sending message through GSM module SIM 900A:

#include<reg51.h>
unsigned char *command_ATE0 = "ATE0\r";
unsigned char *command_AT = "AT\r";
unsigned char *command_CMGF = "AT+CMGF=1\r";
unsigned char *command_CMGS = "AT+CMGS=\"+9184xxxxxxxx\"\r";
unsigned char *message = "Welcome to the world of Robotics..!";
unsigned char CTRLZ = 0x1A;
void gsm();
void puts(unsigned char* ptr);
void putc(unsigned char chr);
void sendsms(void);
void initialize();
void delay(unsigned int time);

// Msg 2 be send

void main()
{
gsm();
while(1);
}

void gsm()
{
initialize();
sendsms();
}
void initialize()
{
SCON = 0x50; /*SCON: mode 1, 8-bit UART, enable receive
TMOD |= 0x20; /*TMOD: timer 1, mode 2, 8-bit

*/

TH1 = 0xFD; /*TH1: for 9600 baud


TR1 = 1;

/*TR1: timer 1 run

*/

*/
*/

}
void sendsms()
{
puts(command_ATE0);
delay(50);
puts(command_AT);
delay(50);
puts(command_CMGF);
delay(50);
puts(command_CMGS);
delay(50);
puts(message);
delay(50);
putc(CTRLZ);
}
void puts(char* p)
{
char *temp = p;

/*temp pointer so that the actual pointer is not displaced */

while(*temp != 0x00)
{
putc(*temp);
temp++;

10

}
}
void putc(unsigned char chr)
{
SBUF = chr;
while(TI==0);
TI=0;

/*Wait until the character is completely sent */


/*Reset the flag */

void delay(unsigned int time)


{
unsigned int y,z;
for(y=0;y<=time;y++)
for(z=0;z<2400;z++)
{
;
}
}

11

DB9 male wire pin 2 to DB9 female pin 3


DB9 male wire pin 3 to DB9 female pin 2
DB9 male wire pin 5 to DB9 female pin 5
left rest of all the pin non-connected
//==============================================================
C CODE TO SEND MESSAGE ON PARTICULAR NUMBER
//==============================================================
#include<reg51.h>
void serialcomm()
{
TMOD=0x20;

// Mode=2

TH1=0xfd; // 9600 baud


SCON=0x50;
TR1=1;

// Serial mode=1 ,8-Bit data,1 Stop bit ,1 Start bit , Receiving on


// Start timer

}
void delay(unsigned int value)
{
unsigned int i,j;
for(i=0;i<value;i++)
for(j=0;j<1275;j++);

12

void serial(unsigned char x)


{
SBUF=x;
while(TI==0);
TI=0;
}

void Send2Gsm(char *aaa)


{
unsigned int i;
for(i=0;aaa[i]!=0;i++)
{
serial(aaa[i]);
}
}

void main()
{

serialcomm();
Send2Gsm("AT\r\n");
delay(2);

Send2Gsm("AT+CMGF=1\r\n");
delay(2);
Send2Gsm("AT+CMGS=\"+9190163476\"\r\n");
delay(2);
Send2Gsm("hy");
serial(0x1a);

while(1);
}

13

S-ar putea să vă placă și