UART Problem ...

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);

}

You’ve currently got a 1-second delay between sending “AT” and calling AT_rcv() to get the reply. Unless MikroC’s usart_read() does some buffering internally, this will give you at most the last three characters of the response, all the previous ones having been lost to buffer overflow. Those three characters are almost certainly not going to include the two s that your AT_rcv() is looking for, therefore it would be expected for it to hang.

The normal format for a response is “OK”. However, the exact format, and indeed the very existance of any response to “AT”, are controlled by various AT commands that you are failing to give. You really need to explicitly set the response format, command echo, numeric/verbose results, etc. before attempting to interpret any data coming back from the module.

Also, AT_rcv really needs a timeout feature so you don’t hang forever if a glitch occurs.

thank you jasonharper for your fast reply

I Doubt that the usart_read() does any internal buffering cause it isnt mentioned anywhere in the help file, so what your saying is that i should remove the 1 second delay ? , i will try this out.

thanx again

Sevan

I removed the 1 second delay and nothing happened,still the same problem.

any other suggestions?

Thanks

Sevan

Is AT_rcv() still looking for two s before returning?

Yes … but its not returning

Ok … i found out the problem , i thought the default setting for the command echo is off , i didnt read the manual carefully, my mistake anyway thanks for your help again

Sevan