Microcontroller › AVR › How to interface GSM modem TO atmega16 › My GSM modem and AVR usart
March 31, 2011 at 2:03 pm
#5846
Participant
My GSM modem and AVR usart are working fine individually….but when i connect modem to controller,i
#include<avr/io.h>
#include<util/delay.h>
#define F_CPU 11059200UL
#define USART_BAUDRATE 9600 // Baud Rate value
#define BAUD_PRESCALE (((F_CPU / (USART_BAUDRATE * 16UL))) – 1)
#define LCD_DATA PORTB //LCD data port
#define ctrl PORTD
#define en PD2 // enable signal
#define rw PD3 // read/write signal
#define rs PD4 // register select signal
void usart_putstr(char * s);
void LCD_cmd(unsigned char cmd);
void init_LCD(void);
void LCD_write(unsigned char data);
void usart_init();
static void usart_putch(unsigned char send);
unsigned int usart_getch();
void gotoxy(unsigned char row,unsigned char column);
static void LCD_String(char *s);
int main()
{
unsigned char value,i;
DDRB=0xff; // LCD_DATA port as output port
PORTB=0x00;
DDRD|=0xFC;
init_LCD(); //initialization of LCD
_delay_ms(50); // delay of 50 milli seconds
usart_init(); // initialization of USART
gotoxy(1,1);
//char a[] = “AT”;
char b[] = “AT+CMGS=”;
char no[]=”+919595955635″;
char body[] = “Successful”;
{
//usart_putstr(a);
//_delay_ms(5);
// usart_putstr(“rn”);
// _delay_ms(100);
usart_putstr(b);
_delay_ms(100);
usart_putch(‘”‘);
// _delay_ms(100);
usart_putstr(no);
// _delay_ms(100);
usart_putch(‘”‘);
_delay_ms(100);
usart_putch(‘r’);
usart_putch(‘n’);
_delay_ms(100);
usart_putstr(body);
_delay_ms(100);
usart_putch(0x1A);
// for (i=0;i<16;i++)
// {
// value=usart_getch(); // Call a function to get data from serial port
// _delay_ms(100);
// LCD_write(value); // write data to LCD
// }
// gotoxy(2,1);
}
return 0;
}
void init_LCD(void)
{
LCD_cmd(0x38); // initialization of 16X2 LCD in 8bit mode
_delay_ms(1);
LCD_cmd(0x01); // clear LCD
_delay_ms(1);
LCD_cmd(0x0E); // cursor ON
_delay_ms(1);
LCD_cmd(0x80); // —8 go to first line and –0 is for 0th position
_delay_ms(1);
return;
}
void LCD_cmd(unsigned char cmd)
{
LCD_DATA=cmd;
ctrl &=~ (1<<rs);
ctrl&=~(1<<rw);
ctrl|=(1<<en); // RS and RW as LOW and EN as HIGH
_delay_ms(1);
ctrl &=~ (1<<rs);
ctrl&=~(1<<rw);
ctrl&=~(1<<en); // RS, RW , LOW and EN as LOW
_delay_ms(1);
return;
}
void LCD_write(unsigned char data)
{
LCD_DATA= data;
ctrl |= (1<<rs);
ctrl&=~(1<<rw);
ctrl|=(1<<en); // RW as LOW and RS, EN as HIGH
_delay_ms(1);
ctrl |= (1<<rs);
ctrl&=~(1<<rw);
ctrl&=~(1<<en); // EN and RW as LOW and RS HIGH
_delay_ms(1); // delay to get things executed return ;
}
void usart_init()
{
UBRRL = 0x47;
// UBRRL = (unsigned char)BAUD_PRESCALE;
// Load lower 8-bits of the baud rate value into the low byte of the UBRR register
// UBRRH = (unsigned char)(BAUD_PRESCALE>>
; // Load upper 8-bits of the baud rate value..

_delay_ms(1);
UCSRB |= (1 << RXEN) | (1 << TXEN); // Turn on the transmission and reception circuitry
UCSRC |= (1 << URSEL) | (1<<USBS) | (1 << UCSZ0) | (1 << UCSZ1);
// Use 8-bit character sizes
}
unsigned int usart_getch()
{
while (!(UCSRA & (1 << RXC)) );
// Do nothing until data has been received and is ready to be read from UDR
_delay_ms(1);
return(UDR); // return the byte
}
static void usart_putch(unsigned char send)
{
while ((UCSRA & (1 << UDRE)) == 0); // Do nothing until UDR is ready..
// for more data to be written to it
UDR = send; // Send the byte
}
void gotoxy(unsigned char row,unsigned char column)
{
switch (row)
{
case 1: LCD_cmd (0x80 + column – 1); break;
case 2: LCD_cmd (0xc0 + column – 1); break;
default: break;
}
}
static void LCD_String(char *s)
{
register char c;
while((c = *s++))
{
_delay_ms(10);
LCD_write(c);
}
return;
}
void usart_putstr(char * s)
{
while(*s)
{
usart_putch(*s++);
}
}
am not receiving messages…