1. Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.
    Dismiss Notice

Problem receiving SMS from GSM using LPC2148[HELP]

Discussion in 'ARM' started by Twisted_transistor, Apr 21, 2013.

  1. Twisted_transistor

    Twisted_transistor New Member

    Joined:
    Jul 22, 2012
    Messages:
    23
    Likes:
    0
    Hi, I've connected my SIM300 to LPC2148 via RX, TX & GND lines and successfully transmitted SMSs. Now I've written a code to do the following:
    -Initialise the GSM module and wait for an SMS to arrive at the SIM
    -Wen an SMS is received, the LPC2148 receives an indication in the form of a +CMTI string
    -We extract the location of the SMS on the SIM and read the SMS
    -This same SMS is den sent to another number indicated by ########## in the code

    But on burning the code it was found that blank messages are being sent to the number ########## instead of the actual received SMS.

    Can someone please tell me whats wrong in my code:

    Code (text):
    #include<lpc214x.h>
    extern unsigned char cmgf[]="AT+CMGF=1";                            //Text format in GSM modem
    extern unsigned char cmgsh[]="AT+CMGS=\"+############\"";           //Mobile number to which the msg is sent

    unsigned char cmgr[]="AT+CMGR=";
    unsigned char newmsg=0x00;
    unsigned char msgid;

    void txu1(unsigned char data)                 //Transmit a byte of data through UART1
    {
    while(!(U1LSR & 0x20));
      U1THR=data;
     }

    unsigned char rxu1()
    {
    unsigned char p;
    while ((U1LSR&0x01)!=1);
    p=U1RBR;
    return p;
    }

    void sendstring(unsigned char *p)           //Sends a string of data through UART1
    {
    while(1)
    {
    if(*p=='\0') break;
    txu1(*p++);
    }
    }
    void delay()                              //delay function
    {
    int i,j;
    for(i=0;i<60000;i++)
    for(j=0;j<200;j++);
    }


    void readmsg()
    {
    int i;
    unsigned char p[21];
    sendstring(cmgr);
    txu1(msgid);
    txu1(0x0D);
    txu1(0x0A);
    for(i=0;i<6;i++)
    p[i]=rxu1();
    p[6]='\0';

    IO1SET=0x00070000;
    sendstring(cmgf);
    txu1(0x0D);                                     // equivalent of
    txu1(0x0A);                                     //   enter key
    delay();
    sendstring(cmgsh);
    txu1(0x0D);
    txu1(0x0A);
    delay();
    sendstring(p);
    txu1(0x1A);
    delay();
    txu1(0x1A);
    IO1CLR=0x00070000;
    }



    void uart1_irq() __irq
    {                     //ISR if anything is recieved in UART1
    unsigned char p[12];
    unsigned char q;
    int i;
    q=U1RBR;
    if(q=='+')
    {
    for(i=0;i<11;i++)
    {
    p[i]=U1RBR;
    }
    msgid=p[10];
    p[11]='\0';

    IO1SET=0x00020000;
    newmsg=0x01;
    }

    VICVectAddr=0;
    }

    void init()                 //Initialization of UART0,UART1 and ISR
    {
    U1LCR=0x83;
    U1DLL=0x62;
    U1DLM=0x00;
    U1LCR=0x03;
    U1IER=0x01;
    U1FCR=0X07;
    VICIntSelect&=0xffffff7f;
    VICVectAddr2=(unsigned int)uart1_irq;
    VICIntEnable|=0x00000080;
    VICVectCntl2=0x20|7;
    }


    int main()
    {
    VICIntEnClr=0x00000080;
    PINSEL0=0x00050005;
    PINSEL1=0x00000000;
    PINSEL2=0x00000000;
    init();

    IO1DIR=0xFFFF0000;

    sendstring("ATe0\r\n");
    delay();

    sendstring("AT+CNMI=3,1,0,0,0\r\n");
    delay();

    IO1SET=0x00010000;
    U1IER=0x01;
    while(newmsg==0x00);
    newmsg=0x00;
    readmsg();
    }

    Any help will be greatly appreciated.

    Muito obrigada:)
     
  2. AtomSoft

    AtomSoft Well-Known Member

    Joined:
    Feb 7, 2008
    Messages:
    5,670
    Likes:
    41
    Location:
    Brooklyn, NY US
    While ive never tried any SMS stuff, ill look over this code and see if anything pops out to me
     
  3. AtomSoft

    AtomSoft Well-Known Member

    Joined:
    Feb 7, 2008
    Messages:
    5,670
    Likes:
    41
    Location:
    Brooklyn, NY US
    Ok from what i can see.. the UART IRQ is reading 12bytes of data only.. also loops in the IRQ isnt cool i think...

    can you set a breakpoint at "delay();"
    about here:

    delay();//DEBUG HERE
    sendstring(p);

    and see whats in "p"
     
  4. dave

    Dave New Member

    Joined:
    Jan 12, 1997
    Messages:
    -
    Likes:
    0


     
  5. Twisted_transistor

    Twisted_transistor New Member

    Joined:
    Jul 22, 2012
    Messages:
    23
    Likes:
    0

    Yup.. k.. I've modified the code..
    Now, the programmed number ########## receives p correctly. i.e it receives the string:- CMTI: "SM",2
    Where "2" is the location in the SIM memory where the received SMS is stored. But the problem now is that I still cannot read the received SMS.

    The corrected code is as follows:

    Code (text):
    #include<lpc214x.h>
    extern unsigned char cmgf[]="AT+CMGF=1";                            //Text format in GSM modem
    extern unsigned char cmgsh[]="AT+CMGS=\"+############\"";           //Mobile number to which the msg is sent

    unsigned char cmgr[]="AT+CMGR=";
    unsigned char newmsg=0x00;
    unsigned char msgid;

    void txu1(unsigned char data)                 //Transmit a byte of data through UART1
    {
    while(!(U1LSR & 0x20));
      U1THR=data;
     
    }

    unsigned char rxu1()
    {
    unsigned char p;
    while ((U1LSR&0x01)!=1);
    p=U1RBR;
    return p;
    }

    void sendstring(unsigned char *p)            //Sends a string of data through UART1
    {
    while(1)
    {
    if(*p=='\0') break;
    txu1(*p++);
    }
    }


    void delay()                              //delay function
    {
    int i,j;
    for(i=0;i<60000;i++)
    for(j=0;j<200;j++);
    }


    void readmsg()
    {
    int i;
    unsigned char p[60];
    unsigned char q[7];
    sendstring(cmgf);
    txu1(0x0D);                                     // equivalent of
    txu1(0x0A);                                     //   enter key
    delay();
    sendstring(cmgr);
    txu1(msgid);
    txu1(0x0D);
    txu1(0x0A);
    for(i=0;i<58;i++)
    p[i]=U1RBR;

    for(i=0;i<6;i++)
    q[i]=U1RBR;
    q[6]='\0';

    IO1SET=0x00070000;
    sendstring(cmgf);
    txu1(0x0D);                                     // equivalent of
    txu1(0x0A);                                     //   enter key
    delay();
    sendstring(cmgsh);
    txu1(0x0D);
    txu1(0x0A);
    delay();
    sendstring(q);
    txu1(0x1A);
    delay();
    txu1(0x1A);
    IO1CLR=0x00070000;
    }



    void uart1_irq() __irq
    {                     //ISR if anything is recieved in UART1
    unsigned char p[13];
    unsigned char q;
    int i;

    q=U1RBR;
    if(q=='+')
    {
    for(i=0;i<12;i++)
    {
    p[i]=rxu1();
    }
    msgid=p[11];
    p[12]='\0';

    sendstring(cmgf);
    txu1(0x0D);                                     // equivalent of
    txu1(0x0A);                                     //   enter key
    delay();
    sendstring(cmgsh);
    txu1(0x0D);
    txu1(0x0A);
    delay();
    sendstring(p);
    txu1(0x1A);
    delay();
    txu1(0x1A);

    IO1SET=0x00020000;
    newmsg=0x01;
    }
    VICVectAddr=0;
    }

    void init()                              //Initialization of UART0,UART1 and ISR
    {
    U1LCR=0x83;
    U1DLL=0x62;
    U1DLM=0x00;
    U1LCR=0x03;
    U1IER=0x01;
    U1FCR=0X07;
    VICIntSelect&=0xffffff7f;
    VICVectAddr2=(unsigned int)uart1_irq;
    VICIntEnable|=0x00000080;
    VICVectCntl2=0x20|7;
    }


    int main()
    {
    VICIntEnClr=0x00000080;
    PINSEL0=0x00050005;
    PINSEL1=0x00000000;
    PINSEL2=0x00000000;
    init();

    IO1DIR=0xFFFF0000;

    sendstring("ATe0\r\n");
    delay();

    sendstring("AT+CNMI=3,1,0,0,0\r\n");
    delay();

    IO1SET=0x00010000;
    U1IER=0x01;

    while(newmsg==0x00);
    newmsg=0x00;

    readmsg();
    }
    I'll remove the loop from the ISR later once my code starts working properly.

    Thanks alot Atom for helping. I do appreciate it:)
    Now only readind the SMS from the SIM is the problem..
     
  6. Twisted_transistor

    Twisted_transistor New Member

    Joined:
    Jul 22, 2012
    Messages:
    23
    Likes:
    0
    Heya Atom!! :)
    I've been able to sucessfully receive & read the SMS. But now when I re-enable the interrupt to receive new SMSes, the instant I reenable the interrupt using "VICIntEnable=0x80;" my code branches to the ISR and gets stuck there. Do you know why?

    The code is as follows:
    Code (text):
    #include<lpc214x.h>
    extern unsigned char cmgf[]="AT+CMGF=1";                            //Text format in GSM modem
    extern unsigned char cmgsh[]="AT+CMGS=\"+############\"";           //Mobile number to which the msg is sent
    unsigned char cmgr[]="AT+CMGR=";
    unsigned char newmsg=0x00;
    unsigned char msgid;

    void txu1(unsigned char data)                 //Transmit a byte of data through UART1
    {
    while(!(U1LSR & 0x20));
      U1THR=data;
    }

    unsigned char rxu1()
    {
    unsigned char p;
    while ((U1LSR&0x01)!=1);
    p=U1RBR;
    return p;
    }

    void sendstring(unsigned char *p)            //Sends a string of data through UART1
    {
    while(1)
    {
    if(*p=='\0') break;
    txu1(*p++);
    }
    }


    void delay()                              //delay function
    {
    int i,j;
    for(i=0;i<60000;i++)
    for(j=0;j<200;j++);
    }


    void readmsg()
    {
    int i,j;
    unsigned char p[500];
    unsigned char q[30];

    VICIntEnClr=0x80;
    sendstring(cmgf);
    txu1(0x0D);                                     // equivalent of
    txu1(0x0A);                                     //   enter key
    delay();
    sendstring(cmgr);
    txu1(msgid);
    txu1(0x0D);
    txu1(0x0A);
    for(i=0;i<130;i++)
    {
    p[i]=rxu1();
    if(p[i]=='%')
    {
    for(j=0;j<10;j++)
    q[j]=rxu1();
    q[10]='\0';
    IO1SET=0x00070000;
    break;
    }
    }

    sendstring(cmgf);
    txu1(0x0D);                                     // equivalent of
    txu1(0x0A);                                     //   enter key
    delay();
    sendstring(cmgsh);
    txu1(0x0D);
    txu1(0x0A);
    delay();
    sendstring(q);
    txu1(0x1A);
    delay();
    txu1(0x1A);
    IO1SET=0x00080000;
    }


    void uart1_irq() __irq
    {                     //ISR if anything is recieved in UART1
    unsigned char p[13];
    unsigned char q;
    int i;

    q=U1RBR;
    if(q=='+')
    {
    for(i=0;i<12;i++)
    {
    p[i]=rxu1();
    }
    msgid=p[11];
    p[12]='\0';

    sendstring(cmgf);
    txu1(0x0D);                                     // equivalent of
    txu1(0x0A);                                     //   enter key
    delay();
    sendstring(cmgsh);
    txu1(0x0D);
    txu1(0x0A);
    delay();
    sendstring(p);
    txu1(0x1A);
    delay();
    txu1(0x1A);
    IO1CLR=0x000F0000;
    IO1SET=0x00020000;
    newmsg=0x01;
    }

    VICVectAddr=0;
    }

    void init()                              //Initialization of UART0,UART1 and ISR
    {
    U1LCR=0x83;
    U1DLL=0x62;
    U1DLM=0x00;
    U1LCR=0x03;
    U1IER=0x01;
    U1FCR=0X07;
    VICIntSelect&=0xffffff7f;
    VICVectAddr2=(unsigned int)uart1_irq;
    VICIntEnable|=0x00000080;
    VICVectCntl2=0x20|7;
    }


    int main()
    {
    VICIntEnClr=0x00000080;
    PINSEL0=0x00050005;
    PINSEL1=0x00000000;
    PINSEL2=0x00000000;
    init();


    IO1DIR=0xFFFF0000;

    sendstring("ATe0\r\n");
    delay();


    sendstring("AT+CMGD=1,4\r\n");
    delay();

    sendstring("AT+CNMI=3,1,0,0,0\r\n");
    delay();

    IO1SET=0x00010000;
    U1IER=0x01;
    while(1)
    {
    IO1CLR=0x000F0000;
    while(newmsg==0x00);
    newmsg=0x00;
    readmsg();
    VICIntEnable=0x80;                                                    // here it branches to ISR
    }
    }
    Summary: The first SMS which is received it read correctly and transmitted. But wen I re-enable the interrupt to receive more SMSes, it branches to the ISR andhangs der.. I know it hangs der coz the LED connected to P1.17 lights..

    PLs help..
     
  7. AtomSoft

    AtomSoft Well-Known Member

    Joined:
    Feb 7, 2008
    Messages:
    5,670
    Likes:
    41
    Location:
    Brooklyn, NY US
    Have you tried clearing the IRQ flag after the interrupt? (well after newmsg=0x01; )

    Page 170 states:

     
    Last edited: Apr 26, 2013
  8. Twisted_transistor

    Twisted_transistor New Member

    Joined:
    Jul 22, 2012
    Messages:
    23
    Likes:
    0
    Heya Atom..
    I found the problem. Actually wen I send an SMS, the GSM module sends back a string of the following form: "+CMGS: 65".
    So the '+' sign was causing the interrupt. Therefore now I first read the buffer before exiting the readmsg() function as shown:

    Code (text):
    for(i=0;i<130;i++)
    {
    p[i]=rxu1();
    if(p[i]=='+')
    break;
    }
    Now my entire code is working fine!!:)
    Now all I have to do is integrate this code with my MEMS code & my project will be done!!
    Muito muito obrigada Atom:)
     
  9. Twisted_transistor

    Twisted_transistor New Member

    Joined:
    Jul 22, 2012
    Messages:
    23
    Likes:
    0
    Hi Atom!!
    I've integrated the GSM code with my MEMS code but for some reason when an accident occurs or an SMS is receivd, the respective ISRs are not entered.. I just cannot understand why this is happening.
    Pls check if I've initialised & handled the interrupts correctly...

    Btw the main aim of my project is Accident Detection.. But I also have additional features that depend on the command sent to the GSM module via SMS.

    Code (text):
    #include<lpc214x.h>
    extern int msgflag=0;
    unsigned char status;
    unsigned char flag;
    unsigned char data;
    extern unsigned char cmgf[]="AT+CMGF=1";
    unsigned char cmgr[]="AT+CMGR=";                            //Text format in GSM modem
    extern unsigned char cmgsh[]="AT+CMGS=\"+###########\"";            //Mobile number to which the msg is sent
    extern unsigned char msg[]="ACCIDENT!!!";                                  //secret code
    static unsigned char lat[10];
    static unsigned char lon[11];
    extern unsigned char cmgsp[]="AT+CMGS=\"+###########\"";
    unsigned char msgid;


    unsigned char recuart0()                // recieves a byte from U0
    {
    unsigned char p;
    while ((U0LSR&0x01)!=1);
    p=U0RBR;
    return p;
    }


    unsigned char rxu1()
    {
    unsigned char p;
    while ((U1LSR&0x01)!=1);
    p=U1RBR;
    return p;
    }

    void senduart1(unsigned char a)                 //sends a byte through U1
    {
    U1THR=a;
    while(U1LSR!=0x60);
    }


    void sendstring(unsigned char *p)            //Sends a string of data through UART1
    {
    while(1)
    {
    if(*p=='\0') break;
    senduart1(*p++);
    }
    }



    void  __irq IRQ_Eint3(void)     //EINT3 ISR
    {  
    msgflag=1;

    EXTINT = 0x08;             
    VICVectAddr = 0x00;    
    }  

    void delaygsm()                           //delay function
    {
    int i,c=0;
    for(i=0;i<40000;i++)
    {
    c++;
    }
    }


    void recgps()           // receives a byte from U0
    {
    unsigned char p;
    int gps=0;
    int i;

    while(gps==0)
    {
    p=recuart0();
    while(p!='$')
    {
    p=recuart0();
    }
    p=recuart0();
    if(p=='G')
    {
    }
    else
    continue;
    p=recuart0();
    if(p=='P')
    {
    }
    else
    continue;
       p=recuart0();
    if(p=='G')
    {
    }
    else
    continue ;
        p=recuart0();

    if(p=='G')
    {
    }
    else
    continue;
           p=recuart0();

    if(p=='A')
    {
    while(p!=',')
    {
       p=recuart0();
    }
       p=recuart0();
    while(p!=',')
    {
          p=recuart0();
    }
    for(i=0;i<9;i++)
    {
    lat[i]=recuart0();
    }
        p=recuart0();
    while(p!=',')
    {
        p=recuart0();
    }
        p=recuart0();
    while(p!=',')
    {
         p=recuart0();
    }
    for(i=0;i<10;i++)
    {
    lon[i]=recuart0();
    }
    lat[9]='\0';
    lon[10]='\0';
    gps=1;
    }
    else
    continue;
    }
    }


    void sendloc()
    {
    recgps();
    sendstring(cmgf);                                  
    delaygsm();
    sendstring(cmgsh);
    senduart1(0x0D);
    senduart1(0x0A);   
    delaygsm();
    sendstring("LAT: ");
    sendstring(lat);
    senduart1(0x0a);
    senduart1(0x0d);
    sendstring("LON: ");
    sendstring(lon);
    senduart1(0x1A);
    delaygsm();
    senduart1(0x1A);
    }


    void readmsg()
    {
    int i,j;
    unsigned char p[500];
    unsigned char q[30];
    VICIntEnClr|=0x80;
    sendstring(cmgf);                                  
    delaygsm();
    sendstring(cmgr);
    senduart1(msgid);
    senduart1(0x0D);
    senduart1(0x0A);
    for(i=0;i<130;i++)
    {
    p[i]=rxu1();
    if(p[i]=='%')
    {
    for(j=0;j<3;j++)
    q[j]=rxu1();
    q[3]='\0';
    break;
    }
    }

    if(q[0]=='1'){ sendloc();
                  IO1SET=0x00010000; }  // cut-off fuel supply
                   
    if(q[0]=='2'){    sendloc();
                      IO1SET=0x00020000; }  

    if(q[0]=='3'){ int i;
                      for(i=0;i<3;i++)
                      {
                        sendloc();
                        delaygsm();      //5 mins delay
                      }  
                               }

    for(i=0;i<130;i++)
    {
    p[i]=rxu1();
    if(p[i]=='+')
    break;
    }
    VICIntEnable|=0x80;
    }


    void uart1_irq() __irq
    {                     //ISR if anything is recieved in UART1
    unsigned char p[13];
    unsigned char q;
    int i;
    q=U1RBR;
    if(q=='+')
    {
    for(i=0;i<12;i++)
    {
    p[i]=rxu1();
    }
    msgid=p[11];
    }
    VICVectAddr=0;
    readmsg();
    }

    void intSetup()      //This function setups EINT3
    {
     
     EXTMODE = (1<<3);  // EINT3 is edge sensitive
     EXTPOLAR = (0<<3);                 // EINT3 in triggered on falling edge

     VICIntSelect = 0x00000000;     // Setting EINT3 as IRQ(Vectored)
     VICVectCntl0 = 0x20|17;        // Assigning Highest Priority Slot to EINT3 and enabling this slot
     VICVectAddr0 = (int)IRQ_Eint3; // Storing vector address of EINT3
     EXTINT = 0x08; //Clearing EINT3 flag  
     VICIntEnable = (1<<17);    // Enable EINT3
    }


    void start()
    {
    I2C0CONSET=0x20;
    }


    void stop()
    {
    I2C0CONSET=0x10;
    }


    unsigned char state(unsigned char number)
    {
    while(flag==0);
    flag=0;
    if(status!=number)
    { return 1; }
    else
    { return 0;}
    }



    void __irq intt(void)
    {
    flag=0xFF;          //update status flag
    status=I2C0STAT;                //Read Status byte
    I2C0CONCLR=0x28;
    VICVectAddr = 0x00;         //Acknowledge Interrupt
    }


    unsigned char read(unsigned char place1)
     {
     start();
     if(state(0x08))
     {
      return 1;
     }
     I2C0DAT=0x38;
     if(state(0x18))
     {
      return 1;
     }
    I2C0DAT=place1;
    if(state(0x28))
    {
     return 1;
     }
    start();
    if(state(0x10))
    {
    return 1;
    }
    I2C0DAT=0x39;
    if(state(0x40))
    {
    return 1;
    }
    I2C0CONCLR=0x04;
    if(state(0x58))
    {
    return 1;
    }
    data=I2C0DAT;
    stop();
     return 0;
     }


     
     unsigned char write(unsigned char place,unsigned char text)
     {
     start();
     if(state(0x08))
     {
      return 1;
     }
     I2C0DAT=0x38;
     if(state(0x18))
     {
     return 1;
     }
    I2C0DAT=place;
    if(state(0x28))
    {
     return 1;
     }
    I2C0DAT=text;
    if(state(0x28))
    {
     return 1;
     }
     stop();
     return 0;
     }



    void initi2c()
    {
    PINSEL0&=0xFFFFFF0F;
    PINSEL0|=0x00000050;

     I2C0CONCLR=0x6C;
     I2C0CONSET=0x40;
     I2C0SCLH=80;
     I2C0SCLL=70;
     VICIntSelect = 0x00000000;     // Setting all interrupts as IRQ(Vectored)
     VICVectCntl1 = 0x20 | 9;       // Assigning Highest Priority Slot to I2C0 and enabling this slot
     VICVectAddr1 = (unsigned long)intt; // Storing vector address of I2C0
     VICIntEnable = (1<<9);
     }


    void i2cperform()
    {
    PINSEL0|=0x00050005;
    PINSEL1|= 0x20000000;
    PINSEL2|=0x00000000;

    initi2c();
    write(0x2A,0x18);
    write(0x15,0x78);
    write(0x17,0x15);
    write(0x18,0x0A);
    write(0x2D,0x04);
    write(0x2E,0x04);
    data=read(0x2A);
    data|=0x01;
    write(0x2A,data);
    }

    void initgsm()                               //Initialization of UART0,UART1 and ISR
    {
    U0LCR=0x83;
    U0DLL=0x62;
    U0DLM=0x00;
    U0LCR=0x03;
    U1LCR=0x83;
    U1DLL=0x62;
    U1DLM=0x00;
    U1LCR=0x03;
    U1IER=0x01;
    U1FCR=0X07;
    VICIntSelect&=0xffffff7f;
    VICVectAddr2=(unsigned int)uart1_irq;
    VICIntEnable|=0x00000080;
    VICVectCntl2=0x20|7;
    }


    void gsmperform(void)
    {
    PINSEL0|=0x00050005;
    PINSEL1|=0x00000000;
    PINSEL2|=0x00000000;
    initgsm();
    sendstring("ATe0\r\n");
    delaygsm();
    sendstring("AT+CNMI=3,1,0,0,0\r\n");
    delaygsm();
    }





    void sendmsg(void)
    {
    recgps();
    sendstring(cmgf);
    senduart1(0x0D);                                        // equivalent of
    senduart1(0x0A);                                        //   enter key
    delaygsm();
    sendstring(cmgsh);
    senduart1(0x0D);
    senduart1(0x0A);   
    delaygsm();
    sendstring(msg);
    senduart1(0x0a);
    senduart1(0x0d);
    sendstring("LAT: ");
    sendstring(lat);
    senduart1(0x0a);
    senduart1(0x0d);
    sendstring("LON: ");
    sendstring(lon);
    senduart1(0x1A);
    delaygsm();
    senduart1(0x1A);

    sendstring(cmgf);
    senduart1(0x0D);                                        // equivalent of
    senduart1(0x0A);                                        //   enter key
    delaygsm();
    sendstring(cmgsp);
    senduart1(0x0D);
    senduart1(0x0A);   
    delaygsm();
    sendstring(msg);
    senduart1(0x0a);
    senduart1(0x0d);
    sendstring("LAT: ");
    sendstring(lat);
    senduart1(0x0a);
    senduart1(0x0d);
    sendstring("LON: ");
    sendstring(lon);
    senduart1(0x1A);
    delaygsm();
    senduart1(0x1A);
    }


    int main()
    {
    PINSEL0 = 0x00000000;       // Enable GPIO on all pins
    PINSEL1 = 0x00000000;
    PINSEL2 = 0x00000000;

    intSetup();
    i2cperform();
    gsmperform();

    while(1)
    {
    if(msgflag==1)
    {
    sendmsg();
    msgflag=0;
    IO1DIR=0xFFFF0000;
    IO1SET=0x000F0000;
    }
    }
    }
     
  10. Darshak

    Darshak New Member

    Joined:
    Dec 14, 2013
    Messages:
    1
    Likes:
    0
    Can any one halp me in code to solve the error....???


    #define CR 0x0D
    #include <LPC21xx.H>
    #include <stdio.h>
    void getstring(unsigned char *);
    int getchar (void) /* Read character from Serial Port */
    void status_ok(void);
    void Serial_Init(void);
    void delay(unsigned int n);
    void main(void)
    {
    unsigned int cnt=0x80,m;
    char xx;
    Serial_Init();
    delay(50);
    while(1)
    {
    printf("AT\r"); // AT COMMAND FOR INITIALING
    status_ok();
    printf("AT+IPR=9600\r"); // AT COMMAND FOR BAUD RATE
    status_ok();
    printf("AT+CMGR=2\r"); // Reading the message detail
    // at Index 1 with phone number, data and time
    status_ok();
    delay(250);
    printf("ATD9727855007;\r");//AT COMMAND FOR CALL DIALING
    delay(250);
    status_ok();
    delay(500);
    delay(500);
    delay(500);
    delay(500);
    delay(500);
    delay(500);
    printf("ATH\r"); // AT COMMAND FOR CALL DISCONNECTING
    delay(250);
    status_ok();
    delay(500);
    delay(500);
    printf("ATDL\r"); // AT COMMAND FOR REDIALING
    delay(250);
    status_ok();
    delay(500);
    delay(500);
    printf("ATH\r"); // AT COMMAND FOR ANSWERING THE CALL
    delay(250);
    status_ok();
    delay(500);
    delay(500);
    }
    }
    void getstring(unsigned char *array)
    {
    unsigned char temp=0, i=0;
    do
    {
    temp = getchar();
    *array++ = temp;
    }
    while((temp != '\r') && (temp != '\n'));
    *array = '\0';
    }
    int getchar (void) /* Read character from Serial Port */
    {
    while (!(U0LSR & 0x01));
    return (U0RBR);
    }
    void status_ok(void)
    {
    getstring(y);
    while(!(strstr(y,"OK"))) getstring(y);
    pointr = strstr(y,"OK");
    lcd_cmd(0xc0);
    lcd_data(*pointr++);
    lcd_data(*pointr);
    delay(500);
    lcd_cmd(0x01);
    }
    void Serial_Init(void)
    {
    PINSEL0 |= 0X00000005; //Enable Txd0 and Rxd0
    U0LCR = 0x00000083; //8-bit data, no parity, 1-stop bit
    U0DLL = 0x00000061; //for Baud rate=9600,DLL=82
    U0LCR = 0x00000003; //DLAB = 0;
    }
    void delay(unsigned int n)
    {
    unsigned int i,j;
    for(i=0;i<n;i++)
    {
    for(j=0;j<12000;j++)
    {;}
    }
    }





    #define CR 0x0D
    #include <LPC21xx.H>
    #include <stdio.h>
    void getstring(unsigned char *);
    int getchar (void) /* Read character from Serial Port */
    void status_ok(void);
    void Serial_Init(void);
    void delay(unsigned int n);
    void main(void)
    {
    unsigned int cnt=0x80,m;
    char xx;
    Serial_Init();
    delay(50);
    while(1)
    {
    printf("AT\r"); // AT COMMAND FOR INITIALING
    status_ok();
    printf("AT+IPR=9600\r"); // AT COMMAND FOR BAUD RATE
    status_ok();
    printf("AT+CMGR=2\r"); // Reading the message detail
    // at Index 1 with phone number, data and time
    status_ok();
    delay(250);
    printf("ATD9790550124;\r");//AT COMMAND FOR CALL DIALING
    delay(250);
    status_ok();
    delay(500);
    delay(500);
    delay(500);
    delay(500);
    delay(500);
    delay(500);
    printf("ATH\r"); // AT COMMAND FOR CALL DISCONNECTING
    delay(250);
    status_ok();
    delay(500);
    delay(500);
    printf("ATDL\r"); // AT COMMAND FOR REDIALING
    delay(250);
    status_ok();
    delay(500);
    delay(500);
    printf("ATH\r"); // AT COMMAND FOR ANSWERING THE CALL
    delay(250);
    status_ok();
    delay(500);
    delay(500);
    }
    }
    void getstring(unsigned char *array)
    {
    unsigned char temp=0, i=0;
    do
    {
    temp = getchar();
    *array++ = temp;
    }
    while((temp != '\r') && (temp != '\n'));
    *array = '\0';
    }
    int getchar (void) /* Read character from Serial Port */
    {
    while (!(U0LSR & 0x01));
    return (U0RBR);
    }
    void status_ok(void)
    {
    getstring(y);
    while(!(strstr(y,"OK"))) getstring(y);
    pointr = strstr(y,"OK");
    lcd_cmd(0xc0);
    lcd_data(*pointr++);
    lcd_data(*pointr);
    delay(500);
    lcd_cmd(0x01);
    }
    void Serial_Init(void)
    {
    PINSEL0 |= 0X00000005; //Enable Txd0 and Rxd0
    U0LCR = 0x00000083; //8-bit data, no parity, 1-stop bit
    U0DLL = 0x00000061; //for Baud rate=9600,DLL=82
    U0LCR = 0x00000003; //DLAB = 0;
    }
    void delay(unsigned int n)
    {
    unsigned int i,j;
    for(i=0;i<n;i++)
    {
    for(j=0;j<12000;j++)
    {;}
    }
    }
    #define CR 0x0D
    #include <LPC21xx.H>
    #include <stdio.h>
    void getstring(unsigned char *);
    int getchar (void) /* Read character from Serial Port */
    void status_ok(void);
    void Serial_Init(void);
    void delay(unsigned int n);
    void main(void)
    {
    unsigned int cnt=0x80,m;
    char xx;
    Serial_Init();
    delay(50);
    while(1)
    {
    printf("AT\r"); // AT COMMAND FOR INITIALING
    status_ok();
    printf("AT+IPR=9600\r"); // AT COMMAND FOR BAUD RATE
    status_ok();
    printf("AT+CMGR=2\r"); // Reading the message detail
    // at Index 1 with phone number, data and time
    status_ok();
    delay(250);
    printf("ATD9790550124;\r");//AT COMMAND FOR CALL DIALING
    delay(250);
    status_ok();
    delay(500);
    delay(500);
    delay(500);
    delay(500);
    delay(500);
    delay(500);
    printf("ATH\r"); // AT COMMAND FOR CALL DISCONNECTING
    delay(250);
    status_ok();
    delay(500);
    delay(500);
    printf("ATDL\r"); // AT COMMAND FOR REDIALING
    delay(250);
    status_ok();
    delay(500);
    delay(500);
    printf("ATH\r"); // AT COMMAND FOR ANSWERING THE CALL
    delay(250);
    status_ok();
    delay(500);
    delay(500);
    }
    }
    void getstring(unsigned char *array)
    {
    unsigned char temp=0, i=0;
    do
    {
    temp = getchar();
    *array++ = temp;
    }
    while((temp != '\r') && (temp != '\n'));
    *array = '\0';
    }
    int getchar (void) /* Read character from Serial Port */
    {
    while (!(U0LSR & 0x01));
    return (U0RBR);
    }
    void status_ok(void)
    {
    getstring(y);
    while(!(strstr(y,"OK"))) getstring(y);
    pointr = strstr(y,"OK");
    lcd_cmd(0xc0);
    lcd_data(*pointr++);
    lcd_data(*pointr);
    delay(500);
    lcd_cmd(0x01);
    }
    void Serial_Init(void)
    {
    PINSEL0 |= 0X00000005; //Enable Txd0 and Rxd0
    U0LCR = 0x00000083; //8-bit data, no parity, 1-stop bit
    U0DLL = 0x00000061; //for Baud rate=9600,DLL=82
    U0LCR = 0x00000003; //DLAB = 0;
    }
    void delay(unsigned int n)
    {
    unsigned int i,j;
    for(i=0;i<n;i++)
    {
    for(j=0;j<12000;j++)
    {;}
    }
    }
    #define CR 0x0D
    #include <LPC21xx.H>
    #include <stdio.h>
    void getstring(unsigned char *);
    int getchar (void) /* Read character from Serial Port */
    void status_ok(void);
    void Serial_Init(void);
    void delay(unsigned int n);
    void main(void)
    {
    unsigned int cnt=0x80,m;
    char xx;
    Serial_Init();
    delay(50);
    while(1)
    {
    printf("AT\r"); // AT COMMAND FOR INITIALING
    status_ok();
    printf("AT+IPR=9600\r"); // AT COMMAND FOR BAUD RATE
    status_ok();
    printf("AT+CMGR=2\r"); // Reading the message detail
    // at Index 1 with phone number, data and time
    status_ok();
    delay(250);
    printf("ATD9790550124;\r");//AT COMMAND FOR CALL DIALING
    delay(250);
    status_ok();
    delay(500);
    delay(500);
    delay(500);
    delay(500);
    delay(500);
    delay(500);
    printf("ATH\r"); // AT COMMAND FOR CALL DISCONNECTING
    delay(250);
    status_ok();
    delay(500);
    delay(500);
    printf("ATDL\r"); // AT COMMAND FOR REDIALING
    delay(250);
    status_ok();
    delay(500);
    delay(500);
    printf("ATH\r"); // AT COMMAND FOR ANSWERING THE CALL
    delay(250);
    status_ok();
    delay(500);
    delay(500);
    }
    }
    void getstring(unsigned char *array)
    {
    unsigned char temp=0, i=0;
    do
    {
    temp = getchar();
    *array++ = temp;
    }
    while((temp != '\r') && (temp != '\n'));
    *array = '\0';
    }
    int getchar (void) /* Read character from Serial Port */
    {
    while (!(U0LSR & 0x01));
    return (U0RBR);
    }
    void status_ok(void)
    {
    getstring(y);
    while(!(strstr(y,"OK"))) getstring(y);
    pointr = strstr(y,"OK");
    lcd_cmd(0xc0);
    lcd_data(*pointr++);
    lcd_data(*pointr);
    delay(500);
    lcd_cmd(0x01);
    }
    void Serial_Init(void)
    {
    PINSEL0 |= 0X00000005; //Enable Txd0 and Rxd0
    U0LCR = 0x00000083; //8-bit data, no parity, 1-stop bit
    U0DLL = 0x00000061; //for Baud rate=9600,DLL=82
    U0LCR = 0x00000003; //DLAB = 0;
    }
    void delay(unsigned int n)
    {
    unsigned int i,j;
    for(i=0;i<n;i++)
    {
    for(j=0;j<12000;j++)
    {;}
    }
    }
     

Share This Page