Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[SOLVED] GSM module interfacing problem to AVR

Status
Not open for further replies.

Briez

Member level 5
Member level 5
Joined
Nov 30, 2012
Messages
83
Helped
4
Reputation
8
Reaction score
4
Trophy points
1,288
Activity points
1,835
Hello,


I want to interface GSM module with atmega32.

I have wrote a c code using avr studio 4 and compiler winavr using 16MHZ crystal.

But when i send sms sending AT command, GSM module doesnt send sms.

I have checked my gsm module in hyperterminal. It is an okay.

I am sending commands as follow,
Code:
AT\r 
delay(1000); //millisecond 
ATE0\r 
delay(1000); //millisecond 
AT+CMGF=1\r 
delay(1000); //millisecond 
AT+CMGS="xxxxxxxxxx"\r 
delay(100); //millisecond 
(Message) 
Ctrl+Z

when i transmit "AT" to GSM it responds me with "PU".

What will be the problem?
 

Mention the functions used to send character and string to USART.

gsm2lcd2.png

92193d1370750609-gsm2lcd2.png


92183d1370708194-smsbriez4.png



This code is for 8 MHz clock. delay is causing the problem. If you use 16 MHz clock then double the delays. The delays are not giving exact milliseconds.


Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
send_string("AT+CMGF=1");
send_data(0x0D);
send_data(0x0A);
_delay_ms(2000);
send_string("AT+CMGS=");
send_data(0x22);
send_string("974245XXXX");
_delay_ms(200);
send_data(0x22);
send_data(0x0D);
send_data(0x0A);
_delay_ms(500);
send_string("Hello from Jayanth");
send_data(0x0D);
_delay_ms(5000);
send_data(26);
send_data(0x0D);
_delay_ms(8000);

 

Attachments

  • smsbriez4.png
    smsbriez4.png
    93.3 KB · Views: 146
Last edited:
  • Like
Reactions: Briez

    Briez

    Points: 2
    Helpful Answer Positive Rating
if i send AT+CMGR=1 some garbage data display on LCD.

My code is,

Code:
#define F_CPU 16000000UL

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

#define BAUD 9600
#define MYUBRR ((( F_CPU / ( BAUD * 16UL))) - 1)

#define rx_on	UCSRB|=(1<<RXCIE);
#define rx_off	UCSRB&=~(1<<RXCIE);

void uart_init(unsigned int ubrr);
void send_string(unsigned char *str);
void send_data(unsigned char back);
void reset_flush(void);

unsigned char ReceivedByte[200];
unsigned char count,i=0,j,k,data,AT_ack=1;


int main(void)
{

DDRB=0xFF;
DDRA=0xFF;
DDRC=0xFF;
DDRD=0xFE;


PORTD=0x00;

MCUCSR|=(1<<JTD);
MCUCSR|=(1<<JTD);

lcd_init();	

uart_init(MYUBRR);

_delay_ms(500);

lcd_send_R1(0,"GSM_init");

sei();
_delay_ms(50);
rx_off;
_delay_ms(500);


while(1)

  {
/*******************************************************************************/
//								AT+CMGR=1									//
/*******************************************************************************/
	send_string("AT+CMGR=1");				//send "AT" to GSM
	send_data(0x0D);
	send_data(0x0A);
	rx_on;							// checking response from GSM
	_delay_ms(10000);
	rx_off;	

	for(k=0;k<16;k++)
	  {
	  	lcd_cmd(0x80+k);
		lcd_data1(ReceivedByte[k]);
		_delay_ms(500);
	  }

	for(k=16;k<32;k++)
	  {
	 	k=k-16;
		lcd_cmd(0xC0+k);
		lcd_data1(ReceivedByte[k]);
		_delay_ms(500);
	  }

	for(k=32;k<48;k++)
	  {
	 	k=k-32;
		lcd_cmd(0x80+k);
		lcd_data1(ReceivedByte[k]);
		_delay_ms(500);
	  }



	reset_flush();
	_delay_ms(5000);

/*******************************************************************************/


  }

return 0;

}

/*******************************************************************************/
//							UART Initialization									//
/*******************************************************************************/
void uart_init(unsigned int ubrr)
{

UBRRH = (uint16_t)(ubrr>>8);
UBRRL = (uint16_t)ubrr;

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

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

/*******************************************************************************/
//									char send to UART							//
/*******************************************************************************/

void send_data(unsigned char back)
{
  
  while( !( UCSRA & (1<<UDRE)) ) ;

    UDR=back;
}

/*******************************************************************************/
//									String send to UART							//
/*******************************************************************************/

void send_string(unsigned char *str)
{

	while(*str)
	  {
         send_data(*str++);
	  }
}

/*******************************************************************************/
//									Reset Buffer								//
/*******************************************************************************/
void reset_flush(void)
{
  i=0;
  count=0;
  for(j=0;j<200;j++)
    {
		ReceivedByte[j]='\0';
    }
}

ISR ( USART_RXC_vect )
{

	count=UDR;

if(count!=0x0D && count!=0x0A && count!='>' && count!='"')					//Do not Print \r\n and ">"
  {
	ReceivedByte[i]=count;
	i++;
  }

if(i==200)
  {
   i=0;
  }
}


Where i am making mistake?
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top