我正在使用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++;
}
答案 0 :(得分:0)
你是唯一和我有完全相同问题的人。
不知何故,来自gsmlib.org的库工作但直接使用Arduino串行监视器输入AT命令,使用Arduino作为桥接器,或者只是FTDI没有。
原因是SIM900显然希望命令以“\ r”字符结尾。我通过尝试GTKTerm找到了这个。
如果输入“AT”并在GTKTerm中输入,实际发送的是“AT”,后跟两次'\ r'(0x0d)和一次0x0a
答案 1 :(得分:0)
默认情况下,GSM模块处于回显ON模式。你需要改变你的命令。
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