EngineersGarage

  • Engineers Garage Main Site
  • Visit our active EE Forums
    • EDABoard.com
    • Electro-Tech-Online
  • Projects & Tutorials
    • Circuits
    • Electronic Projects
    • Tutorials
    • Components
  • Digi-Key Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • Advertise
You are here: Home / Topics / ATMEGA16A : Unable to receive OK response from SIM900 gsm module

ATMEGA16A : Unable to receive OK response from SIM900 gsm module

|

Microcontroller › AVR › ATMEGA16A : Unable to receive OK response from SIM900 gsm module

  • This topic has 0 replies, 1 voice, and was last updated 11 years, 9 months ago by Narendra Saini.
Viewing 1 post (of 1 total)
  • Author
    Posts
  • April 13, 2014 at 9:58 am #3040
    Narendra Saini
    Participant

    I have been trying to interface Atmega16 and GSM Modem Sim900 through USART to send and receive sms. I am able to send SMS from Atmega16 using Sim900. 

    But I am not able to receive the ‘received SMS’s from sim900. I have tried it through (a) polling the RXC flag and (b) RXC interrupt. But none of the approaches is working. 

    So, to see if anything is being received by the RX pin (of Atmega16) at all, I have written a code to check if an OK response is being received after initialising the GSM modem by sending “AT” from Atmega16. I have used LEDs to know if OK response is received or not.

    When executed, LEDs indicate that OK response is not being received by Atmega16. But when the GSM modem is connected to Hyperterminal using serial port and the Atmega16 is disconnected, I am getting OK response when “AT” is sent in Hyperterminal.

    Please provide any suggestion and solution to this problem.

    Thank you.

     

    Code :

     

    #define RECEIVE_BUFF_SIZE 64

    volatile uint8_t UQFront;
    volatile int8_t UQEnd;
    volatile char URBuff[RECEIVE_BUFF_SIZE];

    int main(void)
    {
           char *response;
    USARTInit(5); // Baud rate = 9600

    DDRB=0xFF; 

            // Initialize GSM Modem




            UWriteString(“ATr”);
    _delay_ms(1500);
    UWriteString(“ATE0r”);
    _delay_ms(1500);
    UWriteString(“AT+CMGF=1r”);
    _delay_ms(1500);

    //




    UQFront=UQEnd=-1;

    UWriteString(“ATr”); // Sending AT again to check if OK response is received

    _delay_ms(7000);

    UReadBuffer(response,6);

    SIM300CheckResponse(response,”OK”,6);
    }

    void USARTInit(uint16_t ubrrvalue)
    {
    //Setup queque
    UQFront=UQEnd=-1;

    //Set Baud rate
    UBRRH=(unsigned char)(ubrrvalue>>8);
    UBRRL=(unsigned char)ubrrvalue;

    /*Set Frame Format

    Asynchronous mode
    No Parity
    1 StopBit
    char size 8

    */

    UCSRC=(1<<URSEL)|(3<<UCSZ0);
    UCSRB=(1<<RXCIE)|(1<<RXEN)|(1<<TXEN);
    sei();

    }

    //The USART ISR
    ISR(USART_RXC_vect)
    {
    //Read the data
    char data=UDR;

    //Now add it to queque

    if(((UQEnd==RECEIVE_BUFF_SIZE-1) && UQFront==0) || ((UQEnd+1)==UQFront))
    {
    //Q Full
    UQFront++;
    if(UQFront==RECEIVE_BUFF_SIZE) UQFront=0;
    }


    if(UQEnd==RECEIVE_BUFF_SIZE-1)
    UQEnd=0;
    else
    UQEnd++;


    URBuff[UQEnd]=data;

    if(UQFront==-1) UQFront=0;

    }

    char UReadData()
    {
    char data;

    //Check if queque is empty
    if(UQFront==-1)
    return 0;

    data=URBuff[UQFront];

    if(UQFront==UQEnd)
    {
    //If single data is left
    //So empty queque
    UQFront=UQEnd=-1;
    }
    else
    {
    UQFront++;

    if(UQFront==RECEIVE_BUFF_SIZE)
    UQFront=0;
    }

    return data;
    }

    void UWriteData(char data)
    {
    //Wait For Transmitter to become ready
    while(!(UCSRA & (1<<UDRE)));

    //Now write
    UDR=data;
    }

    void UWriteString(char *str)
    {
    while((*str)!=’’)
    {
    UWriteData(*str);
    str++;
    }
    }
    void sendMsg(char *num, char *msg)
    {
    char cmd[25];
    sprintf(cmd,”AT+CMGS=”%s”r”,num);
    UWriteString(cmd);
    _delay_ms(1000);
    UWriteString(msg);
    _delay_ms(500);
    UWriteData(0x1A);
    }

    void UReadBuffer(void *buff,uint16_t len)
    {
    uint16_t i;
    for(i=0;i<len;i++)
    {
    ((char*)buff)=UReadData();
    }
    }
    void SIM300CheckResponse(const char *response,const char *check,uint8_t len)
    {
    len-=2;
    int a;

    //Check leading CR LF
    if(response[0]!=0x0D || response[1]!=0x0A)
    PORTB=0xF0; // LED indication

    //Check trailing CR LF
    else if(response[len]!=0x0D || response[len+1]!=0x0A)
    PORTB=0x0F; // LED indication

    else {
    //Compare the response
    a=1;
    for(uint8_t i=2;i<len;i++)
    {
    if(response!=check[i-2])
    a=0;
    }

    if(a)
    {
    PORTB=0xFF; // LED indication for “OK” received
    sendMsg(“09xxxxxxxxx”, response); // Send the response as SMS
    }
    else
    PORTB=0x00; // LED indication

    }

    }

     

  • Author
    Posts
Viewing 1 post (of 1 total)
  • You must be logged in to reply to this topic.
Log In

RSS Recent Posts

  • Variable audio oscillator January 17, 2026
  • Sine wave distortion January 17, 2026
  • My Advanced Realistic Humanoid Robots Project January 17, 2026
  • Micro mouse January 17, 2026
  • flexible copper cable January 16, 2026

Stay Up To Date

Newsletter Signup
EngineersGarage

Copyright © 2026 WTWH Media LLC. All Rights Reserved. The material on this site may not be reproduced, distributed, transmitted, cached or otherwise used, except with the prior written permission of WTWH Media
Privacy Policy | Advertising | About Us

Search Engineers Garage

  • Engineers Garage Main Site
  • Visit our active EE Forums
    • EDABoard.com
    • Electro-Tech-Online
  • Projects & Tutorials
    • Circuits
    • Electronic Projects
    • Tutorials
    • Components
  • Digi-Key Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • Advertise