Sign In

Can Not Read AT Response Of SIM 900 From ATMEGA16a

Prakash Pancholi pcpancholi@gmail.com India

Hardware: ATMEGA 16 A Interface With SIM 900 Software: AVR Studio And EXtreme Burner

Dear sir
I am trying to interface my ATMEGA16a with SIM 900 GSM modem
a. and want to Give AT command from ATMEGA16a to SIM900 and want to read response
b. I am using Baud rate for both SIM900 and ATMEGA16a as 4800 and I have connected TX pin(Pin no:-15) of ATMEGA16a with RX of SIM 900 and RX Pin of ATMEGA16a (Pin 14) with TX Pin of SIM 900.
c. I have connected SIM900 with my PC via COM port to check input/ output.
d. My ATMEGA16a giving proper AT command to SIM900 and I am able to check it also on PC via COM port, but my ATMEGA16a is not getting AT response from SIM900 .
Here is my code :-
#include <avr/io.h>
#include <inttypes.h>
# include <util/delay.h>
#include <avr/interrupt.h>


void USARTInit(uint16_t ubrr_value)
{

//Set Baud rate

UBRRL = ubrr_value;
UBRRH = (ubrr_value>>8);

/*Set Frame Format


>> Asynchronous mode
>> No Parity
>> 1 StopBit

>> char size 8

*/

UCSRC=(1<<URSEL)|(3<<UCSZ0)|(1<<UCSZ1);


//Enable The receiver and transmitter

UCSRB=(1<<RXEN)|(1<<TXEN);

sei();
}

char getchar(void)
{

while(!(UCSRA) & (1<<RXC))
{

//Do nothing
}
_delay_ms(100);
return UDR;
}



void command(char*a) //function to send a string using pointers
{
int i;
for(i=0;a[i]!='';i++)
{
while(!(UCSRA&(1<<UDRE)));
UDR=a[i];
_delay_ms(100);

}

}

void flush()
{
char temp=UDR;
_delay_ms(400);


}
int main(void)
{

char sentence[5];


USARTInit(12); // baud rate 4800
_delay_ms(1000);
command("atirn"); // command is a function to send AT command to SIM900
_delay_ms(100);
flush();
unsigned char response[15]; //array response is define , which will store response of given AT command
int i=0;
char c;
while(i<20)
{

c = getchar(); // getchar function will read char from read buffer of UART

response[i] = c;
i++;
if(c='r')
{
c=-1;
break;
}
if(c==-1)
break;

_delay_ms(300);
}

response[i] = '';
_delay_ms(1000);
command(response); // as we store response of ATI command in response string, so we transmit this
// to SIM 900 and from COM port of SIM900 connected to PC we try to read response

while(1)
{




}
}

Images

Program

#include <avr/io.h>
#include <inttypes.h>
# include <util/delay.h>
#include <avr/interrupt.h>


void USARTInit(uint16_t ubrr_value)
{

   //Set Baud rate

   UBRRL = ubrr_value;
   UBRRH = (ubrr_value>>8);

   /*Set Frame Format


   >> Asynchronous mode
   >> No Parity
   >> 1 StopBit

   >> char size 8

   */

   UCSRC=(1<<URSEL)|(3<<UCSZ0)|(1<<UCSZ1);


   //Enable The receiver and transmitter

   UCSRB=(1<<RXEN)|(1<<TXEN);

sei();
}

char getchar(void)
{
	
	while(!(UCSRA) & (1<<RXC))
	{
		
		//Do nothing
	}
 _delay_ms(100);
 	return UDR;
}



void command(char*a)                   //function to send a string using pointers
{
	int i;
	for(i=0;a[i]!='';i++)
	{
		while(!(UCSRA&(1<<UDRE)));
		UDR=a[i];
		_delay_ms(100);
		
	}
	
}	

void flush()
{
	char temp=UDR;
	_delay_ms(400);
	
	
}
int main(void)
{
 
  char sentence[5];

 
   USARTInit(12); // baud rate 4800
   _delay_ms(1000);
   command("atirn"); // command is a function to send AT command to SIM900
   _delay_ms(100);
   flush();
  unsigned char response[15]; //array response is define , which will store response of given AT command
   int i=0;
   char c;
  while(i<20)
     {
		  
		 c = getchar();  // getchar function will read char from read buffer of UART
		
	  response[i] = c;
	  i++;
	  if(c='r')
	  {
		  c=-1;
		  break;
	  }	
	  if(c==-1)	  
	  break;
	  
	   _delay_ms(300);
  }
  
  response[i] = '';
  _delay_ms(1000);
    command(response);  // as we store response of ATI command in response string, so we transmit this 
	                    // to SIM 900 and from COM port of SIM900 connected to PC we try to read response
    
    while(1)
    {
        
		
		
		
    }
}

Post a reply to Prakash Pancholi

Think you can help Prakash Pancholi ? Then post your thoughts that might help Prakash Pancholi. You will earn a lot of reputation in the technical community.

If your program is in multiple files, then ZIP the entire folder and attach below

Images and Screenshots

These helps other better understand your suggestion.