GSM Modem Interfacing with PIC Microcontroller

Status
Not open for further replies.

sathiieesh

Newbie level 5
Joined
Feb 5, 2010
Messages
8
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,283
Location
Chennai
Activity points
1,379
Hi to all...
I am doing a project in which i will be interfacing a gsm modem with PIC microcontroller(16f877).. when i connect the gsm modem with PC i can able to send and read the messages in the sim using AT commands in hyperterminal...Then i iniatized UART in PIC send and received data to PC through hyperterminal its working properly...
When i interfaced PIC with GSM Modem i can able to send AT command to GSM modem but the reply "OK " from GSM modem to PIC is not received by PIC...

Example:

AT (Enter)-----In Hyperterminal
OK ------Message from GSM Modem

Compiler:MikroC
Baud Rate:9600 bps
GSM MOdem:Wavecom HT-W2101

I can able to send AT and Enter command from UART to PIC... But i cant able see the reply from GSM modem... but it works well when i interface GSM modem with PC hyperterminal...

Help me...
 

1 - Is your hardware configured correctly - TX of uP to RX of Modem, RX of uP to TX of modem?

2 - Are you sure your sending commands to the GSM modem -Serial port configured, proper handshaking, proper baud rate, etc.

3 - Are you terminating the "AT" command with a 'carriage return' when you send commands via the micro.
 

    V

    Points: 2
    Helpful Answer Positive Rating

    zolbayarp

    Points: 2
    Helpful Answer Positive Rating

    pic+gsm

    Points: 2
    Helpful Answer Positive Rating
Hello!

Try this code below.... It's working now! I used a SONY ERICSON T230 phone.... It reads the message on the gsm thru the PIC and displays the message being read... PIC16F877A is being used here...
Do you have an ISIS 7 Professional circuit simulator?.... Or any other ciruit simulator?.... Try simulate it first on the simulator... I connected the phone through its USB Data Cable to the USB Port of the PC, and on the circuit simulator, I connected the TX pin of COMPIM to TX of PIC16F877A and its RX to RX of PIC16F877A.... And a virtual terminal across its RX pin...

Code:
  unsigned char* MSG1 = "AT";
unsigned char* MSG2 = "at+CMGF=1";
unsigned char* MSG3 = "AT+CPMS=\"ME\"\n";
unsigned char* MSG4 = "AT+CNMI=2,1,0,0,0";
unsigned char* MSG5 = "AT+CMGR=1";
unsigned char* MSG6 = "AT+CMGD=1";
unsigned char output[70];
int i=0,flag=0;
void main() {
int ctr,x=0;
TRISB=0x02;
TRISD=0;
PORTB=0;
PORTD=0;

UART1_Init(9600);

     for(ctr=0;ctr<3;ctr++)
     {
       PORTB=0x01;
       Delay_ms(500);
       PORTB=0;
       Delay_ms(500);
     }

      //UART1_Write_Text(MSG1);    //at
      //Delay_ms(1000);
      //UART1_Write(0X0D);      // ENTER
      //Delay_ms(1000);

      UART1_Write_Text(MSG2);    //cmgf=1
      Delay_ms(1000);
      UART1_Write(0X0D);      // ENTER
      Delay_ms(1000);

      UART1_Write_Text(MSG3);    //cpms
      Delay_ms(1000);
      UART1_Write(0X0D);        // ENTER
      Delay_ms(1000);
    a:
      UART1_Write_Text(MSG5);    //cmgr
      Delay_ms(1000);
      UART1_Write(0X0D);     // ENTER
      Delay_ms(3000);




     UART1_Write_Text(MSG5); //cmgr
      Delay_ms(1000);
      UART1_Write(0X0D);     // ENTER
      
      


     do{

        UART1_Read_Text(output, "OK", 65);  reads text until 'OK' is 

found
        PORTD=output[x];
        UART1_Write_Text(output);           // sends back text
        
       }
        
          x++ ;


     } while(x<2);

       Delay_ms(1000);

      Delay_ms(3000);
      


       for(ctr=0;ctr<3;ctr++)
     {
       PORTB=0x01;
       Delay_ms(500);
       PORTB=0;
       Delay_ms(500);
     }
     
      x=0;
      goto a;

}
 

    V

    Points: 2
    Helpful Answer Positive Rating

    pistole89

    Points: 2
    Helpful Answer Positive Rating

    salahoo

    Points: 2
    Helpful Answer Positive Rating
Why all of the delays? You shouldn't need a delay between sending the data and the carriage return. Also, you should be reading the results to from the phone to see if there are any errors. At best, your software will take several seconds to do what can be done in milliseconds.
 
Dear Sir/Madam;

Many thanks for your good information

I bought Telit GM862-Quad GSM with EasyGSM/GPRS GM862 MikroElektronika Board

My project is to use PIC16F877A controller with this GSM Modem to send SMS when certain action happens

But it is not work, I used MikroBasic to program PIC16F877A

Please see attached file which include software and hardware

Awaiting your kind reply

Best regards;

Eng. Aiman Ismail
 
Reactions: montaser

    V

    Points: 2
    Helpful Answer Positive Rating

    montaser

    Points: 2
    Helpful Answer Positive Rating
Where's the file?
 

    V

    Points: 2
    Helpful Answer Positive Rating
Hi iam attaching a code which works perfectly when i interface PIC Microcontroller with PC hyperterminal to send and receive messages... The Hardware connections is also right... when i try to send sms from PIC it works perfectly... the problem in reading the message in Sim memory..
but the message received in my mobile is ATTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT TTTTTTTTTTTTTT....

WHAT MIGHT BE THE PROBLEM... I am attaching the code...

Code:
void sms_read();
void sms_send();
char output[70];
void main() {
     UART1_Init(9600);              // Initialize UART module at 9600 bps
     Delay_ms(100);                 // Wait for UART module to stabilize
     sms_read();                    //to read the sms in location 1
     delay_ms(500);
     sms_send();                    //send an sms
}
void sms_read()
{
unsigned char i;
UART1_Write_Text("AT\n\r");
delay_ms(500);
UART1_Write_Text("AT+CMGF=1\n\r");
delay_ms(500);
UART1_Write_Text("AT+CMGR=1\n\r");
delay_ms(500);
UART1_Write_Text("AT+CMGR=1\n\r");
delay_ms(500);
while (UART1_Data_Ready() == 0) ;
for(i=0;i<=65;i++)
{
 output[i]=UART1_Read();
}
delay_ms(500);
}

void sms_send()
{
int i;
/*UART1_Write_Text("AT\n\r");
delay_ms(500);
UART1_Write_Text("AT+CMGF=1\n\r");
delay_ms(500); */
UART1_Write_Text("AT+CMGS=");
UART1_Write(0x22);
UART1_Write_Text("+919444721638");
UART1_Write(0x22);
UART1_Write_Text("\n\r");
delay_ms(500);
UART1_Write_Text(output);
UART1_Write(26);// send ctrl + Z

}

Sathiesh Kumar.V
 
I'm having the same problem. Is there anyone can help?
 

Hi,

I am two GPRS modems. I use hyperterminal from Windows XP for both modems at COM1 and COM2. Modem1 initiate the connexion with ATDnumber and release the connection with ATH. Modem2 automatically answer after one RING ( ATS0=1 ). The problem is that these modems DO NOT CONNECT FOR THE FIRST TIME in bidirectional data transfer ( characters ) mode although both modems returns to PC the "CONNECT 9600" message. For the second attempt to establish connection the connection is correct after "CONNECT 9600" returned message from both modems and data trasfer is bidirectional ( Modem1 <-----> Modem2 ).

What can be the cause of this problem ?
 

Hello,
I am conducting my PhD project at the moment. I have purchased a Zigbee development board and have assembled it (hopefully correctly!). There are two connectors for the processor, one with two rows of 8 pins and one with nine two rows. I wish to connect sensors and a Telit GSM/GPS module and three sensors to this board, with an XBee Zigbee 2.4 GHz. I am also having problems writing the code I have to the PIC 16F819 I have. My background is not in electronics. Can you advise how to fit the GSM module and sensors properly and the easiest way to load the code to the processor please? I would be very grateful for any help given.

Many thanks,
Jim Hood.
 

I'm working on making a UMTS modem , able to transmit data through SMS & Internet using UC864-g module ,
I'm asking about a micro controller to use to send AT commands to the module using UART ,
1-Can i use 8 Bit micro controller to send through UART ?
2- Can i use mc as PIC18f44500 , but id doesn't contain UART , it contain USART & MSSP & USB ?
also i would like to know where is the UART in 16f877 ?
3-Does transmitting data through USB is complicated ?( i'm not professional in mc )
 

msmomar said:
1-Can i use 8 Bit micro controller to send through UART ?
Yes
msmomar said:
2- Can i use mc as PIC18f44500 , but id doesn't contain UART , it contain USART & MSSP & USB ???
USART is a UART that can send either Synchronous or Asynchronous data - look at the datasheet
msmomar said:
3-Does transmitting data through USB is complicated ?( i'm not professional in mc )
First, you need a controller that has a USB Host or OTG interface (available only in PIC24 & PIC32 families). Secondly, it is much more difficult to program USB than serial.
 
First i would like to thank you GSM Man ,
but im a beginner in PIC this is my first project ,
may i ask you if you have any example using Hardware UART of pic18f4550 or any pic18f family,
i tried to make it using Soft_UART , it worked , but it send data only not characters as AT commands didn't work.

this is the code i wrote using soft Uart ( its working on bits not on characters )



long s ;
//int f =5;
int m = 0;
int x=20 ;
int datatx = 255;

void main (void) {
TRISA =0;
Porta = 127;
portb=255;
TRISb=0;

Soft_Uart_init (portd, 1,0,9600,0);




while(x>0){
Soft_uart_write(datatx) ;
m++;
x-- ;
porta = ~porta ;
vDelay_ms(100) ;
}
}
 

I have exactly the same problem with sathiieesh & peter2020.

I`ve already check the GSM module connect with HT, and it works fine (i can send sms to my handphone through hyperterminal-GSM)

I`ve already check PIC with hyperterminal...to crosscheck my program, and it`s doing fine

But when i`m connecting PIC to GSM, i never received any sms in my handphone

What is the problem????
Is there anyone can help?

Added after 16 minutes:

Any suggestion ???
GSMman could you help Us please...

thanks
 

SO you have the RX of the PIC connected to the TX of the modem, and the TX of the module connected to theRX of the PIC?

Are you sending a Carriage return after each command?

If all else fails, post a sample of what you are sending and what the module is returning.
 
this is the result from connection between GSM module and Hyperterminal PC

Call Ready
AT
OK
AT+CMGS=1
ERROR
AT+CMGF=1
OK
AT+CSCS="GSM"
OK
AT+CMGS="085880340583"
> TEST GSM YAH
+CMGS: 11

OK

I received an SMS in my handphone : TEST GSM YAH

and then to cross check my PIC program, i connected PIC to Hyperterminal, just to make sure that the looping is doing fine, and it is. i try to give the "wrong" response, and my program didn`t continue the code but reply the code before error.

i`m curious, what happened to my board???

I`m using PIC-GSM board from Olimex

but, i`m suspicious with "response code" maybe my PIC didn`t receive it in a right way.

this is the code:
......
.....
......
for(i=0;i<4;i++)
{
datastr=getch();
}
OK();
.....
.....
.....
/////////////this is the subroutine

void OK(void)
{
if ((datastr[2]=='O')&&(datastr[3]=='K'))
data=1;
else
data=0;
}

unsigned char getch() {
// retrieve one byte
while(!RCIF) clear_usart_errors_inline; // set when register is not empty
return RCREG;
}



I only read four character from GSM
\r\nOK
if receive data number 3 & 4 is OK then data=1 which will trigger next code


Is there something wrong with my program?

thanks for your reply
 

But this program (without knowing the response) is working fine

puts("AT");
putch(0X0D);
wait();
wait();
puts("AT+CMGF=1");
putch(0X0D);
wait();
puts("AT+CSCS=");putch('"');puts("GSM");putch('"');
putch(0X0D);
wait();
wait();
puts("AT+CMGS=");putch('"');puts("085880340583"); putch('"');
putch(0X0D);
wait();
wait();
puts("test GSM PIC");
putch(0X1A);
wait();
wait();
wait();
 

hey,
i have connected gprs modem to pc and typed the commands in hyperterminal and got the sms to the prescribed number....

now

i want to just have a microcontroller and gprs modem and send the sms to any given number

pplease help me,,/.....
 

Hello GSM man!

How can I use interrupt in sending a string, "OFF", command to GSM which will then be used by PIC16f877a to turn the alarm off? This alarm has been triggered by one of my sensors (horn-switch of a motorcycle).

Could you please help me out with doing the interrupt for the receive part in GSM?
Could you please help me start with interrupt? It's the receive part that burdens me a lot.
Because we need to send "OFF" to stop the alarm once the sensor has been triggered and then wait for another trigger to sound the alarm. This will be in a loop.
How can I interface this received command by the GSM to PIC16f877a so that this mcu will be the one responsible for turning the alarm off and then be ready for another loop?
Please help us please..

Thank you so much.
 

Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…