First, I am working on a project that opens an electric door when certain cell phones call the GSM modem's SIM card's number. But, as a starting point I want to send some AT commands to the modem, then from there I can continue. Here is the code I wrote so far:
#define CINBUFSIZE 255
#define COUTBUFSIZE 255
#define TIMEOUT 500
char modembuf[255];
void INIT(void){
serCopen(115200);
serCflowcontrolOff();
serCparity(PARAM_NOPARITY);
serCwrFlush();
serCrdFlush();
}
void clrbuf(void){
serCwrFlush();
serCrdFlush();
memset(modembuf, 0x00, 255);
}
int fnMsDelay(unsigned long delay){
unsigned long u10;
u10 = MS_TIMER;
while((MS_TIMER-u10)<delay);
return 0;
}
void GSM_INIT(void){
int looping;
looping = 0;
puts("\nGSM_INIT");
tryagain:
clrbuf();
serCputs("AT\r");//waking modem from sleep mode
fnMsDelay(TIMEOUT);
serCread(modembuf, 255, TIMEOUT);
printf("\nReady to accept commands: %s", modembuf);
if(strstr(modembuf, "OK")){
clrbuf();
serCputs("ATDT*some_number*");//calls *some number*
fnMsDelay(TIMEOUT);
serCread(modembuf, 255, TIMEOUT);
printf("\nCalling 0522386652, status: %s", modembuf);
if(strstr(modembuf,"OK")){
printf("\nGSM_INIT OK");
BitWrPortI(PADR, &PADRShadow, 0, 0);
clrbuf();
return;
}
}
looping++;
printf("\nLooping: %d\n", looping);
if(looping==20){
printf("\nGSM_INIT FAILED");
return;
}
goto tryagain;
serCclose();
}
void main(void){
INIT();
GSM_INIT();
}
However, every time I run the above code the program fails to send any AT commands. Why? And how do I fix this problem?