how to program GSM module in avr...??

Go To Last Post
7 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

how to program GSM module in avr...??

Last Edited: Fri. Oct 16, 2015 - 02:16 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Depends on the module used. Since your questions says absolutely nothing at all about that, the answer will be on the same level of abstraction:

Write code.

As of January 15, 2018, Site fix-up work has begun! Now do your part and report any bugs or deficiencies here

No guarantees, but if we don't report problems they won't get much of  a chance to be fixed! Details/discussions at link given just above.

 

"Some questions have no answers."[C Baird] "There comes a point where the spoon-feeding has to stop and the independent thinking has to start." [C Lawson] "There are always ways to disagree, without being disagreeable."[E Weddington] "Words represent concepts. Use the wrong words, communicate the wrong concept." [J Morin] "Persistence only goes so far if you set yourself up for failure." [Kartman]

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

i am using SIM300 module and i am getting problem to read new arrived message from module....

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Show code.

Describe problem more specifically than just "getting problem".

As of January 15, 2018, Site fix-up work has begun! Now do your part and report any bugs or deficiencies here

No guarantees, but if we don't report problems they won't get much of  a chance to be fixed! Details/discussions at link given just above.

 

"Some questions have no answers."[C Baird] "There comes a point where the spoon-feeding has to stop and the independent thinking has to start." [C Lawson] "There are always ways to disagree, without being disagreeable."[E Weddington] "Words represent concepts. Use the wrong words, communicate the wrong concept." [J Morin] "Persistence only goes so far if you set yourself up for failure." [Kartman]

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

HERE IS THE CODE FOR YOU . HERE ATMGA168 IS USED,, WHEN MSG IS SENT LED WILL TURN ON.

 

 

 

#ifndef F_CPU
#define F_CPU 1000000UL                    // set the CPU clock
#endif

#include <avr/io.h>
#include <string.h>
#include <util/delay.h>

//Functions initialization
char *compare();
void send();

// Global Variable Initialization
char *data1,str1[100],str2[100],y[10],*data2,index;
int s,e;

void uart_init(){
    UBRR0H=0x00;
    UBRR0L=    12;    
    UCSR0A=(0<<RXC0) | (0<<TXC0) | (0<<UDRE0) | (0<<FE0) | (0<<DOR0) | (1<<U2X0) | (0<<MPCM0);
    UCSR0B=(0<<RXCIE0) | (0<<TXCIE0) | (0<<UDRIE0) | (1<<RXEN0) | (1<<TXEN0) | (0<<UCSZ02) | (0<<RXB80) | (0<<TXB80);
    UCSR0C=(0<<UMSEL00) | (0<<UPM01) | (0<<UPM00) | (0<<USBS0) | (1<<UCSZ01) | (1<<UCSZ00) | (0<<UCPOL0);
}

void uart_transmit (char data){
    while (!( UCSR0A & (1<<UDRE0))); // wait while register is free
    UDR0 = data; // load data in the register    
}

void string_transmit(const char *str){
    unsigned char s=0;
    while (str[s]!=0){
        uart_transmit (str[s]);
        s++;
    }
}

unsigned char uart_receive (){
        
    while((UCSR0A&(1<<RXC0)) == 0); // Return received data
        return UDR0;
}

    
char * string_receive1(){
        
    unsigned char  x,i = 0; //receive the characters until "," character comes
    while((x = uart_receive())!=','){
            str2[i++] = x; //and store the received characters into the array string[] one-by-one
    }
    str2[i] = '\0';    //insert NULL to terminate the string
        return str2;
}

char * string_receive2()
{
    unsigned char  x,i = 0;
    //receive the characters until "K" character comes
    while((x = uart_receive())!='K')
    {
        str2[i++] = x; //and store the received characters into the array string[] one-by-one
    }
    
    str2[i] = '\0'; //insert NULL to terminate the string
    return str2;//return the received string
}

void gsm_init()
{
    string_transmit("\r\nAT\r\n");
    _delay_ms(500);
    string_transmit("ATE1\r\n");
    _delay_ms(500);
    string_transmit("AT+CMGF=1\r\n");
    _delay_ms(500);
    string_transmit("AT+CMGD=1,4\r\n");
    _delay_ms(500);
    string_transmit("AT+CNMI=1,1,0,1\r\n");
    
}

char *compare(){
    int i = 0;
    // s = start of new string
    // e = end of new string
    while(s<e ){
        y[i++] = data1[s++]; //and store the received characters into the array string[] one-by-one
    }
    y[i] = '\0'; //insert NULL to terminate the string
            
    return(y); //return the received string
}

//Main function

int main()
{
    DDRC=0xff; 
    uart_init(); 
    gsm_init(); 

    while(1){

     PORTC ^= (1 << 0);

    _delay_ms(300);
    data1=string_receive1();
    index=uart_receive();

    _delay_ms(300);
    s=5;e=9;
    data2=compare();
    if(strncmp(data2,"+CMTI",4)==0){ PORTC ^= (1 << 1); }

    string_transmit("AT+CMGR=");
    uart_transmit(index);
    string_transmit("\r\n");
    
    data1=string_receive2();
    
    _delay_ms(300);
    
    s=78;e=86;

    data2=compare();

    

    _delay_ms(300);

    if(strncmp(data2,"Yellow",6)==0)

    {if ((PORTC & (1 << 4) ) == 0){
        
        PORTC |= 1 << 4;
        
    }
    else{
        
        PORTC &= ~(1 << 4);
     }}
    if(strncmp(data2,"Green",5)==0){
        
        if ((PORTC & (1 << 2))==0){
            
            PORTC |= 1 << 2;
    
        }
        
        else{
            
            PORTC &= ~(1 << 2);
        }
    }

        _delay_ms(2700);
        string_transmit("AT+CMGD=1,4\r\n");
    }
    return 0;
 }
 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks for the contribution but the OP was 8 years ago.wink

John Samperi

Ampertronics Pty. Ltd.

https://www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Continuing the necromancy theme ...

 

 

Do not do this:

avrfreaken wrote:

    string_transmit("\r\nAT\r\n");
    _delay_ms(500);
    string_transmit("ATE1\r\n");
    _delay_ms(500);
    string_transmit("AT+CMGF=1\r\n");
    _delay_ms(500);
    string_transmit("AT+CMGD=1,4\r\n");
    _delay_ms(500);
    string_transmit("AT+CNMI=1,1,0,1\r\n");

All AT commands give a response - "OK" or an Error - to indicate when the unit has finished handling one command, and is ready for the next.

 

You need to pay attention to these responses; not just blindly ignore them with delays, as above - any such code is going to come unstuck sooner or later when a command takes even a little longer than expected, or fails completely.

 

See: 

 

https://www.avrfreaks.net/commen...

 

https://www.avrfreaks.net/commen...

 

https://www.avrfreaks.net/commen...

 

https://www.avrfreaks.net/commen...

 

https://www.avrfreaks.net/commen...

 

etc, etc, ...

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...