Problem reading "OK" on AT command

Status
Not open for further replies.

lloydi12345

Member
I tried AT commands on hyperterminal and they have no problem. I have written a program and it just can't receive the character 'O' or even 'K' on its uart1_read(). I don't know if it's because of the phone or because of the simulation. I checked everything by virtual terminal using Proteus and the phone used is T68i ericsson. The format allowed only is in PDU.

Code:
char i;
char rec[10];
char old;

void main(){
portb = 0x00;
adcon1 = 0x06;
cmcon = 0x07;
trisb = 0x00;

uart1_init(9600);
delay_ms(500);

uart1_write_text("AT\r");    // Send "AT" and press enter
delay_ms(2000);
i = 0;
do {
  while(!UART1_Data_Ready()) {
   ; // just wait here until a char appears
  }
  old = UART1_Read();
  rec[i++] = old;
} while (old != 'O');
portb = 0xff;   // Flash LEDs
}

if I change the while statement to this:
Code:
while (old != 'A')
or even this:
Code:
while (old != 'T)
it works fine. But I don't really have any interest on the echoed message, I want to check if I'm receiving "OK" message.

Can you help me how to check "OK" here on mikroC PRO?
 

Attachments

  • sms.PNG
    133.4 KB · Views: 234
Last edited:
Thanks ericgibbs for the reply. In mikroc \r is carriage return. You can see it on the image I attached that I was able to receive an "OK" response Can you help me further?
 
Thanks ericgibbs for the reply. In mikroc \r is carriage return. You can see it on the image I attached that I was able to receive an "OK" response Can you help me further?

hi,
The problem is I don't program in 'C'...
 
Get rid of the delay and check for both characters. Something like,
Code:
    uart1_write_text("AT\r");    // Send "AT" and press enter
    [COLOR="red"]//  delay_ms(2000); No delay!![/COLOR]
    i = 0;
    do {
          while(!UART1_Data_Ready()) {
          ; // just wait here until a char appears
        }
        old = UART1_Read();
        rec[i++] = old;
    } [COLOR="red"]while ((rec[i-2]!='O')&&(rec[i-1]!='K''));[/COLOR]
    portb = 0xff;   // Flash LEDs
}

Mike.
 
One other issue is that you can't guarantee that the buffer is clear when your program sends "AT". Just connecting the cable often adds some spurious characters,
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…