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.

[SOLVED] GSM Modem SIM300 and PIC16F877A accessing problem

Status
Not open for further replies.

speedEC

Full Member level 6
Joined
Apr 1, 2011
Messages
337
Helped
23
Reputation
46
Reaction score
21
Trophy points
1,298
Activity points
4,324
GSM Modem SIM300 and PIC16F877A +AT+CLCC Command problem

I am new to PIC world and also I am moderate on C/C++. I have already communicated GSM Modem (SIMCOM300) using MS VB6.0 from PC successfully. Now I tried to communicate GSM Modem from PIC16F877A. I can able to send and receive sms, ring tone from/to GSM Modem SIM300 and PIC16F877A. All SMS commands works fine. But, when I issue "AT+CLCC" Command, it also works and also the commands followed by are also executed well, but it didn't come out from the loop. I have to switch-off the power and restart. Then only PIC process the command. Can you pl help me to locate the issue and guide me to solve this problem. I will be very humble and thankful to you if anyone provide help to solve this issue.

PIC16F877A
HI-TECH C PRO Compiler (MPLAB v8.63)
SIMCOM300 GSM Modem
LCD JHD 162A


Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
Code:
 
#include <stdio.h>
#include <htc.h>
#include "usart.h"
#include "lcd.h"
#include "string.h"
 
__CONFIG(HS & WDTDIS & UNPROTECT &  LVPDIS);
 
unsigned char gsmInput[60];
unsigned int i=0;
unsigned int lenOfGSMInput = 0;
 
bit OK;
bit Error;
bit Ring;
 
void showGSM_DATA(char GSM_DATA[]){ //to show the GSM OUTPUT after eliminating the chars '\r' and '\n'
    
    if (strcmp(GSM_DATA, "OK") == 0){ 
        OK = 1;
    }
    else if (strcmp(GSM_DATA, "ERROR") == 0){
            Error = 1;
    }
    else if (strcmp(GSM_DATA, "RING") == 0){
       
        Ring = 1;
        
        GSM_DATA[0] = '\x00';
        puts("AT+CLCC");
        putch(0x0D);
        
    }
    else{
        lcd_clear();
        lcd_goto(0);
        lcd_puts(GSM_DATA);
    }
  GSM_DATA[0] = '\x00';
 
} // end function showGSM_DATA
 
void main(int argc, char* argv[]){
 
    unsigned char input;
       
    INTCON=0;   // purpose of disabling the interrupts.
    
    lcd_init(); // initiate LCD
    
    init_comms();   // set up the USART - settings defined in usart.h
                    
    puts("ATE0");
    putch(0X0D);
    
    puts("AT+CMGF=1");
    putch(0X0D);
    
    while(1){
                       
        input = getch();    // read a response from the GSM
        
        switch(input){
            
            case '\x0A': // if line feed detected in the GSM output i.e. '\n'
                        break;
            case '\x0D': // if carriage return detected i.e. '\r'
                        gsmInput[i] = '\x00';
                        
                        lenOfGSMInput = strlen(gsmInput);
                        if (lenOfGSMInput > 0){
                            i = 0;
                            lenOfGSMInput = 0;
                            showGSM_DATA(gsmInput);
                        }
                        break;
            case '\x3E': // if greater-sign (in order to send SMS)
                        break;
            
        default: // if characters received
                gsmInput[i] = input;
                i++;
                break;
        }//end brace for switch
    } //end brace for while loop
}//end brace for main

 
Last edited:

Try to test these two commands with the hyperterterinal first. See if you get the expected response from the module.
 

Yes. I already tested with hyperterminal. There is no problem.
 

Hi seadolphine, Can you pl help me to correct the issue?
 

Try the following:
1- Comment this part of the code and see if the program flow will continue normally.
Code:
    else if (strcmp(GSM_DATA, "RING") == 0){       
        Ring = 1;        
        GSM_DATA[0] = '\x00';
        puts("AT+CLCC");
        putch(0x0D);

2- If the program ran normally, then the problem is specifically in the command "AT+CLCC". It may be that the MODEM is still sending some characters, or the MODEM's response is delayed for some reason while you are trying to send it another command.

Hope this helps.
Good Luck
 
Try the following:
1- Comment this part of the code and see if the program flow will continue normally.
Code:
    else if (strcmp(GSM_DATA, "RING") == 0){       
        Ring = 1;        
        GSM_DATA[0] = '\x00';
        puts("AT+CLCC");
        putch(0x0D);

2- If the program ran normally, then the problem is specifically in the command "AT+CLCC". It may be that the MODEM is still sending some characters, or the MODEM's response is delayed for some reason while you are trying to send it another command.

Hope this helps.
Good Luck

I have changed the code but the same result. I worked with hyperterminal also. It works fine. No problem there. I think problem in my code. I sent you the entire code for your review. Pl go thro' my code and try to find out the problem. I need your help. Pl.

For your information:

The following code works fine. (I have enabled Clip using AT+CLIP=1 to avoid AT+CLCC command. Before this, If I disconnect the call after processing AT+CLCC response (+CLCC : 1,1, ..), I cannot receive "NO CARRIER" message. Now I receive "NO CARRIER" because of "AT+CLIP" command)

Just display the GSM_DATA (No data validation):

void showGSM_DATA(char GSM_DATA[]){ //to show the GSM OUTPUT after eliminating the chars '\r' and '\n'

if (strcmp(GSM_DATA, "OK") == 0){
OK = 1;

if (strcmp(NextCmd, "CMGF") == 0){
strcpy(NextCmd, "CLIP");
puts("AT+CMGF=1");
putch(0X0D);

}
if (strcmp(NextCmd, "CLIP") == 0){
*NextCmd = 0;
puts("AT+CLIP=1");
putch(0X0D);

}
return;
}

if (strcmp(GSM_DATA, "ERROR") == 0){
Error = 1;
*GSM_DATA = 0;
return;
}

if(strlen(GSM_DATA) > 6){

lcd_clear();
lcd_goto(0);
lcd_puts(GSM_DATA);
}
*GSM_DATA = 0;
return;

} // end function showGSM_DATA


*** The following also works fine but only one time(Startup Commands like ATE0, AT+CMGF=1, AT+CLIP=1) and Any Phone/SMS received (After Successful Startup Commands Execution). If I send another SMS/Phone nothing happen. I have to restat the device. GSM Modem working correctly.

Just I add substring function. Thats all:

if(strlen(GSM_DATA) > 6){

substring(0,14,GSM_DATA);

}

void substring(size_t start, size_t stop, char src[]){

int j = 0;

if (start >= stop){
//return substringOfInput;
return;
}

for(i = start;i < stop; i++){
substringOfInput[j] = src;
j++;
}

substringOfInput[j] = '\x00';
lcd_clear();
lcd_goto(0);
lcd_puts(substringOfInput);
*src=0;
*substringOfInput=0;
j=0;
return;
}

Can you pl help me?
 

Hi seadolphine,

I found the bug I made in the code inside "substring" function. I already declared "i" as global variable. I removed and also change the code line

void substring(size_t start, size_t stop, char src[]){

int j = 0;

if (start >= stop){
//return substringOfInput;
return;
}

for(i = start;i < stop; i++){
substringOfInput[j] = src;
j++;
}

substringOfInput[j] = '\x00';
lcd_clear();
lcd_goto(0);
lcd_puts(substringOfInput);
*src=0;
*substringOfInput=0;
j=0;
return;
}

to

for(int i = start;i < stop; i++){

Now everything works fine. Great Thanks.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top