Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

problem with reciving answer from sim800

Mr.eyni

Newbie level 5
Joined
Jan 12, 2014
Messages
9
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,333
When I give the AT command to the module. The module should give me the answer AT\r\nOK\r\n but to my surprise it gives the answer AT\r\r\nOOK\r\n. I understood this problem by getting the answer from the code below. While if I delete the wrong lines from the code below, the module does not respond.


C:
Send_AT();
    do
    {
      buffer=get_char();
    }while(buffer!='A');
    
    
        buffer=get_char();
        if(buffer=='T')
                   {
                       buffer=get_char();
               if(buffer=='\r')
                          {
                             buffer=get_char();
                             if(buffer=='\r')
                                  {                             
                                      buffer=get_char();
                                      if(buffer=='\n')
                                              {
                                                  buffer=get_char();
                                                   if(buffer=='O')
                                                           {
                                                                 if(buffer=='O')
                                                                    {
                                                                           buffer=get_char();
                                                                           if(buffer=='K')
                                                                                {
                                                                                     buffer=get_char();
                                                                                     if(buffer=='\r')
                                                                                           {                                                                                             
                                                                                             buffer=get_char();
                                                                                             if(buffer=='\n')
                                                                                                    {                                                                                   
                                                                                                                   for(i=0;i<5;i++)
                                                                                                                    {
                                                                                                                            HAL_GPIO_WritePin(GPIOC,GPIO_PIN_13,GPIO_PIN_SET);
                                                                                                                            HAL_Delay(500);       
                                                                                                                            HAL_GPIO_WritePin(GPIOC,GPIO_PIN_13,GPIO_PIN_RESET);
                                                                                                                            HAL_Delay(500);
                                                                                                                    }
                                                                                                    }
                                                                                           }
                                                                                }
                                                                    }
                                                           }
                                              }
                                  }                       
                          }       
                   }
 
Hello!

I haven't played with AT commands in the past 20 yeard, but you should never write such a heap of code.
What you should write is something like:

const char at_cmd[] = "AT\n";
const char ok_string[] = "AT\r\nOK\n";

char reply[0x10];

uart_send(at_cmd);
uart_recv(reply);

And then compare the reply with the AT ok string.

Beside this, the command you call "Send_AT()" is in fact only receiving character, so this is already a problem.
Of course, you have the right of naming your functions the way you want. You can name "CloseFile" a function that
in fact opens a file, but it will not improve the readability of your code. That said, shutting down windows is done
from the start menu but it's not a reason to make the same kind of mistake.

Dora.
 
Hello!

I haven't played with AT commands in the past 20 yeard, but you should never write such a heap of code.
What you should write is something like:

const char at_cmd[] = "AT\n";
const char ok_string[] = "AT\r\nOK\n";

char reply[0x10];

uart_send(at_cmd);
uart_recv(reply);

And then compare the reply with the AT ok string.

Beside this, the command you call "Send_AT()" is in fact only receiving character, so this is already a problem.
Of course, you have the right of naming your functions the way you want. You can name "CloseFile" a function that
in fact opens a file, but it will not improve the readability of your code. That said, shutting down windows is done
from the start menu but it's not a reason to make the same kind of mistake.

Dora.
The idea you put forward to simplify AT command handling is spot on! Keeping code brief and clear enhances readability and maintainability. Accurate function naming also helps with code understanding. Thank you for providing this great point of view!
 
Last edited by a moderator:

LaTeX Commands Quick-Menu:

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top