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

How to transmit to GSM module

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



Joined: 10 Nov 2008
Posts: 16
Location: Malaysia

View user's profile Send private message Yahoo Messenger

How to transmit to GSM module
PostPosted: Sat Mar 21, 2009 4:41 am     Reply with quote

This response from my modem.

Code:
\0A21/2009 18:07:07.421 --> Latitude:AT+CMGF=1                                                                 
OK                                                                             
AT+CMGS="0129669558"                                                           
 > Latitude:0300.5810.N \0D                                                                     
--> +CMS ERROR: invalid text mode parameter\0D     




Code:
rs232(baud=4800,parity=N,xmit=PIN_C5,rcv=PIN_C4,bits=8,stream=GPS,errors)//data from GPS to PIC
#use rs232(baud=115200,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8,stream=GSM1,errors)// data from PIC to PC
#byte portc=7


char k;
char i;
char buffer[80];                                       
char busca[]="GPGGA";
const int cr=0x0D; // PIC press ENTER
const int cz=0x1A; // PIC press Control-Z

void main() {

set_tris_c(0x90);
setup_adc_ports(NO_ANALOGS);
setup_adc(ADC_OFF);
setup_spi(FALSE);
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
   
    do
      {   
         while ( fgetc(GPS) != 36 );             
         for (k=0;k<17;k++)
         buffer[k]=fgetc(GPS); 
      } while (strncmp(buffer,busca,5)!=0);     
         {k=0;
            while (i!="*" && k<12)
             {
              i = fgetc(GPS);
               buffer[k++]= i;
             }
         }
   
    fprintf (GSM1, "AT");
    fputc (cr, GSM1);                      // send ENTER (carriage return) signal
    delay_ms (2000);                       // wait half second
   
   fprintf (GSM1, "AT+CMGF=1");
   fputc (cr, GSM1);
   delay_ms (2000);
   
   fprintf (GSM1, "AT+CMGS=\"0129669558\"");
   fputc (cr, GSM1);
   delay_ms (2000);

   fprintf(GSM1,"\n\n\rLatitude:%s",buffer);
   fputc (cz,GSM1);
   delay_ms (2000);
   //fputc (cr,GSM1);
     
   
}


I want to tansmit data from gps to gsm.But i got error msg.It said "invalid text mode parameter".What the problem with the code? Question
FvM



Joined: 27 Aug 2008
Posts: 2337
Location: Germany

View user's profile Send private message

PostPosted: Sat Mar 21, 2009 7:03 am     Reply with quote

There are at least two errors, that potentially can cause failure of the code:
- i is uninitialized in while (i!="*" && k<12)
- terminating \0 isn't missing in buffer

The latter may cause failure of the CMGS action by sending an unprintable character.

Also your said "response from modem" doesn't seem exact, where you got e.g. the "-->"? An exact hexdump of both directions would be better to understand, what's going wrong.

As a more general comment, your method of decoding NMEA-0183 seems rather dubious, it would be better to use field delimiters rather than fixed length. I don't see, that NMEA specifies a certain field length.
syide



Joined: 10 Nov 2008
Posts: 16
Location: Malaysia

View user's profile Send private message Yahoo Messenger

PostPosted: Sat Mar 21, 2009 7:41 pm     Reply with quote

I am able to print

Quote:
AT+CMGS="0129669558"

Latitude:0300.5810,N,


if i connect directly to hyperterminal without using modem.

Code.

Code:


#use rs232(baud=4800,parity=N,xmit=PIN_C5,rcv=PIN_C4,bits=8,stream=GPS,errors)//data from GPS to PIC
#use rs232(baud=115200,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8,stream=GSM1,errors)// data from PIC to PC
#byte portc=7


char k;
char i;
char buffer[80];                                       
char busca[]="GPGGA";
const int cr=0x0D; // PIC press ENTER
const int cz=0x1A; // PIC press Control-Z

void main() {

set_tris_c(0x90);
setup_adc_ports(NO_ANALOGS);
setup_adc(ADC_OFF);
setup_spi(FALSE);
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
   
    do
      {   
         while ( fgetc(GPS) != 36 );               // wait  $
         for (k=0;k<17;k++)
         buffer[k]=fgetc(GPS);   // store first 6 chars toel buffer[]  (GPGGA)
     
      } while (strncmp(buffer,busca,5)!=0);       // compare if the first five chars are GPGGA, if not, keep searching
         k=0, i=0;
            while (i!="*" && k<12)
             {
              i = fgetc(GPS);
               buffer[k++]= i;
             }
              buffer[k++] = '\0'; //terminate buffer
         
   
    fprintf (GSM1, "AT");
    fputc (cr, GSM1);                      // send ENTER (carriage return) signal
    delay_ms (2000);                       // wait half second
   
   fprintf (GSM1, "AT+CMGF=1");
   fputc (cr, GSM1);
   delay_ms (2000);
   
   fprintf (GSM1, "AT+CMGS=\"0129669558\"");
   fputc (cr, GSM1);
   delay_ms (2000);

   fprintf(GSM1,"\n\n\rLatitude:%s",buffer);
   fputc (cz,GSM1);
   delay_ms (2000);
   //fputc (cr,GSM1);
     
   
}


By the way "-->" didn't have in modem response.It is from hyperterminal.I dun know how to do hexdump.



Thank u
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