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.

[AVR] problem about communication with sim900a through atmega16

Status
Not open for further replies.

balvendrajat

Newbie level 5
Joined
Dec 3, 2014
Messages
10
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Location
Bhilwara, India
Activity points
81
hi
i created a circuit for control a device from a phone in which i use
mcu-atmega16
gsm modem- sim900A from simcom
power supply for GSM-9V, 2Amps
in this when i called from a particular NO. there is no response from the controller so what i do please help me
my code is like this

Code:
#include <avr/io.h>
#include <avr/interrupt.h>
#include <util/delay.h>
#include <uart_lib.h>
#include <stdio.h>



static unsigned char c;

static char line=0, status = 0,index = 0,mob[10] = "          ", A[20]="asdfghjk";
ISR(USART_RXC_vect)
{
	c = UDR;
	if(index<16)
A[index]=c;
	index++;
	if (c==0x0A)
{
status|=1;
index = 0;
line=0;
}

	else if(index == 5)
{
			 if((strncmp(A,"+CMTI",5) == 0))
{
 status|=4;
line=1;
}
		else if((strncmp(A,"+CLIP",5) == 0))
{
 status|=2;
line=1;
}
		else if((strncmp(A,"NO CA",5) == 0))
{
 status&=~2;
line=1;
}
	}
	else if(index>11&index<22&(status>>1))mob[index-12]=c;
}




int main(void) {
	DDRA|=(1<<0);
	set_uartbaud(9600);
	enable_uart_rxcint();
	
	sei();
	_delay_ms(2000);
	sendstring_uart("AT\r");
	sendstring_uart("at+clip=1\r");
	_delay_ms(2000);
	while (1)
 {
		if(status==3)
{
			_delay_ms(100);
		if(status>>1&(strncmp(mob,"9694324852",10) == 0))
{
			sendstring_uart("ath\r");
			PORTA^=(1<<0);
			status=1;
		}
	
		}

		
	}
}

i also use library
uart_lib.c


Code:
#include<uart_lib.h>
#include<avr/io.h>
#include<util/delay.h>
#define FOSC 4000000
void set_uartbaud(int BAUD)
{
	UBRRH = (unsigned char)((FOSC/16/BAUD-1)>>8);
	UBRRL = (unsigned char)(FOSC/16/BAUD-1);
	UCSRC|=(1<<URSEL)|(1<<UCSZ1)|(1<<UCSZ0);
	UCSRB|=(1<<RXEN)|(1<<TXEN);
}

void disable_uart()
{
	UCSRB&=~(1<<TXEN);
	UCSRB&=~(1<<RXEN);
}



void enable_uart_txcint()
{
	UCSRB|=(1<<TXCIE);
}

void enable_uart_rxcint()
{
	UCSRB|=(1<<RXCIE);
}

void enable_uart_udreint()
{
	UCSRB|=(1<<UDRIE);
}

void disable_uart_txcint()
{
	UCSRB&=~(1<<TXCIE);
}

void disable_uart_rxcint()
{
	UCSRB&=~(1<<RXCIE);
}

void disable_uart_udreint()
{
	UCSRB&=~(1<<UDRIE);
}

void sendchar_uart(char data)
{
	int temp;
	temp=UCSRA&(1<<UDRE);
	temp=temp>>UDRE;
	while(!temp)
	{

	}
	UDR=data;
}

char getchar_uart()
{
	// Wait until a byte has been received

	while((UCSRA&(1<<RXC)) == 0);

	// Return received data

	return UDR;

}

void sendstring_uart(char v[])
{
	int i;
	for(i=0;i<strlen(v);i++)
	{
		sendchar_uart(v[i]);
		_delay_ms(10);
	}
}



and uart_lib.h

Code:
#include <avr/io.h>

#define FOSC 4000000// Clock Speed


please help me sir....
 
Last edited by a moderator:

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top