gsm modem and stk500

Discussion in 'Embedded Systems and Microcontrollers' started by agnostos, May 17, 2008.

  1. agnostos

    Thread Starter New Member

    May 17, 2008
    2
    0
    hello 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.
    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 = getchar();
    // delay_ms(100);
    PORTB.1 = 0;
    // if (myData=='\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...
     
  2. hgmjr

    Moderator

    Jan 28, 2005
    9,030
    214
    Code ( (Unknown Language)):
    1.  
    2. /*****************************************************
    3. This program was produced by the
    4. CodeWizardAVR V1.25.9 Professional
    5. Automatic Program Generator
    6. © Copyright 1998-2008 Pavel Haiduc, HP InfoTech s.r.l.
    7. [URL="http://www.hpinfotech.com/"]http://www.hpinfotech.com[/URL]
    8.  
    9. Project :
    10. Version :
    11. Date : 16/5/2008
    12. Author : ditoskas
    13. Company : ditoskas
    14. Comments:
    15.  
    16.  
    17. Chip type : ATmega8515L
    18. Program type : Application
    19. Clock frequency : 4,000000 MHz
    20. Memory model : Small
    21. External SRAM size : 0
    22. Data Stack size : 128
    23. *****************************************************/
    24.  
    25. #include <mega8515.h>
    26.  
    27. //TA CR KAI LF XRISIMOPOIOUNTAI GIA TIN APOSTOLI TOY ENTER.
    28. #define CR 0x0D
    29. #define LF 0x0A
    30.  
    31. //DEKAEKSADIKI TIMI TOY CTRL-Z EINAI I 0x1A.
    32. #define CTRLZ 0x1A
    33. #include <delay.h>
    34. // Standard Input/Output functions
    35. #include <stdio.h>
    36. // Declare your global variables here
    37. //char msg[127];
    38. char myData[127];
    39. void GetData(void)
    40. {
    41.    int i;
    42.    PORTB.1 = 1;
    43.    delay_ms(100);
    44.    PORTB.1 = 0;
    45.    for (i = 0;i<10;i++)
    46.    {
    47.       PORTB.1 = 1;
    48.       myData[i] = getchar();
    49.       // delay_ms(100);
    50.       PORTB.1 = 0;
    51.       // if (myData[i]=='\0')
    52.       // break;
    53.    }
    54. }
    55.  
    56.  
    57. void SendSms(void)
    58. {
    59.    printf("at+cmgs=6938699188");  
    60.    putchar( CR ); //CR
    61.    putchar( LF ); //LF  
    62.    delay_ms(100);
    63.    printf("%s","TEST");
    64.    putchar(CTRLZ);
    65.    // putchar( LF ); //LF
    66.    };
    67.  
    68. void main(void)
    69. {
    70.    // Declare your local variables here
    71.  
    72.    // Input/Output Ports initialization  
    73.    // Port A initialization
    74.    // Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In
    75.    // State7=T State6=T State5=T State4=T State3=T State2=T   State1=T State0=T
    76.    PORTA=0x00;
    77.    DDRA=0x00;
    78.  
    79.    // Port B initialization
    80.    // Func7=Out Func6=Out Func5=Out Func4=Out Func3=Out Func2=Out Func1=Out Func0=Out
    81.    // State7=0 State6=0 State5=0 State4=0 State3=0 State2=0 State1=0 State0=0
    82.    PORTB=0x00;
    83.    DDRB=0xFF;
    84.  
    85.    // Port C initialization
    86.    // Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=Out Func0=In
    87.    // State7=T State6=T State5=T State4=T State3=T State2=T State1=1 State0=T
    88.    PORTC=0x02;
    89.    DDRC=0x02;
    90.  
    91.    // Port D initialization
    92.    // Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In
    93.    // State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T
    94.    PORTD=0x00;
    95.    DDRD=0x00;
    96.  
    97.    // Port E initialization
    98.    // Func2=In Func1=In Func0=In
    99.    // State2=T State1=T State0=T
    100.    PORTE=0x00;
    101.    DDRE=0x00;
    102.  
    103.    // Timer/Counter 0 initialization
    104.    // Clock source: System Clock
    105.    // Clock value: Timer 0 Stopped
    106.    // Mode: Normal top=FFh
    107.    // OC0 output: Disconnected
    108.    TCCR0=0x00;
    109.    TCNT0=0x00;
    110.    OCR0=0x00;
    111.  
    112.    // Timer/Counter 1 initialization
    113.    // Clock source: System Clock
    114.    // Clock value: Timer 1 Stopped
    115.    // Mode: Normal top=FFFFh
    116.    // OC1A output: Discon.
    117.    // OC1B output: Discon.
    118.    // Noise Canceler: Off
    119.    // Input Capture on Falling Edge
    120.    // Timer 1 Overflow Interrupt: Off
    121.    // Input Capture Interrupt: Off
    122.    // Compare A Match Interrupt: Off
    123.    // Compare B Match Interrupt: Off
    124.    TCCR1A=0x00;
    125.    TCCR1B=0x00;
    126.    TCNT1H=0x00;
    127.    TCNT1L=0x00;
    128.    ICR1H=0x00;
    129.    ICR1L=0x00;
    130.    OCR1AH=0x00;
    131.    OCR1AL=0x00;
    132.    OCR1BH=0x00;
    133.    OCR1BL=0x00;
    134.  
    135.    // External Interrupt(s) initialization
    136.    // INT0: Off
    137.    // INT1: Off
    138.    // INT2: Off
    139.    MCUCR=0x00;
    140.    EMCUCR=0x00;
    141.  
    142.    // Timer(s)/Counter(s) Interrupt(s) initialization
    143.    TIMSK=0x00;
    144.  
    145.    // USART initialization
    146.    // Communication Parameters: 8 Data, 1 Stop, No Parity
    147.    // USART Receiver: On
    148.    // USART Transmitter: On
    149.    // USART Mode: Asynchronous
    150.    // USART Baud Rate: 115200
    151.    UCSRA=0x00;
    152.    UCSRB=0x18;
    153.    UCSRC=0x86;
    154.    UBRRH=0x00;
    155.    UBRRL=4000000/16/115200-1;
    156.  
    157.    // Analog Comparator initialization
    158.    // Analog Comparator: Off
    159.    // Analog Comparator Input Capture by Timer/Counter 1: Off
    160.    ACSR=0x80;
    161.    PORTB.0 = 0;
    162.    PORTB.1 = 0;
    163.    //printf("ATE0\r\n");
    164.    while(1)
    165.    {
    166.       printf("AT \r\n");
    167.  
    168.       PORTB.0 = 1;
    169.       scanf("%s", myData);
    170.       //GetData();
    171.       printf("at+cmgs=6938699188\r\n");
    172.  
    173.       printf("%s",myData);
    174.       putchar(CTRLZ);
    175.       delay_ms(1000);
    176.       // if (myData[0] == 'O')
    177.       PORTB.0 = 0;
    178.       break;
    179.    }
    180. }
    181.  
    182. [/i][/i]



    Code formatting to enhance readability.

    hgmjr
     
  3. agnostos

    Thread Starter New Member

    May 17, 2008
    2
    0
    i am sorry but i don't understand what you mean where is the error????
     
Loading...