Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[SOLVED] Sending SMS command thro' USART to GSM Modem error - PIC18F452

Status
Not open for further replies.

speedEC

Full Member level 6
Joined
Apr 1, 2011
Messages
337
Helped
23
Reputation
46
Reaction score
21
Trophy points
1,298
Activity points
4,326
Dear Sir,

I am using PIC18F452 MCU (MPLAB IDE v8.63 and MPLABC18 v3.37.01) to communicate SIMCOM300 GSM Modem. I connected and it works fine. But when I send SMS Command it gives error. I think I am doing wrong in sending string through USART. The code is follows.

*I have to send the Command as AT+CMGS="1234567890"

Code C - [expand]
1
2
3
4
5
6
7
8
char strBuff_IncomingPhNum[11]; 
 
putrsUSART((const far rom char*)"AT+CMGS=");
putcUSART(0x22);
putrsUSART((const far rom char*)"9123456789"); 
//putsUSART(strBuff_IncomingPhNum);
putcUSART(0x22);
putcUSART(0x0D);


AT+CMGF=1 text mode enabled at start up. Also Echo off (ATE0) done at start-up.

The following code works (for Dialing):

Code C - [expand]
1
2
putrsUSART((const far rom char*)"ATD+123456789;");   
putcUSART(0x0D);


I tried with store the phone number into strBuff_IncomingPhNum (data -ram - memory). [Declared as char strBuff_IncomingPhNum [11]].
But still I am getting error.

Can anyone help me to solve this issue? Advance thanks.
 

are

Advanced Member level 4
Joined
Nov 16, 2004
Messages
111
Helped
17
Reputation
34
Reaction score
12
Trophy points
1,298
Location
Balen (Belgie)
Activity points
644
why use ascii code x22 (DC2) do you mean ASCII x12 (LF)?
 

speedEC

Full Member level 6
Joined
Apr 1, 2011
Messages
337
Helped
23
Reputation
46
Reaction score
21
Trophy points
1,298
Activity points
4,326
why use ascii code x22 (DC2) do you mean ASCII x12 (LF)?

0x22 is Hex code for "Double Quotes".

---------- Post added at 12:01 ---------- Previous post was at 11:49 ----------

use +91 in front of the number and send 0x0a and 0x0d after every command..........

Thanks for the response Mr.ckshivaram. I have modified the code as you told. But still I am getting same error. I have also worked with PIC16F877A and 'puts' and 'putch' USART commands works fine there. Any help please?
 

speedEC

Full Member level 6
Joined
Apr 1, 2011
Messages
337
Helped
23
Reputation
46
Reaction score
21
Trophy points
1,298
Activity points
4,326
you should not send double quotes when you send command...........

If you don't mind, The SMS command that we have to send is
AT+CMGS="1234567890"
So we should send "AT+CMGS=" Dbl Quotes 1234567890 DblQuotes <Enter Key-0x0D>

Without sending Dbl quotes the modem will give the error. Am I right?
 

nandhu015

Advanced Member level 5
Joined
Feb 11, 2006
Messages
1,965
Helped
300
Reputation
600
Reaction score
224
Trophy points
1,353
Location
India
Activity points
9,854
I have modified the code as you told. But still I am getting same error.

You havn't mentioned what error you are getting?

The following sequence is working fine for me
AT+CMGS = "xxxxxxxxxx" 0x0d
The modem will respond with ">"
Then you have to send the content of the message and send escape character ie. 0x21
 

speedEC

Full Member level 6
Joined
Apr 1, 2011
Messages
337
Helped
23
Reputation
46
Reaction score
21
Trophy points
1,298
Activity points
4,326
You havn't mentioned what error you are getting?

The following sequence is working fine for me

The modem will respond with ">"
Then you have to send the content of the message and send escape character ie. 0x21

Thanks Mr. nandhu015. I receive only 'Error' message and not any specific error message like +CME ERROR or +CMS ERROR. The same command works fine on PIC16F877A (using Hi-Tech C Compiler). But here(MPLAB C18) not works. I don't know why? The modem not displaying '>' char. Just throw Error after the AT+CMGS command.

I checked whether AT+CMGF=1 executed correctly before sending AT+CMGS. Its correct. After disconnecting serial port and reconnect with Hyperterminal and try to send SMS using AT+CMGS, it also works fine.

---------- Post added at 14:35 ---------- Previous post was at 14:24 ----------

Dear Mr. Nandhu,
I checked with SMS command AT+CMGR=1 at the place of AT+CMGS.

putrsUSART((const far rom char*) "AT+CMGR=");
putrsUSART((const far rom char*) "1");
putcUSART(0x0D);

(OR)

putrsUSART((const far rom char*) "AT+CMGR=1");
putcUSART(0x0D);

Both commands work fine.

---------- Post added at 14:38 ---------- Previous post was at 14:35 ----------

For your information, I used inside the interrupt handler.

---------- Post added at 15:29 ---------- Previous post was at 14:38 ----------

Thanks Dear Mr. Sivaram and Nandhu. I have added some delay before issuing AT+CMGS command and inbetween the 0x0D. Now everything works perfect.

The working code is:

Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
[B]for(i=0;i<20000;i++){
}
[/B]
putrsUSART((const far rom char*)"AT+CMGS=");
putcUSART(0x22);
putsUSART(strBuff_IncomingPhNum);
putcUSART(0x22);
                    
[B]for(i=0;i<10000;i++){
}
[/B]
putcUSART(0x0A);
putcUSART(0x0D);



Once again thanks to both of you and all.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top