putc(26); //send the msg with a CNTL-Z 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 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;
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
putc(26); //send the msg with a CNTL-Z
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.
PIC16F877AHI-TECH C PRO Compiler (MPLAB v8.63)SIMCOM300 GSM ModemLCD JHD 162A
Code C - [expand]12345678910111213141516171819202122232425262728293031323334353637
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
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);
*** 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.
void interrupt(){intTimer++;PIR1.TMR1IF=0;if(intTimer%10==0){if(intTimer%20==0){intFlag=1;}}}//SMS processingvoid textMode(){ // Set message format as textmode
void check_message() { // check message statusif(strcmp(mess,"Unlock")==0){TRIGGER=1; // trigger relaydelay_ms(2000);TRIGGER=0;}}void main() {TRISA=0x3F;ADCON1=0x06;PORTA=0x00;TRISB = 0X00;PORTB=0x00;TRISD=0x00; // Set PORT D as OUPTPUTPORTD=0x00;
we can send sms from gsm modem.but cant receive sms and to display it on lcd by pic16f877a..pl help me..we are in deadline.check my code and correct it.
while(char_rcvd !='\0'){//char_rcvd = fgetc(GSM);data[i]=char_rcvd;i++;}i=0;//data[i] = 0; // return new line shows that all character has been collected
}*/#int_rdavoid serial_isr(){int i= 0;
//char_rcvd = fgetc(GSM);// while (char_rcvd!='\0')while(i!=2){char_rcvd = fgetc(GSM);data[i]=char_rcvd;output_high(PIN_B7);i++;}i=0;t=1;
//data[i] = 0; // return new line shows that all character has been collected
fputc('G',GSM);fputc('f',GSM);fputc('=',GSM);fputc('1',GSM);fputc(0x0D,GSM);//fprintf(GSM, "AT+CMGF = 1\r\n"); //set to GSM to text modedelay_ms(1000);
void lcddata(char value){output_b(value); //put the value on the pinsoutput_high(PIN_E0); //rs highoutput_high(PIN_E1); // enable pins H-L pulsedelay_ms(15);output_low(PIN_E1); //enable pins}
/*void lcdcmd(int value1){output_low(PIN_E0); //rs lowoutput_low(PIN_E1); //enableoutput_d(value1) ; //put the value on the pinsoutput_high(PIN_E1); //strobe the enable pins H-L pulsedelay_ms(15);output_low(PIN_E1); //enable}*/
Re: How to get SMS delivery notification by GPRS modem (SIM300)
+CDS : <length> <CR> <LF><pdu> (PDU mode) or +CDS : <fo>,<mr>, [<ra>] , [<tora>], <scts>,<dt>,<st> (Text mode)2: SMS-STATUS-REPORTs are stored and routed using the unsolicited result code :+CDSI: “SR”,<index>
#include <16F877.h> // Defines chip #include <stdio.h> // this gets the printf() definition #include <string.h> // string handling library #use delay(clock=4000000) // tells compiler clock speed #fuses hs, noprotect, nowdt, nolvp, nobrownout // sets the fuses #use rs232(baud=9600,xmit=PIN_C6, rcv=PIN_C7, stream=GSM, ERRORS) // sets the rs232 up #byte PORTD = 8 // portd is located at file 8 #bit injector1 = PORTD.0 // portd1 is injector1 #bit injector2 = PORTD.1 // portd2 is injector2 #bit injector3 = PORTD.2 // portd3 is injector3 #bit injector4 = PORTD.3 // portd4 is injector4 #bit lift_pump = PORTD.4 // portd5 is lift pump
. const int CR=0x0d; const int CZ=0x1A; const int LF=0x0A;
char response[8]; char reply[20]; char result[2];
int read_message; int send_message; int delete_message; int receive_message; int shutdown;
void main(void) { set_tris_d(0xE0);
};
void send_message()
{
fprintf(GSM,"AT\r\n"); delay_ms(500); // checks are they communicating fgets(GSM); //gets the responce and dump it
fprintf(GSM,"AT+CMGF=1\r\n"); // sends an at command to set messages to text mode delay_ms(500); //sends a carriage return fgets(GSM); //gets the responce and dump it
fprintf(GSM,"AT+CMGS=\"07749960685\"\r\n"); // sents the following text to this number delay_ms(500); fgets(GSM); //gets the responce and dump it
fprintf(GSM,"Shutdown Procedure Complete. Contact Authorities"); // the text that will actually be sent delay_ms(100);
fprintf(GSM,"+CMTI: "SM",1"); //sends the command to read the message at location 1 delay_ms(500) //wait 500ms fgets(GSM); //gets the first line of text message and dumps it delay_ms(500) //wait 500ms fgets(GSM); // gets the second line and dumps it delay_ms(500) //wait 500ms fgets(GSM); //gets the 3rd line which is line we want delay_ms(500) //wait 500ms fputs(GSM,text_code); // puts the string in file called text_code delay_ms(500)
fgets(GSM); // gets the blank line result1 = stricmp(text_code1, text_code2); result2 = stricmp(text_code1, text_code3); if(result1=0 && result2=-1||1) //if result1 is true carry out shut down shutdown(); //procedure
else if(result1 = 1||-1 && result2 = 0) // if result2 is true carry out startup main();
else (result=1||-1 && result2= 1||-1) // if stricmp returns 1 == false delete_message(); fgets(GSM); //gets the carriage return and dumps it
delay_ms(500) //wait 500ms };
//this function deletes the message in location 1 void delete_message(void) { fprintf(GSM="AT+CMGD=1"); //deletes the text message at location1 so next command can be dealt with delay_ms(500) gets(response,GSM); // gets the ok response main };
// this function carries out the shut down procedure void shutdown(void) { injector1= 0; // switch off injector 1 delay_ms(500); injector2= 0; // switch off injector 2 delay_ms(10000); // wait ten seconds delay_ms(10000); // wait ten seconds delay_ms(10000); // wait ten seconds delay_ms(10000); // wait ten seconds delay_ms(10000); // wait ten seconds delay_ms(10000); // wait ten seconds (1 minute) lift_pump=0; // turn the life pump in tank off //once the pump has been deactivated the engine will have no fuel and so the car will come to a //halt, receive_message(); // calls cool down period where it waits for the // command to turn the car back on };
How to test your GSM device/SIM card using Hyperterminal
To test if your GSM device, phone or GSM modem can work with VisualGSM, you can use Window's hyperterminal.
1). Start Hyperterminal as shown below:-
2). Connect your GSM device to a COM port, e.g. COM port 1. Ensure that there is sufficient COM ports in the first place. For IrDA or infrared connection, please ensure that your IrDA port is mapped to a serial port, e.g. COM4 is commonly used by IrDA. Some mobile devices can only be connected via IrDA, e.g. Nokia 8210.
(Note: IrDA is used by only VisualGSM Lite. If you are using IrDA on Win2k, you may need to install a patch. You can download the patch from Lite download page.)
3). Enter a name for the connection, e.g. test.
4). Select COM port 1, if you device is connected to COM 1. If you are not sure, you can try the other COM ports.
5). Click restore default. If you are using a mobile phone via data cable, you may need to change the baud rate to 19200 Bits per second.
6). Go to File - Properties.
7). Click on Settings tab, select ASCII Setup. Ensure that "Append line feeds to incoming line ends", "Wrap lines that exceed terminal width", and "Send line ends with line feeds" are checked.
8.) Test your connection by issuing AT, and AT+CPIN. If you get OK and +CPIN: READY as response, then your device is ready for use with VisualGSM Enterprise. If you cannot get the response as shown below, please check with other ports, and baud rate combinations.