CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

GSM with PIC interface Help needed!!!

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
aldinlapinig



Joined: 16 Dec 2005
Posts: 22

View user's profile Send private message

GSM with PIC interface Help needed!!!
PostPosted: Tue Aug 08, 2006 2:33 am     Reply with quote

Hello all,

I am developing a program that will interface a GSM module with PIC through RS232. Can anybody who have tried doing this give me an idea on how I could analyze the reponse from the GSM module evry after I send an AT command to the it? To make this clearer, I'll explain the process I did which unfortunately stuck me up because I couldn't come up with a better algorithm to analyze the reponses of the GSM. Here are what I did: (actually, what the program will do)

* I send AT command to the gsm module.

* I wait for a coressponding time (depending on the command I send) for the response to be received in the serial input buffer.If data is available within the specified time, I read it. Otherwise communication error will be declared.

Example:
tx : "AT"<cr>
rcv : AT<cr><cr><lf>OK<cr><lf>

tx : "AT+IPR=38400"<cr>
rcv : AT+IPR=38400<cr><cr><lf>OK<cr><lf>

tx : "AT+CPIN"<cr>
rcv : AT+CPIN<cr><cr><lf>+CPIN: READY<cr><lf><cr><lf>OK<cr><lf>

Now, the problem I am encountering is that, the module would give me different responses on different AT commands (which is normal) and I don't know how to make a better algorithm for my program to get a certain part of the response I need. I got no problem with the first 2 of the examples above because I only need to get the "OK" status. The problem is detecting other responses and status of the communication like device is "READY" message is "READ" or "UNREAD", the "ERROR ###"... and so on... Is there any other way aside from parsing the data I receive? It would create a very long program to extract the status of the communication just to extract "OK", "READY", "REC READ", ERROR", the "ERROR ###"... Hope I stated the problem clearly enough... thanx guys. Need your help on this.

Have a good day!

kind regards,

aldin
jaime



Joined: 25 Nov 2005
Posts: 56
Location: Porto - Portugal

View user's profile Send private message Visit poster's website

PostPosted: Tue Aug 08, 2006 3:57 am     Reply with quote

I have a litle system that uses a cell phone to control a light.

I use state machine to do the job. I use a outine to read rx interrupt and then analyse what the cell phone sends...

This is my rda routine

Code:
#int_rda
void trata_rda()
/*
two examples of what we can receive
case 1:
LF CR O K CR LF
case 2:
LF CR + C P B R: xxxxxxxxxxxxxxx CR LF CR LF O K CR LF
the program must detect only the LF if it's not CR or LF the program puts in the
buffer[x]
*/
{
temp=getc();
if(temp==0x0A)
   {
   if(!start_pack)
      {
      start_pack=true;                     //start of message
      x=0;
      }
   else if(start_pack && buffer[0]=='+' && !middle_pack && !ok_pack)
      middle_pack=true;
   else if(start_pack && buffer[0]=='+' && middle_pack && !ok_pack)
      ok_pack=true;
   else
      {
      receive_pack=true;                   //we got the message
      buffer[x]=0;
//uncomment the next line to debug     
//printf("buffer=%s\r",buffer);
      }
   }
else if(temp!=0x0A && temp!=0x0D && !ok_pack)
   {
   buffer[x]=temp;
   x++;
   }
}


This is my debug function
Code:
void debug_data()
{
/*
when receive something in the buffer[] we debug to know what's inside
we can have in buffer[] 2 things.
case 1:
short message like:
OK, RING, ERROR, BUSY, NO DIAL TONE.
this type of message only actives a flag
case2:
Long message like:
+CLCC:...
+CPBR:...
this type of message we must decode inside the message
*/

if(!middle_pack)
   {
   if     (buffer[0]=='O')                //receive OK
      ok=true;
   else if(buffer[0]=='R')                //receive a ring
      ring=true;
   else if(buffer[0]=='A')                //receive a echo
      ok=true;
   else
      error=true;                         //receive another short message
   }
else
   {
                                          //ve se o que recebeu � um +clcc
   if(buffer[2]=='L' && buffer[3]=='C' && buffer [4]=='C')
      {
      clcc=true;
      incognito=true;                     //� um clcc. pesquisa a flag recebida
      for(f=1;f<=x;f++)                   //the caller number is inside "  "
         {
         if(!achei && buffer[f]==0x22 )   //procura a primeira aspa 0x22 = "
            achei=true;
         else if(achei && buffer[f]!=0x22)//estamos dentro das aspas. guarda o
            {                             //numero chamador
            chamador[i]=buffer[f];
            i++;
            chamador[i]=0;
            incognito=false;
            }
         else if(achei && buffer[f]==0x22)//segunda aspa indica q acabou o nume
            break;                        //ro chamador
         }
      }
   else if(buffer[2]=='P' && buffer[3]=='B' && buffer [4]=='R')
      {
      cpbr=true;
      for(f=1;f<=x;f++)                   //the number is inside " "
         {
         if(!achei && buffer[f]==0x22 )   //0x22 = "
            achei=true;
         else if(achei && buffer[f]!=0x22)
            {
            permitido[i]=buffer[f];
            i++;
            permitido[i]=0;
            }
         else if(achei && buffer[f]==0x22)
            break;
         }
      }
   else if(buffer[2]=='P' && buffer[3]=='B' && buffer [4]=='S')
      {
      cpbs=true;                          //the lengh of the card is after,
      for(f=1;f<=x;f++)
         {
         if(!achei && buffer[f]==0x2C )   //0x2D = ,
            achei=true;
         else if (!encontrei && achei && buffer[f]==0x2C)
            encontrei=true;
         else if(encontrei)
            {
            maximo[i]=buffer[f];
            i++;
            maximo[i]=0;
            }
         }
      sim=atoi(maximo);                    //convert ascii to decimal
      }
   }
   start_pack=middle_pack=ok_pack=false;  //reset das flags de controlo
   receive_pack=false;
   achei=encontrei=false;
   i=f=0;
   x=0;
   buffer[0]='0';
   i=0;
}


Hope it helps
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group