Continue to Site

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.

Needs code to send AT commands for SMS PDU format

Status
Not open for further replies.

amila133

Member level 4
Joined
Oct 13, 2009
Messages
72
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,288
Location
Sri Lanka
Activity points
1,746
I was able to dial the phone using PIC. My phone only support for PDU format.


I studied about PDU format and I sent SMS using Hyperterminal in PC through serial port.

But when I applied same methodology in PIC it doesn't work.

I need some code example to do it.If you have please send me. This is my code.

Code:
int i=0;
int j=0;



void main(){

          const unsigned char para[3]="AT";
          const unsigned char pdumode[10]="AT+CMGF=0";  //select pdu mode (o is given ; 1 is given for text mode)
          const unsigned char dial[17] ="ATD0716530115;\n\r";
          const unsigned char tpdu_length[11]="AT+CMGS=16";          //length of the  message
          const unsigned char message1[47]="069149170000F311000B914917560311F50000AA02C822";      //message
          unsigned short receive;
           //toPDU("It is easy to send sms messages", send);

           Usart_Init(9600);
           TRISB=0;
           PORTB=0;

           while(1) {
     

                    for(i=0;i<3; i++){
                            Usart_Write(para[i]);      //type at
                            Delay_ms(200);
                      }
                       Usart_Write(0x0D);
                     if(Usart_Data_Ready()){
                        PORTB=1;
                        Delay_ms(4000);
                        PORTB=0;                      //set pdumode
                        for(i=0;i<10;i++) {
                          //if(command1[i]=='\0') break;
                          Usart_Write(pdumode[i]);
                          Delay_ms(200);
                        }
                        Usart_Write(0x0D);
                       if(Usart_Data_Ready()){
                              PORTB=1;
                              Delay_ms(4000);
                              PORTB=0;
                               for(i=0;i<11;i++) {
                                    //if(command1[i]=='\0') break;
                                    Usart_Write(tpdu_length[i]);     //length of the message
                                    Delay_ms(200);
                                    }

                                    Usart_Write(0x0D);   //enter
                                    if(Usart_Data_Ready()){
                                          PORTB=1;
                                          Delay_ms(4000);
                                          PORTB=0;
                                          for(i=0;i<47;i++){     //send message
                                                //if(command1[i]=='\0') break;
                                                Usart_Write(message1[i]);
                                                Delay_ms(200);
                                          }
                                          PORTB=1;
                                          Delay_ms(500);
                                          PORTB=0;

                                          Usart_Write(26);    //ctrl+z
                                          PORTB=1;
                                          Delay_ms(7000);
                                          PORTB=0;
                                          if(Usart_Data_Ready()){

                                                                 

                                           for(i=0;i<17;i++){        //dial really starting
                                           if(dial[i]=='\0') break;
                                           Usart_Write(dial[i]);
                                           Delay_ms(200);
                                                               }

                                           PORTB=1;
                                           Delay_ms(1000);
                                           PORTB=0;

                                    }
                                    
                         }
                     }
                     
                     
                     
                     


        

            }
}
}



Thank You very much
 

Hii amila,

What Phonecell do you use?

I think you forgot to close the AT Command with carriage return.

Example :

For sending AT you must send => "AT" + char(0x0D) (this carriage return character). If your connection is okay, then the cellphone will send you "OK" character. I think you must check this character first to check connection, using polling methode or interrupt methode.

for sending SMS using PDU Mode ==> "AT+CMGF=5" + char(0x0D) (sending 5 character). If the command is correct, cellphone will reply with character ">" or char (0x13). So you must check this character first before you send the pdu format. At the end of the PDU format you must add CTRL-Z or chr(26).

I have sample program for 8051 in C(I never used PIC before). if you need, I will send to you.

Hope this help.

Deny(Bodat'z)
 

    amila133

    Points: 2
    Helpful Answer Positive Rating
Thank You very much for your reply.
I did what you have said.
when I send messages through HyperTerminal It is OK But when it senda from PIC it shows CMS ERROR:304.

I just connected phone to PIC
TX(PIC)->RX(Phone)
RX(PIC))->TX(Phone)
GND(PIC)->GND(Phone)
with this connections all the other commands are OK including dial command.It gets error only for SMS.

Can you send your program and circuit diagram.


Thank You
 

I think, you must convert between TTL and RS232 logical voltage levels. PIC uses 5V, while phone probably uses 3v3 or 2v7 voltage level. You can use Zenner diodes or chip from maxim (max232).
If I am wrong, please someone correct me
 

Hi,

I did it using MAX232. But it not works. Without MAX232 I can do all the commands successfully except sending SMS(in PDU mode).(Error is +CMS 304). I can send SMS using HyperTerminal not in PIC.

Thanx.
 

Am also working on the similar project, i need the microcontroller to instruct the phone to send SMS after detection of intrusion, i nitially i had at89c51 and had even written code but i lost it, now am only having pic16f84 but have no code for this, can any one help pliz?
thanks in advance
 

Hi Amila,

You said you manaded to make a call using AT commands. Did you send AT command from a micro controller. If so please help me out on how you didi that. i am also trying/failing with the same project.

Thanks
 

Thing to not Forget :


PC ----> to Max232 = Non Inverted
PIC ---> to Max232 = Inverted
PIC ---> to Max232 to Max232 = Non Inverted

etc..

Don't bother with Wire,use Bluetooth Module To Communicate with Phone


lot of protocol supported, ex: Dun,MAp,etc



hope this help
 

@ the_balistic
can u give a c sample code for 8051 and diagram i want to do work on interfacing and sending sms using microcontroller 8051 so ur code give me a start point
thank u
 

Hi amila and the_balistic,
I am doing a school project using Smart TM1 GSM module to send SMS. However, I fail to test any single AT commands from this GSM module. Could you send me a simple code to test AT commands from this GSM module? Do we need to use interrupt in this case? My email is quangtientruong@gmail.com
Thanks a lot.
Quang Tien
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top