Reputation: 21
I am working with GSM (sim900a) Module interfaced with PIC18F4520 Microcontroller.
Here I am trying to send SMS through PIC controller serially to GSM Module but unable to receive any response from GSM and not receiving any Messages.
When I am trying to connect only GSM Module to Hyperterminal then I am able to send SMS. In the similar fashion when I am trying to send AT commands from PIC to HYPERTERMINAL then I am receiving Commands Serially.
Code Below
#include<p18f4520.h> /* Header File */
#include<string.h>
void delay_ms(int ms);
void Data(char Value);
void Cmd(char Value);
char temp;
void main()
{
char tocheck[] ="AT";/*Basic command to test GSM is working or not */
char sendingsmsmode[]="AT+CMGF=1";/* To change the GSM Module in SMS
sending Mode */
char newsms[]="AT+CMGS=918500923915";/*Set Text mode for SMS */
char msg[]="WelcometoGSM";/* The text which you want to send */
char terminator=0x1A;
int i=0;
TRISC = 0x80; /* RC6=0 (O/P) RC7=1(I/P) */
SPBRG = 0x33; /* Serial Port Baud rate Generator (9600) */
TXSTA = 0X24; /* Transmission Enabling(TXEN=1,SYNC=0,BRGH=1)
*/
RCSTA = 0X90; /* Rception Enabling (SPEN=1,CREN=1) */
TRISC=0X00; /* (RC1,RC0 ->O/P Setting by Zero)
*/
TRISD=0X00; /* PORTD (0 - 7)pins Config as Output
*/
while(tocheck[i]!='\0'){
while(TXSTAbits.TRMT==0);
TXREG=tocheck[i];
delay_ms(30);
i++;
}
i=0;
while(sendingsmsmode[i]!='\0'){
while(TXSTAbits.TRMT==0);
TXREG=sendingsmsmode[i];
delay_ms(30);
i++;
}
i=0;
while(newsms[i]!='\0'){
while(TXSTAbits.TRMT==0);
TXREG=newsms[i];
delay_ms(30);
i++;
}
i=0;
while(msg[i]!='\0'){
while(TXSTAbits.TRMT==0);
TXREG=msg[i];
delay_ms(30);
i++;
}
TXREG=terminator;
delay_ms(3000);
while(1);
}
void Cmd(char Value)
{
PORTD=Value;
PORTCbits.RC1=0; /* RC1=0(RS=0) [Command Registr
Selection]) */
PORTCbits.RC0=0; /* RC0=0(R/W=0) [Write Process])
*/
PORTCbits.RC2=1; /* RC2=1(Enable=1) [Enable Line ON]
*/
delay_ms(4); /* Minimun Delay For Hold On Data
*/
PORTCbits.RC2=0; /* RC2=0(Enable=0) [Enable Line OFF]
*/
}
void Data(char Value)
{
PORTD=Value;
PORTCbits.RC1=1; /* RC1=1(RS=1) [Data Registr
Selection]) */
PORTCbits.RC0=0; /* RC0=0(R/W=0) [Write Process])
*/
PORTCbits.RC2=1; /* RC2=1(Enable=1) [Enable Line ON]
*/
delay_ms(4); /* Minimun Delay For Hold On Data
*/
PORTCbits.RC2=0; /* RC2=0(Enable=0) [Enable Line OFF]
*/
}
void delay_ms(int ms)
{
int i,count;
for(i=1;i<=ms;i++)
{
count=498;
while(count!=1)
{
count--;
}
}
}
Upvotes: 0
Views: 274
Reputation: 4704
You need to send CR or CR+LF (characters number 13 and 10 respectively) after every string you send to the modem.
When using a terminal emulator like HyperTerminal, you press the Enter key, right? If you don't press that key, the modem does not know that the command is terminated and must be executed. The same must be done in your firmware.
There is more: you must allow some delay, and you should read back modem responses, but this could be a second step; first of all, to check the setup is working at the base level, you must send an "AT", followed by a CR, then see if the modem replies with OK (+ CR and LF...).
Modify
char tocheck[] ="AT";
in
char tocheck[] ="AT\r"; // the \r is the CR (carriage return)
and you will see that the modem will reply, if all is connected well.
Upvotes: 1