|
|
View previous topic :: View next topic |
Author |
Message |
yr Guest
|
URGENT HELP REQUIRED!! |
Posted: Thu Jan 19, 2006 11:03 am |
|
|
Hi everyone
i am trying to read new sms messages in my gsm modem using pic microcontrollers
the trouble is that the data im trying to read serially is of the form:
---------------------------------data to be read serially------------------
at+cmgl="REC UNREAD"<CR>
+CMGL:4,"RECUNREAD","+578986513535",,"06/01/18,19:53:49+00",145,2<CR>
this is a test message
-----------------------------------end of data----------------------------
now my code (see below) can only serially input the first line ie 'at+cgml' one. when i try to use 'fgets(msg,modem)' for serially receiving the all important second line '+CGML' one i get nothing. the baud rate is 2400. it appears that maybe the second string passes before the controller can get to the command. but i have tested several modifications of the code and this doesnt seem to be the problem. from this second line i only need the no i.e "+578986513535" and then i need the complete third line i.e (this is a test message).
-----------------------------my code----------------------------------
#include <16F877.h>
#device *=16
#include <stdlib.h>
#include <string.h>
#include <math.h>
#USE DELAY (CLOCK=4000000)
#fuses XT,NOWDT,NOLVP
#use rs232(baud=2400,xmit=pin_d0,rcv=pin_d3,parity=N,stream=modem)//this stream will be used to communicate with the modem
#use rs232(baud=2400,xmit=pin_d1,rcv=pin_c2,parity=N,stream=pc) //this stream will be used to print values on the hyperterminal
char response[10]; //response is the global variable
void smssetup(char *command)
{
do
{
fprintf(modem,"%s",command);
fputc(13,modem);
fgets(response,modem);
}while(strcmp(response,command) != 0); //until we done receive 'at' back from the modem
}
void main()
{
char first[3] = "at";
char second[10] = "at+cfun=1";
char third[10] = "at+cops=0";
char big[25];
char msg[30];
fprintf(pc,"start");
smssetup(first);
smssetup(second);
smssetup(third);
do
{
fprintf(modem,"at+cmgl=");
fputc(34,modem); //this is the ascii value for (")
fprintf(modem,"REC UNREAD"); //so only read unread messages
fputc(34,modem);
fputc(13,modem); //carriage return
fgets(big,modem);
fgets(msg,modem);//<---- this is where i am trying to get the second line
}while(big[8] != 34);
//the above while exits once first line ie (at+cmgl) is not received
fprintf(pc,"the msg is:%s",msg); i always get "the msg is: " <-- so msg=0
}
----------------------------end of code----------------------------------
one might think that since 'msg' has a size of 30 characters so it cant store the second line any way, but sometimes the second line from the modem is---------> ERROR
and even then i this second line into the array 'msg'. i have also tried using other serial input methods such as EX.SISR in the examples folder but to no avail. ne help will be very much appreciated.
regards |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Thu Jan 19, 2006 1:18 pm |
|
|
Change your #use rs232() statement that receives data from the
modem so that it uses the hardware UART. Example:
#use rs232(baud=2400,xmit=PIN_C6,rcv=PIN_C7,ERRORS,stream=modem)
Then do what I recommended to you in this previous thread:
http://www.ccsinfo.com/forum/viewtopic.php?t=25697 |
|
|
|
|
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
|