Hello, i am a bit stuck here, i am trying send my GM862 AT commands from the pick , the module is recieving the AT commands sent (i,ve tried AT#SHDN, and it turned off), but when i want the pic to check if the command is recieved the whole thing seems to get stuck, i have connected a digital oscilloscope to the recieve pin of the PIC and i could see a signal going through, but nothing seem to move, cause i’ve connected a couple of LEDs to check if the code is not going into an infinite loop… where could the error be, hardware or software … plz any help or suggestions well be highly appreciated
i have connected the RX line of GM862 to a SN74LS244 Octal Buffer/Line driver and the buffer’s output to the PIC’s RX Pin, for the transmitter i used a voltage devider ckt.
Here is the PIC code (using MikroC Compiler)
P.S. I’ve read that the form that the GM862 send back the resopnse is THE MESSAGE, is this information correct ?!?
char ATrcv[20];
unsigned short ATptr = 0;
char *AT = "AT";
char *CR = "\r";
char *LF = "\n";
const unsigned int SEC = 1000;
void AT_snd(char *s) {
while(*s) {
usart_write(*s++);
}
}
unsigned short strcmp(char *a,char *b) {
int cmp;
while(*b) {
cmp = *a - *b;
switch(cmp) {
case 0: break;
default: return 1;
break;
}
*a++;
*b++;
}
return 0;
}
void AT_rcv() {
unsigned short rcvng = 2;
unsigned char in;
ATptr = 0;
while (rcvng) {
if (usart_data_ready()) {
in = usart_read();
ATrcv[ATptr] = in;
ATptr++;
if (in == *LF) {
rcvng--;
}
}
}
ATrcv[ATptr] = 0;
}
unsigned int OK_chk() {
if (strcmp(ATrcv,"\r\n""OK""\r\n")) return 1;
else return 0;
}
void main() {
unsigned short loop = 10, z = 0;
unsigned short x, y;
//Setting I/O Ports
PORTB = 0x80;
TRISB = 0;
delay_ms(SEC);
PORTB = 0xC0;
delay_ms(SEC);
PORTB = 0x80;
delay_ms(SEC);
//Turning ON the GM-862, which requires at least a 1 second pulse on the
//Transistor's Base to ground the On/Off Pin
PORTB.F1 = 1;
Delay_ms(SEC*2); //2 Second Delay
PORTB.F1 = 0;
Delay_ms(SEC*10);
//Initiallize USART Communication Module
//at (8 bit, 9600 baud rate, no parity bit..)
Usart_Init(9600);
Delay_ms(SEC); //1 Second Delay
//Start sending AT Commands
intialization:
AT_snd(AT);
AT_snd(CR);
PORTB = 0xC0;
delay_ms(SEC);
AT_rcv();
if (OK_chk() == 1) goto intialization;
PORTB = 0x80;
delay_ms(SEC);
setbaudrate:
AT_snd(AT);
AT_snd("+IPR=9600");
AT_snd(CR);
PORTB = 0xC0;
delay_ms(SEC);
AT_rcv();
if (OK_chk() == 1) goto setbaudrate;
delay_ms(SEC*10);
AT_snd(AT);
AT_snd("#SHDN");
AT_snd(CR);
}