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

SIM900D Modem not responding to SMS receive

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



Joined: 23 Sep 2013
Posts: 14

View user's profile Send private message

SIM900D Modem not responding to SMS receive
PostPosted: Sat Jun 07, 2014 12:21 pm     Reply with quote

hi i am working a long day on it, different codes are tried but no true success. I want to make a program that respond to incoming sms, so i first make a simple program that replay same sms back to specific number. On Proteus simulation it works but in real world! , i also check communication by directly connect to pc.

here is my code
Code:
#include <16F887.h>

#FUSES HS,NOPROTECT,NODEBUG,NOWDT,PUT,NOLVP,BORV21,NOMCLR
#use delay(crystal=18432000)
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8)

#define PWR_GSM PIN_A0
#DEFINE SIZE_BUFFER    70   // Serial Buffer Size

#include "string.h"
#include <stdlib.h>

//**********************************
//********Functions Declaration
//**********************************

void CLEAR_BUFFER();
void initialize();
int  counter_read=0;             //counter to fill the array

int index=0;
Char Recieve_String[SIZE_BUFFER];   //buffer for incoming data

Char temp_str[SIZE_BUFFER];
Char temp_str2[SIZE_BUFFER];

char str_ok[]="OK\0";
char str_smsrx[]="+CMTI:";

char *start;
char str_id[4];

#int_RDA
void  RDA_isr(void)
{
   Recieve_String[counter_read]=getchar();         // Gets chars from uart
   //fputc(Receive_String[counter_read],PC);
   counter_read++;                           // Increment counter
      if(counter_read==SIZE_BUFFER)counter_read=0;   // Circle Buffer
}

////==========================
void main()
{

//====Power ON GSM Module
output_high(PWR_GSM);
delay_ms(1100);
output_low(PWR_GSM);
//===========
   
ENABLE_INTERRUPTS(GLOBAL);               // Enable Interrupts
ENABLE_INTERRUPTS(INT_RDA);               // Enable Serial Interrupts 

delay_ms(2000);

initialize();
   
   printf("AT+CMGS=\"+9*******50\"\r"); \\i replace the number
   delay_ms(400);
   printf("setup complete.\r");
   putchar(0x1A);

   CLEAR_BUFFER();



   while(1)
   {

   while(!(strstr(Recieve_String,str_smsrx)))
   {
   }
      strncpy(temp_str,Recieve_String,counter_read); //copy data to temp array

      start=strchr(temp_str,',');  //FIND location of ',' bcoz sms receiving indication formate is like +CMTI: "SM",2 , where 2 is sms saving slot
      start++;                // then +1 to find saving integer

      strcpy(str_id,start); //coper slot no. to str_id
      index=atoi(str_id);   //convert char to integer
 
      CLEAR_BUFFER();
      delay_ms(500);
   
      printf("AT+CMGR=%d\r",index); // READ SMS AND THEN SEND BACK TO SPECIFIC NUM
      delay_ms(500);
      strcpy(temp_str,Recieve_String); // copey msg to temp string
      printf("AT+CMGD=%d\r",index); //Delete Readed sms
     
       printf("AT+CMGS=\"+9*******50\"\r");
       delay_ms(400);
       printf("SMS REPLAY,\n%s \n%s",temp_str2, temp_str);
       putchar(0x1A);
       delay_ms(800);
       
       CLEAR_BUFFER();
             
       delay_ms(300);
     
     }//--END OF MAIN WHILE
}

void CLEAR_BUFFER()
{
   memset(Recieve_String,NULL,SIZE_BUFFER);      // Set all elements to NULL
   counter_read=0;                           // Reset index
}

void initialize()
{
CLEAR_BUFFER();

delay_ms(2000);

while(!(strstr(Recieve_String,str_ok)))
{
printf("AT\r");
//printf("\n %d \n",counter_read);
delay_ms(400);
}

CLEAR_BUFFER();

while(!(strstr(Recieve_String,str_ok)))
{
printf("AT+CMGF=1\r");            // Set modem to TXT mode
delay_ms(400);
}

CLEAR_BUFFER();

while(!(strstr(Recieve_String,str_ok)))
{
printf("AT+CPMS=\"SM\",\"SM\",\"SM\"\r");   // Store in SIM Card
delay_ms(400);
}

CLEAR_BUFFER();

while(!(strstr(Recieve_String,str_ok)))
{
printf("AT+CNMI=2,1,2,0,0\r");              //SET NEW SMS ALERT MSG
delay_ms(400);
}
delay_ms(500);
//printf("AT+CMGD=1,4\r");
//delay_ms(400);
printf("AT+CMGD=2\r");
delay_ms(300);
printf("AT+CMGD=4\r");
delay_ms(500);

CLEAR_BUFFER();
}
ezflyr



Joined: 25 Oct 2010
Posts: 1019
Location: Tewksbury, MA

View user's profile Send private message

PostPosted: Sat Jun 07, 2014 7:25 pm     Reply with quote

Hi,

First, how are you troubleshooting this? I assume just looking at some LEDs, and then waiting for the presence/absence of a text message? If so, you really need a way to see what's going on inside your code. My preferred method is to use a 2nd serial port, and output diagnostic messages to a PC. This will make your life 100% times easier!!

Do you know for sure that your PIC is running, and running at the correct speed?? You crystal frequency is 'odd', so this might be a problem. At startup, flash an LED at a known rate a few times to verify that the PIC is running and your timing is OK. Try 1 second On and 1 second Off in a loop for 5 loops. Time it. Is it correct?

Add Errors to your #use rs232 directive. This will prevent the UART from hanging if it overruns....

The absolute 1st step in a GSM project is to simply send a text message. That's pretty easy, while receiving is relatively hard.... Does your 'Setup Complete' message ever get sent/received?? If so, at least PIC --> GSM communications is working. Get this down first!

You don't say whether any of the Initialize() function is working or not. Are you receiving an 'OK' when you send the 'AT'?? This will tell you if GSM --> PIC communications is working....

You never say which specific iteration of the SIM900 GSM modem you are using. Tell us, and post a link to it. You say this: "I also check communication by directly connect to pc.", and that is a bit troubling because the interface between the GSM modem and the PC would likely be totally different between the GSM modem and the PIC. I suspect that your 'SIM900' board has the necessary interface components to connect directly to a PC COM port. That means to connect the GSM modem to your PIC then you'll need something like a MAX232 IC. Please clarify this!

John
Shaheers



Joined: 23 Sep 2013
Posts: 14

View user's profile Send private message

PostPosted: Sun Jun 08, 2014 1:06 am     Reply with quote

ezflyr wrote:


I assume just looking at some LEDs,

can't because i make in hardware and i was confident enough that it works.
ezflyr wrote:

My preferred method is to use a 2nd serial port, and output diagnostic messages to a PC. This will make your life 100% times easier!!

I thought about this method that i use a 2nd serial port on pins ISP data/clock pins,
but i have some doubt on it,
1. what happens if by chance soft serial is last time used, is hw receive interrupt works anyway?
2. what tells soft serial that data is received ?

ezflyr wrote:

You crystal frequency is 'odd', so this might be a problem. Time it. Is it correct?

this xtal freq is impressed by datasheet table that it is
1. high clock
2. 0% error rate, on 9600baud rate


ezflyr wrote:

Add Errors to your #use rs232 directive. This will prevent the UART from hanging if it overruns....

copy that, that thing i really miss, but on compile it says "variable never used rs232_errors, but this works, i dont know why.

ezflyr wrote:

interfacing between PC<--->GSM


I check PC<-->GSM communication usig Pickit2 UART tool, just put PIC away and put a jumpers between (40,39)pins to (25,26)h/w uart Pins.
No communication IC used. and i think its TTL because Pickit2 have also PIC.
temtronic



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

View user's profile Send private message

PostPosted: Sun Jun 08, 2014 5:07 am     Reply with quote

hmmm...

'but on compile it says "variable never used rs232_errors, but this works, i dont know why. '

this one is easy( for me)..
It's just a 'warning', saying that variable is never used in your program.
To get rid of the warning just initalize the variable to 0 in the begining of your program.

int8 rs232_errors = 0;

hth
jay
Ttelmah



Joined: 11 Mar 2010
Posts: 19490

View user's profile Send private message

PostPosted: Sun Jun 08, 2014 6:26 am     Reply with quote

Key here is that it is a warning, not an error.

Warnings are things you 'may' need to be aware of, but may also be legitimate.

When 'ERRORS' is added to the RS232 setup, the compiler generates a variable called 'RS232_ERRORS', into which it puts bits reflecting any errors it finds/fixes. This is there so you can test for them if you want. If you don't use it, you get the warning.

You can simply get rid of the warning by reading it or writing it (you don't want the 'int8' in temtronic's example - the variable is already declared).
Even more sneakily, you can add:
Code:

void do_nothing(void)
{
    RS232_ERRORS=0;
}


and then never call this function. No code will then be generated, but the error won't then trigger!.

Or (of course), simply use an #IGNORE_WARNINGS command for this warning.

The latest compiler default to ignoring this specific warning, because it led to a lot of people not adding ERRORS, which is _required_ with hardware RS232, unless you add your own error handling code.....
ezflyr



Joined: 25 Oct 2010
Posts: 1019
Location: Tewksbury, MA

View user's profile Send private message

PostPosted: Sun Jun 08, 2014 6:43 pm     Reply with quote

Hi Shaheers,

You aren't cooperating with the troubleshooting process, so I'm going to abandon this thread. I asked you a number of specific questions, but you ignored most of them, answering only those you felt like, or apparently felt were important.

I've been down this road too many times only to learn on page 3 of a thread that the 'GSM modem' was different than earlier described, or some other critical piece of information was not disclosed. That's why I asked for a link to the modem you are using, and why I asked about your ability to communicate with the modem at all. A successful GSM project starts with a proper hardware interface, and until that is established it makes very little point in going forward. I've "been around the block" a few times having done successful commercial developments using the GM862, ADH8066 and SIM900 GSM modems, so I know a bit about the pitfalls and gotchas.....

You claim that you can't add any diagnostic ability to your project because the hardware is already done, and you are confident of it. Well, it's never too late to make hardware changes if they are important/necessary, and I might suggest that your 'confidence' might actually be 'over-confidence'. The problem is that as a 'newbie' you don't even know what you don't know......

Maybe someone else with GSM experience will chime in and help you out!

Good Luck!

John
Shaheers



Joined: 23 Sep 2013
Posts: 14

View user's profile Send private message

PostPosted: Wed Jun 11, 2014 9:40 pm     Reply with quote

Hi ezflyr,

I am very sorry of my uncooperative behavior form every one, and for late response because i was out.
here is a GSM picture i used



here 0.1uF capacitor to Vdd and GND pins of module
Rx to Tx (pin 25 of 16f887)
Tx to Rx(pin 26 of 16f887)
double checked.
I grounded all GND pins together.
I use a transistor to turn on/off power key of GSM which is working
and left all other pins unconnected.

Although i get success to respond to message, following two changes i made
1. change AT+CNMI=2,1,2,0,0\r to AT+CNMI=2,2,2,0,0\r\n
it change SMS alert type, i mean first it respond like +CNMI: "SM", <n>, where n can be any slot 1,2,3. . .
now it directly rout sms instead of prompt, i dont know if it saves sms or not, i suppose another command to save this msg.
2. I change following code
Code:
while(!(strstr(Recieve_String,str_smsrx)))
   {
   }
where Recieve_String is round buffer from serial int and
str_smsrx[]="+CMTI:";


to
Code:
for(;;)
   {
   
   if(counter_read>2)
   {
   delay_ms(1000);
   statements;.....

   }
   }

where counter_read is a buffer index, one who increments when every char receives.


Now i stopped here because i need some string operations like extract number from incoming sms, and respond to commands like add a number, delete a number, set time, etc.
But i just pause that part, i'll post a another GSM driver made by me which contains such a operations also, because previously made drivers are not working for me :(


now i am working on port B external interrupts,
and i got a problem that individual IOC port B is not working when i made an isr routine for them i rather post another thread because its not relevant
Ttelmah



Joined: 11 Mar 2010
Posts: 19490

View user's profile Send private message

PostPosted: Thu Jun 12, 2014 1:10 am     Reply with quote

Er.

What voltage are you using for the supply?.

The SIM900D, support operating off a 3.4 to 4.5v supply.

You PIC requires 4.5v _minimum_ to run at 18MHz.

If you are running the PIC at 5v, then the SIM900 is 'overvoltage' unless you are running this off a separate supply. If you are, then you run into the problem of level conversion between the signals on the PIC, and those on the module.

Far simpler and easier to run everything at one voltage. Change your PIC's crystal to 8MHz say, and run the PIC and the module off 4v.
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