embed21.com

Interfacing the GM862 with PIC18F452

by Khaled Raed Sharaf on Jan.10, 2010, under GSM/GPRS

Interfacing the PIC18F452 with the GM862 module is relatively simple. What will be left is only the code that needs to be burned on the PIC. By the way,no full codes will be posted here. I will only post the codes that will give you a good kick start because I think it is better to understand than to copy and paste. And there is a Chinese saying:

Give a man a fish, you feed him for a day.
Teach him to fish, and you feed him for lifetime.

This is a sample project that I made and it only deals with making phone calls and I will upload other videos for SMS, GPRS and Data Call:

Now looking at the schematics you will find all the details on how to connect both the module and the PIC.

After doing the above connections, you need to start the module first and then initiate the baudrate that both of them will work on. The Telit module works on different values of baudrates (300, 1200, 2400, 4800, 9600, 19200, 38400, 57600, 115200). For me I shall work with baudrate 19200, but you can choose whatever baudrate that you want.

To start the module, you simply connect the ON_OFF pin to the ground for at least 1 sec (note: this pin is normally high). So you can do this by two ways. First way is to connect a switch and give the ON signal by hand, which is not a good idea. The second way which all of you will do, is to let the PIC18F452 do the job of turning the module ON. We will connect a transistor as shown in the schematic (PN2222A) such that when the base voltage is high, it allows the current to pass to the ground. So, you will need to make PORTC.PIN5 to be HIGH for 1 sec and then toggle it back to LOW (safety factor make it 1.1 sec).

So, after initializing the baudrate on the PIC you need to do the following at the start of your program:


while(recieved_serial!='AT;\nOK\r\n'){
send_serial('AT\r');
delay_ms(300);   //Delay 300 mSec
}

We did this step, as the Module doesn’t know the baudrate that the PIC is set on, so we send multiple ‘AT’ commands until the module figures out the right baudrate. Also, a thumb of rule, try to always put a delay of 300 ms after each command is being sent to the module.

Also, while we are setting up the baudrate of the module, it is trying to register to the cellular network at the same time. You can make sure that it is registering by the 1 sec flash of the STATUS_LED. When the flashing becomes every 3 sec, then now the module is registered to the network. Before sending any command, you need to let the microcontroller know that the module is registered to the network. You can do this with the command AT+CREG?. When it returns +CREG: 0,2 then this means that it is still registering to the network, so you will have to wait for 300 mSec until you can double check again. If it gives +CREG:0,1 then this means that it registered to the cellular network. VOILA!

Something to mention until further experiments:
In the software manual, it says:


AT+CREG?
//Reply from the telit is:
+CREG: 0,3
OK

Which means that when you send the command AT+CREG? to the module it will reply back with only +CREG: 0,3 and OK, but that is not true, as they have forgot to add something else. When you send any AT command it will first reply  back with the same command and with a semicolon at the end. Also don’t forget after sending each and every AT command you must end the command with \r\n. The person who Telit hired to write the Software manual, really didn’t write it that good at all, as there are missing information. If you open the software manual (page 142), you will see the following:

<CR> <LF>
Each message is terminated using Carriage Return (CR) Line Feed (LF) which is \r\n which is hex 0D 0A. Because \r\n are not printable ASCII characters, they are omitted from the example strings, but must be sent to terminate the message and cause the receiver to process that input message.

The writer was so smart that he wrote that at the end of the software manual. Why don’t  you just write it at the beginning or even with the code!! And even if he said that they are omitted why don’t you just write them \r and \n as you wrote them here?? or CR and LF?? There are a million way to write it down on the manual. But seems that he forgot them while he was writing and said to just put it in the end of the manual instead of changing each and ever code. :(

Also, the Telit technical support doesn’t reply on emails that people send. So I really don’t understand how did this company made this beautiful module, but their technical support is really bad.

Anyways, that is a big mistake that people really do, so don’t forget \r or \n. So in the end the code will look something like this when it is registering:


AT+CREG?\r
//Reply from the telit is:
AT+CREG?;\r\n
+CREG: 0,2\r\n
OK\r\n

and if it is registered it will look like this:


AT+CREG?\r
//Reply from the telit is:
AT+CREG?;\r\n
+CREG: 0,1\r\n
OK\r\n

When you get this response then you are able to start making a phone call, SMS, data call, GPRS, SMTP, FTP (you name it :D ). The easiest part that you can try and have a good kick start is making a phone call. Note, the phone call that we will do only gives us a ringing tone to the phone that we will call, but we will not be able to send voice from this module, as we haven’t did the voice circuit yet. What I mean by phone call is just to make another phone ring showing the phone number of the SIM in the module.

To make a simple phone call you need first to disable echo and set full functionality. After that we are ready to make a phone call.


ATE0\r                  // disable echo
AT+CFUN=1\r             // set full functionality
ATD0123023490\r         // call phone number: 0123023490

You need to remove the number “0123023490″ and put your own cell phone number, and if you want to dial an international number just add the plus sign “+” before the number followed bt the code of the country then the phone number that you wish to dialAfter you send these commands to the module, the STATUS_LED will stop blinking and will be turned ON as you are making the call. After a couple of seconds, you will hear your cell phone ringing.

Now you have created your very own cellphone that can only give missed calls to a ceratin number COOL!

Ofcourse you can go further more and add a keypad to the PIC to dial phone numbers or add an LCD to show the replies from the module. For me, in the next series I will show you how to do all of this.

I hope this article was helpful, and if you have any questions please post it here.

:, , , ,

28 Comments for this entry

  • Eng.Aiman
    Eng.Aiman

    Dear Sir;

    Really it is very good project

    Im now designing a project using Telit GSM GM862 connecting with PIC16F877A to use this for controlling and monitoring via SMS

    so, please can you help me in softwar and hardware ?

    Best Regards;

    Eng.@im@n
    +962796732237

  • Khaled Raed Sharaf
    Khaled Raed Sharaf

    No problem Aiman. If you have any questions don’t hesitate to ask!!!

  • Eng.Aiman
    Eng.Aiman

    Dear Mr.Khaled;

    Many thanks for your cooperation

    I saw your project wiring diagram, and I understand what you did

    But I searched about 74HS4050 datasheet and I did not find

    so can you advise about this IC?

    Best Regards;

    Eng.@im@n
    +962796732237

  • Khaled Raed Sharaf
    Khaled Raed Sharaf

    This is the datasheet of the 74HC4050:

    http://www.datasheetcatalog.org/datasheet/philips/74HC4050.pdf

  • Eng.Aiman
    Eng.Aiman

    Dear Khaled;

    Many thanks for your help

    I ask Allah to enter you Paradise

    I read 50% from your good article and I solved many problems that I faced in my project

    Now, Im finishind wiring and test power suppy circuit and evrything is ok

    Status LED blinking evry 3 sec (registered)

    Then I will start programming PIC16F877A with MikroBasic Language to send SMS when certain port in PIC active high

    Best REgards;

  • Eng.Aiman
    Eng.Aiman

    Dear Khaled;

    Many thanks for your help

    I tried test program, but it is not work, 90% from my code

    so please can you help me to make small program to send SMS ?

    Best Regards;

  • Eng.Aiman
    Eng.Aiman

    Dear Mr. Khaled;

    Many thanks for good information that in your article

    It is work, I try to send SMS and it is send

    then try to make call, and it is calling

    Im very happy, so many thanks Eng.Khaled

    Best Regards;

  • Khaled Raed Sharaf
    Khaled Raed Sharaf

    Glade to hear Aiman that everything worked. And very happy to know that the blog was helpful for you!

    Best of luck!

  • Tayfun DOGDAS
    Tayfun DOGDAS

    Hi Khaled;

    Thanks for your really helpful site.I’m not sure but as far as heard telit will not support 862 model in very future,it will recommend 863 model.Did you hear anything about it?And could sparkfun logic level converter (http://www.sparkfun.com/commerce/product_info.php?products_id=8745) be used for interfacing with PIC instead of 74HS4050.What do you think?

  • Khaled Raed Sharaf
    Khaled Raed Sharaf

    Hello Tayfun,
    I am not sure about Telit will continue supporting the GM862 or not, but the fact is it haven’t supported any of its modules except with its manuals!!!

    Yes, the level converter that you are talking about should work fine!
    Best of luck

  • Tayfun DOGDAS
    Tayfun DOGDAS

    Hi again Khaled;

    Thanks for your fast and kind answer.Telit people help me a lot when i ask them for EasyCamera command set.862 is good(embeded sim card holder) but molex connector not good.863 is good with it’s pins design since it does not need molex but external sim card holder is bad i think.I understand them since it’s mobile phone main part so sim card holder should be seperated.And when i tries sparkfun logic converter i’ll share my experiences.

  • Eng.Aiman
    Eng.Aiman

    Dear Prof. Khaled;

    Many thanks

    I havent any problem with sending command to Telit GSM module, but I dont know how can I take response or recieved the result from GSM, like: OK,+CREG:0,1 and other to let my systen to work stand alone

    now I now that GSM registered by status LED but when my system will work stand alone I must tell the PIc to statr AT commant after registeration, this is first

    2nd: I want to know more about 74HC4050, how can I use it to be voltage translator ?

    awaiting your kind reply

    Best Regards;

    Eng.@im@n

  • ismail
    ismail

    I am trying to comunicate my gm862 gsm module. I set up your circuit, when I try to ON gsm module, PWRMON led status is ON, status led flashing 1 sec. several times and then both this led is OFF and the module shut down. what is my problem???

  • Aiman
    Aiman

    Many thanks

    I havent any problem with sending command to Telit GSM module, but I dont know how can I take response or recieved the result from GSM, like: OK,+CREG:0,1 and other to let my systen to work stand alone

    now I now that GSM registered by status LED but when my system will work stand alone I must tell the PIc to statr AT commant after registeration, this is first

    2nd: I want to know more about 74HC4050, how can I use it to be voltage translator ?

    awaiting your kind reply

    Best Regards;

    Eng.@im@n

  • Khaled Raed Sharaf
    Khaled Raed Sharaf

    @Aiman,
    Did you try to make the circuit above?? You should connect the 74HC4050 as in the schematic and everything will work fine for you. You will be able to receive all the data transmitted from the GM862.

  • Laurent
    Laurent

    Hello Khaled,

    Would you please send me the Pic code source you used to dialog with GM862 ?

    I’m novice with C programming and your code will help me a lot .

    Did you use Microchip C18 compiler or Mikro C ?

    One more question :
    Are you powering GM862 with 3.3 Volts ?
    I though it was expecting more than 3.8 V .

    Regarding 74HC4050; are you powering this chip with 3.3V or you use Vcc Pic power = 5V ?

    Many thanks for your help,

    Here is my email address if you accept to share your C code :
    L . coulon @ yahoo.fr

  • Aiman
    Aiman

    ya Mr. Khaled

    I made this circuit

    and evrything is ok

    but I want to learn how can I check the response command of GSM by PIC using mikrobasic software ?

    Best regards;

  • Khaled Raed Sharaf
    Khaled Raed Sharaf

    @Aiman,
    You can use the USART library that is found in the mikrobasic, and this will work fine.
    Open the Mikrobasic help to get to know how to use it.
    You will need to know how to receive data, also you can find a very good example from Mikroelektronika
    Click Here

  • Patrick
    Patrick

    ya Mr. Khaled

    I made this circuit

    and evrything is ok

    but I want to learn how can I check the response command of GSM by PIC using mikrobasic software ?

    Best regards;

  • Khaled Raed Sharaf
    Khaled Raed Sharaf

    @Patrick,
    You need to find out the library on mikroBasic that enables you read and write from/to the UART

  • Manolo
    Manolo

    Hi Khaled!
    Before everything, thank you for your great site!
    I have a little question, and I hope you can help me. What should I try if the module never register to the network? I mean, the status led stills flashing every second no matter how much time I wait. It’s not registered, is it?
    Thank you for everything again.

  • Khaled Raed Sharaf
    Khaled Raed Sharaf

    Hello Manolo,
    Here are somethings that you can try to do if it doesn’t want to register.
    1-Increase the voltage to 4.08v
    2-Change the SIM card of one network to another.
    3-Make sure the antenna is connected properly to the module.

    If it makes the 1sec flashing then then it is not able to find the operator. Try to do what I told you, and tell me how did things work?

  • Jose Angel
    Jose Angel

    I realize a project for the university with a Pic 18F4550 and one module Telit GM862 and I am trying to be able to send a SMS from the PIC, I am using MikroCPro, but I am new in programming and I am not capable of communicating them.
    Your web seems to me to be fantastic and I like that you were helping me with this project, a greeting and thanks.
    Sorry my bad English

  • Manolo
    Manolo

    Hallo Khaled!

    It’s been a while since my last post, now I’m glad to tell you that the module is working fine !! The error was in some part of my code, but thank you for your concern and help, your power source’s design is always helpful.
    Thanks.

  • Khaled Raed Sharaf
    Khaled Raed Sharaf

    Hello Manolo,
    Glade to hear that the module worked!
    And if you have any questions don’t hesitate to ask.

    Best of luck!

  • Elijah mills
    Elijah mills

    Hello i am having a hard time figuring out the code. Can you please email me ebmiv@aol.com

  • dinabrar
    dinabrar

    Hello Sir, i made the circuit, but am unable to configure the mcu, its almost a month now and no progress, i would really appreciate if you could mail me the entire code.

    Regards

  • Aiman Ismail
    Aiman Ismail

    Dear Mr.Khaled;

    How are you ?

    after success in project and sending SMS, I want to display the strength of GSM antenna signal % on LCD or LED array.
    so, how can I get this percentage from GM-862 ?
    awaiting your kind reply
    BR
    Eng.@im@n

Leave a Reply

Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!

Visit our friends!

A few highly recommended friends...

Archives

All entries, chronologically...