Hello I'm having trouble, BIG trouble programing a GM862 from telit.
First of all I'm using pic18f45k20, using development kit pickit3.
I've been trying to communicate with the pickit to the GM862 using UART (connecting TX and RX), I read online that it is fairly simple etc.. but it doesn't work for me..
I think the problem is my UART, I'm not sure how it works and I dont get any thing....
Below is the code I'm using deriving from the sample given from the vendor...
If someone can really help me on that! This is my final project to graduate! thank youuu...
First of all I'm using pic18f45k20, using development kit pickit3.
I've been trying to communicate with the pickit to the GM862 using UART (connecting TX and RX), I read online that it is fairly simple etc.. but it doesn't work for me..
I think the problem is my UART, I'm not sure how it works and I dont get any thing....
Below is the code I'm using deriving from the sample given from the vendor...
If someone can really help me on that! This is my final project to graduate! thank youuu...
Code:
#include <p18f45k20.h> #include <usart.h> #include <delays.h> #include <string.h> #include <stdio.h> #define in usart.h #define in usart.h // set of AT commands const char atc1[] = "ATE0"; // disable command echo const char atc2[] = "AT# CAP= 1"; // enables handsfree external mic/ear audio path const char atc3[] = "ATD19168214521;"; // place a call to phone number 123456789 // instead of 123456789 insert your phone number const char atc4[] = "ATH"; // hang up const char atc5[] = "ATA"; // answer a call const char atc6[] = "AT#HFMICG=4"; // handsfree microphone gain const char atc7[] = "AT#SHFEC=1"; // handsfree echo canceller const char atc8[] = "AT+CLVL=12"; // loudspeaker volume level const char atc9[] = "AT#SRS= 3,0"; // select ringer sound const char atc10[] = "ATS0=0"; // number of rings to auto answer (auto answer disabled) int GSM_OK = 0; int GSM_RING = 1; char gsm_state = 0; char response_rcvd = 0; short responseID = -1, response = -1; // copy const to ram string char * CopyConst2Ram(char * dest, const char * src){ char * d ; d = dest; for(;*dest++ = *src++;) ; return d; } void interrupt() { char tmp; if (PIR1bits.RCIF == 1) { tmp = ReadUSART(); switch (gsm_state) { case 0: { response = -1; // clear response if (tmp == 'O') // we have 'O', it could be "OK" gsm_state = 1; // expecting 'K' if (tmp == 'R') // we have 'R', it could be "RING" gsm_state = 10; // expecting 'I' break; } case 1: { if (tmp == 'K') { // we have 'K' -> response = GSM_OK; // we have "OK" response gsm_state = 50; // expecting CR+LF } else gsm_state = 0; // reset state machine break; } case 10: { if (tmp == 'I') // we have 'I', it could be "RING" gsm_state = 11; // expecting 'N' else gsm_state = 0; // reset state machine break; } case 11: { if (tmp == 'N') // we have 'N', it could be "RING" gsm_state = 12; // expecting 'G' else gsm_state = 0; // reset state machine break; } case 12: { if (tmp == 'G') { // we have 'G' -> response = GSM_RING; // we have "RING" response gsm_state = 50; // expecting CR+LF } else gsm_state = 0; // reset state machine break; } case 50: { if (tmp == 13) // we have 13, it could be CR+LF gsm_state = 51; // expecting LF else gsm_state = 0; // reset state machine break; } case 51: { if (tmp == 10) { // we have LF, response is complete response_rcvd = 1; // set reception flag responseID = response; // set response ID } gsm_state = 0; // reset state machine break; } default: { // unwanted character gsm_state = 0; // reset state machine break; } } } } // send ATC command void send_atc(const char *s) { // send command string while(*s) { WriteUSART(*s++); } // terminate command with CR WriteUSART(0x0D); } // get GSM response, if there is any short get_response() { if (response_rcvd) { response_rcvd = 0; return responseID; } else return -1; } // wait for GSM response void wait_response(char rspns) { while (get_response() != rspns) ; } // pause void wait() { Delay1KTCYx(1000); } void main(){ /*************199********************************************************************************************************************/ // all pins as digital I/Os ANSEL = 0; ANSELH = 0; // set PORTD inputs TRISDbits.TRISD0 = 1; // place a call input TRISDbits.TRISD1 = 1; // hang up input TRISDbits.TRISD2 = 1; // answer a call input TRISDbits.TRISD3 = 1; // continue with PIC program // set RTS pin to zero, we will use only RX i TX TRISCbits.TRISC3 = 0; PORTCbits.RC3 = 0; // enable uart rx interrupt PIE1bits.RCIE = 1; INTCONbits.PEIE = 1; INTCONbits.GIE = 1; /*215********************************************************************************************************************************/ // initialize USART module putrsUSART ((const far rom char *)"AT+IPR=19200\r"); Delay1KTCYx(5000); // wait for the GSM module to initialize it self // negotiate baud rate while(1) { send_atc("AT"); // send "AT" string until gsm sets up its baud rade Delay1KTCYx(100); // and gets it correctly if (get_response() == GSM_OK) // if gsm says "OK" on our baud rate we got it break; } // disable command echo send_atc(atc1); wait_response(GSM_OK); send_atc(atc3); wait_response(GSM_OK); // change audio path (enables handsfree external mic/ear audio path) send_atc(atc2); wait_response(GSM_OK); // handsfree microphone gain send_atc(atc6); wait_response(GSM_OK); // handsfree echo canceller send_atc(atc7); wait_response(GSM_OK); // loudspeaker volume level send_atc(atc8); wait_response(GSM_OK); // select ringer sound send_atc(atc9); wait_response(GSM_OK); // number of rings to auto answer (auto answer disabled) send_atc(atc10); wait_response(GSM_OK); }
Comment