Sim900仅回显命令-没有响应

3
我正在使用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个字节吗?) - JimmyB
flush_usart() 应该重置缓冲区中的索引(现在是 recive_sim900_response() 中的 static int i)。 - JimmyB
if(temp!='\n' && temp!='\r') 后面缺少大括号。 - JimmyB
"// 启用USART接收完成中断" - 为什么?您是否已经准备好了相应的ISR?" - JimmyB
2个回答

1
你是唯一一个和我有完全相同问题的人。
不知何故,来自gsmlib.org的库可以工作,但是直接使用Arduino串行监视器输入AT命令使用Arduino作为桥梁或只是一个FTDI却不能。
原因是显然SIM900希望命令以'\r'字符结尾。我通过尝试GTKTerm找到了这个问题,它能够正常工作。
如果在GTKTerm中键入“AT”并按回车键,则实际发送的是“AT”,后跟两个'\r'(0x0d)和一个0x0a。

0

默认情况下,GSM模块处于回声开启状态。您需要更改您的命令。

sim_command("AT");

你需要在命令后输入CR/LF,所以修改你的代码像这样并尝试一下

sim_command("AT\r");

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

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

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接