Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

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
    sms.PNG
    133.4 KB · Views: 229
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.

Latest threads

New Articles From Microcontroller Tips

Back
Top