Connect with us

interfacing gsm to avr atmega 8

Discussion in 'Microcontrollers, Programming and IoT' started by VARUNI P RAO, Jul 17, 2014.

Scroll to continue with content
  1. VARUNI P RAO

    VARUNI P RAO

    4
    0
    Jul 17, 2014
    My project is to monitor the temperature and when the temperature goes beyond a specified value i need to send message through gsm. gsm was tested with hyperterminal and it worked well. But i am not getting any response when i connect it to microcontroller. i also verified that avr is sending the serial data by using teraterm
    I connected PD.0 and PD.1 to tx and rx of gsm modem. LM35 was connected to channel 3 0f PC(adc). i have used the following code


    #include<avr/io.h>
    #include<avr/interrupt.h>
    #include"uart.h"
    #include"adc.h"
    #include<util/delay.h>
    void main()// read lm35 value in blueterm
    {

    uartinit();


    unsigned char x,y,flag=0;
    adc_init();
    while(1)
    {
    x=getdata(3);// GETTING ADC VALUE
    y=(5.0/1024)*x*100;// CALCULATING TEMPERATURE

    _delay_ms(200);
    if(y>10)// IF TEMPERATURE IS ABOVE 10DEG
    {
    printstring("AT ");
    printstring("\r \n");
    printstring("AT+CMGF=1");
    printstring(" \r \n");
    printstring("AT+CMGS=");
    printchar(0x22);
    printstring("9901902109");
    printchar(0x22);
    printstring("\r \n");
    _delay_ms(200);
    printstring("overHEATING");
    printchar(0x1a);
    flag=1;// MAKE FLAG AS 1
    }
    if(flag==1)// IF THE MESSAGE IS SENT ONCE
    break;
    }
    while(1);
    }




    #ifndef _adc_h_
    #define _adc_h_
    #include<util/delay.h>
    void adc_init()
    {
    ADMUX=0X40;
    ADCSRA=0XE6;
    }

    int getdata(unsigned int channel)
    {
    unsigned int zed,low, high;
    ADMUX=ADMUX|channel;
    _delay_ms(1);
    low=ADCL;
    high= ADCH;
    zed=low+(high<<8);
    return(zed);
    }
    #endif







    #ifndef _UART_H_
    #define _UART_H_

    void uartinit()
    {
    UCSRA=0x00;
    UCSRB=0x18;
    UCSRC=0x86;
    UBRRH=0x00;
    UBRRL=75;
    delayuart(1000);
    }

    void printchar(unsigned char uchar)
    {
    UDR=uchar;
    while((UCSRA&0x40)==0x00);
    delayuart(1000);
    }
    void printstring(const unsigned char *ustring)
    {
    while ( *ustring )
    {
    printchar( *ustring++);

    } }

    void printnum(unsigned int num)
    {
    unsigned char paa=0, H=0,T=0,O=0;
    paa=num/1000;

    H=(num-(paa*1000))/100;
    T=(num -(paa*1000) -(H*100))/10;
    O=(num - (paa*1000) -(H*100) - (T*10));

    if(paa!=0)
    {printchar(paa+48);}
    printchar(H+48);

    printchar(T+48);

    printchar(O+48);

    }
    unsigned char dispdata()
    {
    while((UCSRA&0x80)==0x00);
    return UDR;
    }
    void delayuart(unsigned int delaytime)
    {
    unsigned int dc;
    for(dc=0;dc<=delaytime;dc++)
    {

    asm("nop");asm("nop");asm("nop");asm("nop");asm("nop");asm("nop");
    asm("nop");asm("nop");asm("nop");asm("nop");
    }
    }


    #endif
    please help me.
     
  2. KrisBlueNZ

    KrisBlueNZ Sadly passed away in 2015

    8,393
    1,268
    Nov 28, 2011
    Hi Varuni and welcome to Electronics Point.

    Look in the data sheet for the GSM modem to see whether you need to send an initialisation string (so it can detect the baud rate you are using) and whether you need to wait in between sending command strings to it.

    Also, upload a schematic of the interface between your microcontroller and the GSM modem, and a link to the data sheet for the GSM modem you are using.
     
  3. VARUNI P RAO

    VARUNI P RAO

    4
    0
    Jul 17, 2014
  4. KrisBlueNZ

    KrisBlueNZ Sadly passed away in 2015

    8,393
    1,268
    Nov 28, 2011
    Does that modem connect directly to an RS-232 port? If so, you need to use an RS-232 transceiver (e.g. MAX232) between your microcontroller and the modem.
     
  5. VARUNI P RAO

    VARUNI P RAO

    4
    0
    Jul 17, 2014
    Our modem has 2 options. Rs232 port is there, with max 232 ic already in that pcb .. and directly there are 2 pins tx and rx..

    I tried connecting in both ways. But no sms was sent.
     
  6. VARUNI P RAO

    VARUNI P RAO

    4
    0
    Jul 17, 2014
    I am able to view the at commands in teraterm when, rx and tx of avr microcontroller is connected to pc through cp2100..
    But when connected to gsm modem, sms is not getting sent by it.
     
  7. KrisBlueNZ

    KrisBlueNZ Sadly passed away in 2015

    8,393
    1,268
    Nov 28, 2011
    You haven't given us enough information to tell what you're doing wrong.

    Does the modem need an initialisation string?

    Does it require delays between commands?

    What is "cp2100" that you mentioned?

    Upload a schematic showing exactly how you have connected the microcontroller to the modem using a direct logic-level (not RS-232) connection.

    Provide a link to the data sheet for the modem. The link you posted earlier is just to the sales page; I couldn't find a link to the data sheet.
     
Ask a Question
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.
Electronics Point Logo
Continue to site
Quote of the day

-