【问题标题】:Sim900 only echos back the commands- No responseSim900 只回显命令 - 无响应
【发布时间】:2016-04-19 08:02:16
【问题描述】:

我在一个项目中使用 Atmega32 和 sim900。我一直发送“AT”命令并等待“OK”响应,但我得到的只是 AT\r\n。我已经检查并重新检查了接线和波特率,但仍然没有得到任何结果。无论我向 sim900 发送什么,我都只会得到相同传输字符串的回显。

谁能帮帮我?我真的很感激。

我在这里发布我的代码:

int sim900_init(void)
{   
    while(1)
    {
    sim_command("AT");
    _delay_ms(2000);
    }
return 0;
}

void usart_init(void)
{
/************ENABLE USART***************/
    UBRRH=(uint8_t)(MYUBRR>>8);
    UBRRL=(uint8_t)(MYUBRR);                         //set baud rate
    UCSRB=(1<<TXEN)|(1<<RXEN);             //enable receiver and transmitter
    UCSRC=(1<<UCSZ0)|(1<<UCSZ1)|(1<<URSEL);  // 8bit data format

    UCSRB |= (1 << RXCIE); // Enable the USART Recieve Complete interrupt (USART_RXC)

/***************FLUSH ALL PRIVIOUS ACTIVITIES********************/

    flush_usart();

/*********APPOINT POINTERS TO ARRAYS********************/

    command=commandArray;       // Assigning the pointer to array
    response=responseArray;     //Assigning the pointer to array

/*****************ENABLE INTRUPT***************************/
sei();                          //Enabling intrupts for receving characters
}


void flush_usart(void)
{
    response_full=FALSE;        //We have not yet received the  
}

void transmit_char(unsigned char value)
{
    while (!( UCSRA & (1<<UDRE)));            // wait while register is free
    UDR = value; 
}

void sim_command(char *cmd)
{
    int j=0;
    strcpy(command,cmd);
    while(*(cmd+j)!='\0')
    {
         transmit_char(*(cmd+j)); 
         j++;
    }
     transmit_char(0x0D);   // \r                   // after all the at commands we should send \r\n so, we send it here after the string
     transmit_char(0x0A);   // \n

}

unsigned char recieve_char(void)
{   
    char temp;
    while(!(UCSRA) & (1<<RXC));           // wait while data is being received
    temp=UDR;
    LCDdata(lcdchar,temp);
    return temp;
}

void recive_sim900_response(void)
{
    static int i=0;
    char temp;
    temp=recieve_char();

    if(temp!='\n' && temp!='\r')        // We dont want \r \n that will be send from Sim so we dont store them
    *(response+i)=temp;

        if(i==8)                    //when null char is sent means the string is finished- so we have full response
        {                               //we use them later in WaitForResponse function. we wait until the full response is received
            i=0;                                    
            response_full=TRUE;
        }
        else
            i++;
}

【问题讨论】:

  • 在您显示的代码中,您永远不会调用recive_sim900_response() 或任何东西。 (不相关,但是:您的响应缓冲区真的是 9 字节吗?)
  • flush_usart() 还应该将索引重置到缓冲区中(现在是 recive_sim900_response() 内的 static int i。)
  • if(temp!='\n' &amp;&amp; temp!='\r') 后面缺少大括号。
  • "// 启用 USART 接收完成中断" - 为什么?你有相应的 ISR 吗?

标签: echo response avr at-command sim900


【解决方案1】:

你是唯一一个和我有同样问题的人。

gsmlib.org 的库以某种方式工作,但使用 Arduino 串行监视器直接输入 AT 命令,使用 Arduino 作为桥接器或只是 FTDI 没有。

原因显然是 SIM900 期望命令以 '\r' 字符结尾。我通过尝试有效的 GTKTerm 发现了这一点。

如果在 GTKTerm 中输入“AT”并按回车,实际发送的是“AT”,后跟两个 '\r' (0x0d) 和一个 0x0a

【讨论】:

    【解决方案2】:

    默认情况下,GSM 模块处于回显模式。你需要改变你的命令。

    sim_command("AT");
    

    你需要在 Command 之后 Enter=CR/LF 所以像这样修改你的代码并试一试

    sim_command("AT\r");
    

    如果您想关闭您发送的命令的回显,那么您应该在收到 AT 命令的 OK 响应后发送此命令。

    sim_command("ATE0\r"); //Echo back OFF
    sim_command("ATE1\r"); //Echo back ON
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-04-09
      • 2020-11-03
      • 2022-10-08
      • 1970-01-01
      • 2022-01-18
      • 2017-10-15
      • 1970-01-01
      相关资源
      最近更新 更多