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 support@ccsinfo.com

can't detect that an sms is received by gsm

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



Joined: 11 Jan 2011
Posts: 42

View user's profile Send private message

can't detect that an sms is received by gsm
PostPosted: Sun Mar 30, 2014 9:11 am     Reply with quote

Hi everybody,
I am using a pic16f876 with a gsm (old Siemens mc60 cell phone) to make an sms controller. I can now send AT commands, send and receive sms. But the problem is i can't detect the reception of sms even though i have configured the gsm with the AT command "at+cnmi=1,1". I tested with my pc and hyperterminal and it's ok, when i receive an sms, i get this on the screen:
"+cmti: "ME",4
But when i connect the gsm with my pic nothing happens. Here is the code for testing that. Could you please help me?
Code:

#include <16F876.h>
#device PASS_STRINGS=IN_RAM
#fuses  XT NOWDT NOPUT NOPROTECT BROWNOUT NOLVP NOCPD NOWRT NODEBUG
#use delay(clock=4000000) // you must use this line because the LCD.C use //the delay_us() functions
#use rs232(baud=9600,UART1, ERRORS)

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define use_portb_lcd TRUE
#include <lcd.c>

void main()
{
int i;
char *reponse , buffer[86],test[14];
unsigned char rec_data;
//int lon;

SET_TRIS_A( 0xFF );
lcd_init();

lcd_putc('\f');

printf(lcd_putc,"hallo");
DELAY_ms(3000);

      reponse=NULL;     
      lcd_putc('\f');
      printf(lcd_putc,"initialisation..");
      DELAY_ms(3000);   
      printf("at\r"); //send AT command
      i=0;

      do
      {
       rec_data=getc();
      }
      while(rec_data!='\n');

      do
      {
      rec_data=getc();
      buffer[i]=rec_data;  //save response in a string
      i++;
      }while(rec_data!='K');

       buffer[i]='\o';
       reponse=strstr(buffer,"OK");//test if response is OK
 
       if (reponse == NULL)
            {
            lcd_putc('\f');           
            printf(lcd_putc,"error");
            DELAY_ms(3000);
            }
    else { 
           i=0;
           lcd_putc('\f');         
           printf(lcd_putc,"ready");    //if response is "ok" display "ready" on lcd and configure gsm   
           DELAY_ms(3000);
           printf("ate0\r");
           DELAY_ms(300);
           printf("at+cpms=""ME""\r");
           DELAY_ms(300);
           printf("at+cnmi=1,1\r");
           DELAY_ms(300);   
         } 
         
   lcd_putc('\f');       
   printf(lcd_putc,"waiting for sms");
   DELAY_ms(3000);

for(;;)
 {   
         if(kbhit())  //if sms received by gsm
           {
               i=0;           

               do
               {
               rec_data=getc();
               buffer[i]=rec_data;  //save response in a string
               i++;
               }   
               while(i!=20);

               buffer[i]='\0';
               reponse=strstr(buffer,"+C");
               strncpy(test,reponse,13);

               test[13]='\0';
               lcd_putc('\f');
               printf(lcd_putc,test); //dislay AT command response on lcd
               DELAY_ms(3000);

               rec_data=test[12];
               lcd_putc('\f');
               lcd_putc(rec_data);
               DELAY_ms(2000);   
           }
 
         lcd_putc('\f');       
         printf(lcd_putc,"waiting for sms");
    }
 }

_________________
i am newbe
Ttelmah



Joined: 11 Mar 2010
Posts: 19366

View user's profile Send private message

PostPosted: Sun Mar 30, 2014 9:27 am     Reply with quote

In C, you escape a double quote as \", not as "".
ILLIAS28



Joined: 11 Jan 2011
Posts: 42

View user's profile Send private message

PostPosted: Sun Mar 30, 2014 9:41 am     Reply with quote

Thanks Ttelmah,
I have corrected this error, but the problem is always the same. Should I use the #INT_RDA interruption or kbhit() ?
Many thanks.
_________________
i am newbe
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Sun Mar 30, 2014 5:02 pm     Reply with quote

#int RDA has several advantages over the use from kbhit(). Most important advantage is that you can receive a lot more data while the processor is doing other things like delay_ms for the display. With kbhit() you only have the 2 or 3 characters in the hardware buffer. Have a look at the example program ex_sisr.c, this uses a circular buffer approach.

One error I noticed in line 50:
Code:
buffer[i]='\o';
Here you use letter 'o' instead of number '0'.
ILLIAS28



Joined: 11 Jan 2011
Posts: 42

View user's profile Send private message

PostPosted: Sun Mar 30, 2014 5:48 pm     Reply with quote

Thank you ckielstra,
You are right, it was a o and not a 0. I have used #int_rda and it's working good.
_________________
i am newbe
Ttelmah



Joined: 11 Mar 2010
Posts: 19366

View user's profile Send private message

PostPosted: Mon Mar 31, 2014 12:45 am     Reply with quote

At least you move forward with hints. Smile

Everyone will make this sort of error. Especially if you switch between languages (the "" escape is common in some others). Key thing is to learn to be really 'suspicious' when things don't work, and look three times. Often even better, 'go away' and do something else (not to do with computing), and then come back and read the code again, and try to 'think' as you read, whether you are sure about the syntax. I find 'physical' things, like log chopping, or a bike ride, are the best debugging tool there is!....

Best Wishes
temtronic



Joined: 01 Jul 2010
Posts: 9173
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Mon Mar 31, 2014 5:21 am     Reply with quote

I agree with Mr. T's comments though I'm really, really tired of 'debugging using a snow shovel'!

I would like to add that you should put a 'delay_ms(500);' just before the 'lcd_init();'

This allows the LCD module to power up/get organized before the PIC tries to access it. It's been reported here that different modules take longer than others and might no work as expected. The delay might only need to be 100-250ms, but I've always used 500ms and never had an LCD issue.

Another hint is to have incremental backups of your code. Every time you make a change, copy the old program to a new program, make changes in the new one, save the new one.This way you can go back to what was working code. Making a few changes to the same program can cause hair pulling problems. A simple misspelling, a : instead of a ;, etc' can be hard to track down. We've all done it.

cheers
Jay
Gabriel



Joined: 03 Aug 2009
Posts: 1067
Location: Panama

View user's profile Send private message

PostPosted: Wed May 14, 2014 8:59 am     Reply with quote

Quote:
+cmti: "ME",4


That response is telling you where the sms is located.

I did not see in your code you giving any commands to read the SMS:
Code:
AT+CMGR


for that command you need to provide an address which would be in this case "4".

G
_________________
CCS PCM 5.078 & CCS PCH 5.093
ILLIAS28



Joined: 11 Jan 2011
Posts: 42

View user's profile Send private message

PostPosted: Tue May 27, 2014 10:10 am     Reply with quote

many thank's to all of you for your help
_________________
i am newbe
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