I'm going to interface a SIM900 module to atmega 128a mcu via a UART0 port. I was successfully able to communicate with sim900 module using putty serial interface and got the responses. Now my target is to get response into a char array and process the response. General syntax of a AT command is as follows
AT\r\n //Command sent to modem
AT\r\nOK\r\n //Response from modem with echo enabled
As this syntax doesn't have a termination character or a fixed length can you suggest me a method to get the full response. I have tried this code but it gives a partial response from the sim900 module.
// Code to receive one byte at a time uint8_t USART0ReceiveByte() { // Wait for byte to be received while(!(UCSR0A&(1<<RXC0))){}; // Return received data return UDR0; }
// Code to receive the response string void USART0ReceiveString() { int i=0; while(1) { name[i]=USART0ReceiveByte(); if (name[i]=='\n') break; else i++; } name[i++]='\0'; }
Sample responsees for the AT commands
- AT{0D}{0A}{0D}{0A}OK{0D}{0A}
- AT+CSQ{0D}{0A}{0D}{0A}+CSQ: 19,0{0D}{0A}{0D}{0A}OK{0D}{0A}
- AT+CGATT?{0D}{0A}{0D}{0A}+CGATT: 1{0D}{0A}{0D}{0A}OK{0D}{0A}
- AT+HTTPACTION=0{0D}{0A}{0D}{0A}OK{0D}{0A}{0D}{0A}+HTTPACTION:0,200,6{0D}{0A}
- AT+HTTPREAD{0D}{0A}{0D}{0A}+HTTPREAD:6{0D}{0A}58E2A8{0D}{0A}OK{0D}{0A}
Please suggest me a method to get the full response from sim900 module.
Thank You!