PDA

View Full Version : gsm modem and stk500



agnostos
05-18-2008, 06:09 AM
hello i am a student and i have to make a project until this Monday and i have a big problem
i can send at commands to gsm modem but i can't get the answers and i don't know why. (gsm modem is siemens mc35 and micro is stk500 8515)
the 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.
http://www.hpinfotech.com

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 GetData(void)
{
int i;
PORTB.1 = 1;
delay_ms(100);
PORTB.1 = 0;
for (i = 0;i<10;i++)
{
PORTB.1 = 1;
myData[i] = getchar();
// delay_ms(100);
PORTB.1 = 0;
// if (myData[i]=='\0')
// break;
}
}
void SendSms(void)
{
printf("at+cmgs=6938699188");
putchar( CR ); //CR
putchar( LF ); //LF
delay_ms(100);
printf("%s","TEST");
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;
//printf("ATE0\r\n");
while(1)
{
printf("AT \r\n");

PORTB.0 = 1;
scanf("%s", myData);
//GetData();
printf("at+cmgs=6938699188\r\n");

printf("%s",myData);
putchar(CTRLZ);
delay_ms(1000);
// if (myData[0] == 'O')
PORTB.0 = 0;
break;
}
}


when i use the scanf command i get the same information that i send (the AT command) if use the GetData() the program crash out. why??? what must i change to read a message from gsm???
(the connection between gsm and stk is why null modem cable (2 females) and i connect the 2,3,5 pins from cable to 3,2,5 on avr the same connection is on modem)

please help me because time pressure me and i don't know what to do...

i hope to your answer...

debu
05-18-2008, 07:59 AM
...and i connect the 2,3,5 pins from cable to 3,2,5 on avr ...
8O
No MAX232? Just directly??
Check your clock source, 99% of all UART problems are due to the clock.

Regards,

Debu :)

Edit: Ok.. I just understood what you ment with the 3,2,5 and 2,3,5. You are talking about the DB9 RS232 port, right?

agnostos
05-18-2008, 11:27 AM
yes directly and the 3,2,5 is for the db9 cable... how can i check the clock to ensure that everything is ok? i don't use external clock :(

debu
05-18-2008, 12:58 PM
...i don't use external clock...

Are you using the internal RC Oscillator? If so, what settings? Your code runs at 4MHz, is the clock that you are using running at 4MHz?

Is the device that you are using configured to run at 115200 baud?

Regards,

Debu :)

agnostos
05-18-2008, 04:42 PM
yes and my device is configured for 115200 baud. but nothing...

wizardjack
05-18-2008, 05:08 PM
How do you know that your modem is receiving commands ?
Are you sure you don't have to turn-on echo through a AT command ?

cheers !!!
wizardjack