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.

Problem with reading the return value of AT command

Status
Not open for further replies.

agnostos

Newbie level 4
Joined
May 14, 2008
Messages
5
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,318
read from gsm modem

hello i have a problem with avr and gsm modem.
i can send AT commands to gsm modem but i can't get the returns. how can i read the return value of AT command???
i have the avr stk500 and i send the at command with printf("AT");

i try to read with this way
char myData[50];
scanf("%s",myData);
but nothing happened why???

my code is
Code:
/*****************************************************
This program was produced by the
CodeWizardAVR V1.25.9 Professional
Automatic Program Generator
© Copyright 1998-2008 Pavel Haiduc, HP InfoTech s.r.l.
[url]http://www.hpinfotech.com[/url]

Project : 
Version : 
Date    : 16/5/2008
Author  : ditoskas                        
Company : ditoskas                        
Comments: 


Chip type           : ATmega8515L
Program type        : Application
Clock frequency     : 4,000000 MHz
Memory model        : Small
External SRAM size  : 0
Data Stack size     : 128
*****************************************************/

#include <mega8515.h>

//TA CR KAI LF XRISIMOPOIOUNTAI GIA TIN APOSTOLI TOY ENTER.
#define CR 0x0D 
#define LF 0x0A

//DEKAEKSADIKI TIMI TOY CTRL-Z EINAI I 0x1A.
#define CTRLZ 0x1A 
#include <delay.h>
// Standard Input/Output functions
#include <stdio.h>
// Declare your global variables here
//char msg[127];                 
 char myData[127]; 
void SendSms(void)
{                     
        printf("at+cmgs=6938699188");  
        putchar( CR ); //CR
        putchar( LF ); //LF  
        delay_ms(100);         
        printf("%s",myData);
        putchar(CTRLZ);   
      //  putchar( LF ); //LF  
};

void main(void)
{
// Declare your local variables here
  
// Input/Output Ports initialization
// Port A initialization
// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In 
// State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T 
PORTA=0x00;
DDRA=0x00;

// Port B initialization
// Func7=Out Func6=Out Func5=Out Func4=Out Func3=Out Func2=Out Func1=Out Func0=Out 
// State7=0 State6=0 State5=0 State4=0 State3=0 State2=0 State1=0 State0=0 
PORTB=0x00;
DDRB=0xFF;

// Port C initialization
// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=Out Func0=In 
// State7=T State6=T State5=T State4=T State3=T State2=T State1=1 State0=T 
PORTC=0x02;
DDRC=0x02;

// Port D initialization
// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In 
// State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T 
PORTD=0x00;
DDRD=0x00;

// Port E initialization
// Func2=In Func1=In Func0=In 
// State2=T State1=T State0=T 
PORTE=0x00;
DDRE=0x00;

// Timer/Counter 0 initialization
// Clock source: System Clock
// Clock value: Timer 0 Stopped
// Mode: Normal top=FFh
// OC0 output: Disconnected
TCCR0=0x00;
TCNT0=0x00;
OCR0=0x00;

// Timer/Counter 1 initialization
// Clock source: System Clock
// Clock value: Timer 1 Stopped
// Mode: Normal top=FFFFh
// OC1A output: Discon.
// OC1B output: Discon.
// Noise Canceler: Off
// Input Capture on Falling Edge
// Timer 1 Overflow Interrupt: Off
// Input Capture Interrupt: Off
// Compare A Match Interrupt: Off
// Compare B Match Interrupt: Off
TCCR1A=0x00;
TCCR1B=0x00;
TCNT1H=0x00;
TCNT1L=0x00;
ICR1H=0x00;
ICR1L=0x00;
OCR1AH=0x00;
OCR1AL=0x00;
OCR1BH=0x00;
OCR1BL=0x00;

// External Interrupt(s) initialization
// INT0: Off
// INT1: Off
// INT2: Off
MCUCR=0x00;
EMCUCR=0x00;

// Timer(s)/Counter(s) Interrupt(s) initialization
TIMSK=0x00;

// USART initialization
// Communication Parameters: 8 Data, 1 Stop, No Parity
// USART Receiver: On
// USART Transmitter: On
// USART Mode: Asynchronous
// USART Baud Rate: 115200
UCSRA=0x00;
UCSRB=0x18;
UCSRC=0x86;
UBRRH=0x00;
UBRRL=4000000/16/115200-1;

// Analog Comparator initialization
// Analog Comparator: Off
// Analog Comparator Input Capture by Timer/Counter 1: Off
ACSR=0x80;
PORTB.0 = 0;
PORTB.1 = 0;
while (1)
      {    
        printf("%s","AT+CMGR=1");   
        putchar( CR ); //CR
        putchar( LF ); //LF     
        PORTB.0 = 1;
        delay_ms(100);
        PORTB.0 = 0;         
        scanf("%s",myData);
      // Place your code here   
        delay_ms(1000);
        PORTB.0 = 1;       
        SendSms();
        delay_ms(2000);
        PORTB.0 = 0;
        break;
      };
}
 

Re: read from gsm modem

you can use an uart interrupt. Use a getchar() function if you receive to your serial port the character e.g "A" and the second character is e.g. "T" then move each received character into an array as element.
 

Re: read from gsm modem

i try to use interrupts but nothing new happened. i execute a AT command and read the interrupt buffer to my variable. after that i disable interrupts and send it to my mobile. The problem is that i don't get the answer of gsm modem. i get only the letter a or @
 

Re: read from gsm modem

Did you confirm if GSM is responding to the input properly in hytperterminal first. If it is doing then it solves half of the problem. It would be easy to debug.

Please try communicating with hyperterminal to check if GSM is working properly.
 

Re: read from gsm modem

I often use serial port watcher to check what's happening.
 

Re: read from gsm modem

could you confirm if the modem responds as "AT OK" if you send "AT".
ATE0 response OK. in any of the software you use, with hyperterminal or the software you use. I dont want the application to send the command, just type the command from the terminal you should get the reaponse. Please try and let me know.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top