Ich verwende Atmega32 und sim900 für ein Projekt. Ich sende weiterhin "AT" -Befehl und warte auf die "OK" -Antwort, aber alles, was ich bekomme, ist AT \ r \ n. Ich habe die Verkabelung und meine Baudrate überprüft und überprüft, aber immer noch nirgends hin. Was auch immer ich an sim900 sende, ich bekomme nur die gleiche übertragene Saite zurück.Sim900 gibt nur die Befehle zurück- Keine Antwort
Kann mir bitte jemand helfen? Ich würde es wirklich schätzen.
Ich poste mein Code hier:
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++;
}
In dem Code, den Sie anzeigen, rufen Sie nie 'recive_sim900_response()' oder irgendetwas auf. (Unrelated, aber: Ist Ihr Antwortpuffer wirklich ** 9 ** Byte?) – JimmyB
'flush_usart()' sollte auch den Index in den Puffer zurücksetzen (was 'static int i' innerhalb' recive_sim900_response() 'jetzt ist.) – JimmyB
Es gibt Klammern, die nach 'if (temp! = '\ N' && temp! = '\ R')' fehlen. – JimmyB