This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

How to interface GSM adn GPS to the LPC2148 micro controller.

Hi All,

Am trying to interface GSM(UART0) and GPS(UIART1). I checked individually both modules are working perfectly by connecting to the both UARTs. When i connect to the both then my MUC unit is going to be hanged. if i swith off the GPS moduel then it is working correctly. Can any one pls help me to solve this.

Parents
  • The solution to the problem is debugging.

    You either have errors in your source code (that is totally impossible for us to know about, since we don't want to hack your computer), or your hardware have issues so it can't properly power both modules at the same time.

Reply
  • The solution to the problem is debugging.

    You either have errors in your source code (that is totally impossible for us to know about, since we don't want to hack your computer), or your hardware have issues so it can't properly power both modules at the same time.

Children
  • Am using 12V adapters for all modules. Is it sufficient? And plese check hte below code if you have time.

    My aim of this code is that if i messaged to the mobile no which is placed in GSM the it has to replay to that no as GPS (LT and LG) Values. for that am first initalizing the components(UARTO_init, GSM init) and then reading the message ,getting the GPS values and replying back to that no. I tested individually these 2 operations but when connecting both then it is hanging.

    I hope now my problem is clear to you.

  • code:
    void SEND_UART0(unsigned char *p)
    {

    unsigned int N,len;
    len=strlen(p);
    for(N=0;N<=len;N++)
    { U0THR=*p;
    while(!(U0LSR&0X20));
    p++;
    } }

    void SEND_CHAR(unsigned char p)
    { U0THR=p;
    while(!(U0LSR&0X20));
    }

    /**********************************************/

    unsigned char msgindicator(void)
    { unsigned char str0[50];
    unsigned char ch,sim[1];
    unsigned char x=0;

    for(x=0;x<13;x++)
    { while(!(U0LSR&0X01));
    ch=U0RBR;
    str0[x]=ch;
    }

    while(ch!=0x0d)
    { str0[x++]=ch;
    while(!(U0LSR&0X01));
    ch=U0RBR;
    } str0[x]='\0';
    lcd_write_control(0x01);goto_cursor(0x00);
    lcd_print("NEW MSG RECEIVED");
    sim[0]=str0[--x];
    lcd_write_control(0x01);goto_cursor(0x00);
    lcd_print("index no:");
    goto_cursor(0x40);
    lcd_print(sim);
    return(sim[0]);
    } /****************************************************************************/
    void msgread(unsigned char sim)
    { unsigned char ch;//,*p;
    unsigned char x=0;
    //unsigned char str0[50];

    SEND_CHAR('A');
    SEND_CHAR('T');
    SEND_CHAR('+');
    SEND_CHAR('C');
    SEND_CHAR('M');
    SEND_CHAR('G');
    SEND_CHAR('R');
    SEND_CHAR('=');
    SEND_CHAR(sim);
    SEND_CHAR(0X0D);
    SEND_CHAR(0X0A);

    for(x=0;x<22;x++)
    { while(!(U0LSR&0X01));
    ch=U0RBR;
    //str0[x]=ch;
    } for(x=0;x<2;x++)
    { while(!(U0LSR&0X01));
    ch=U0RBR;
    }

    //while(ch!=0x0d)
    for(x=0;x<15;x++)
    { str1[x]=ch;
    while(!(U0LSR&0X01));
    ch=U0RBR;
    } str1[x]='\0';

    while(ch!=0x0d)
    { while(!(U0LSR&0X01));
    ch=U0RBR;
    }

    while(!(U0LSR&0X01));
    ch=U0RBR;

    x=0;
    while(ch!=0x0d)
    { while(!(U0LSR&0X01));
    ch=U0RBR;
    str2[x++]=ch;
    } str2[x]='\0';

    lcd_write_control(0x01);goto_cursor(0x00);
    lcd_print("MOBILE NO:");

    goto_cursor(0x40);
    lcd_print(str1);
    delay(700000);
    delay(700000);
    delay(700000);

    lcd_write_control(0x01);goto_cursor(0x00);
    lcd_print("MESSAGE:");
    delay(700000);
    delay(700000);
    delay(700000);
    goto_cursor(0x40);
    lcd_print(str2);

    gps();

    sendsms();
    //msgcompare();
    }

    /***************************************/
    void sendsms()
    {

    lcd_write_control(0x01);goto_cursor(0x00);
    lcd_print("SENDING MESSAGE");
    send_sms("AT+CMGS=",str1,LT);
    //send_sms("AT+CMGS=\"9052217913\"",LON);
    lcd_write_control(0x01);
    goto_cursor(0x00);
    lcd_print("MESSAGE SENT");
    }

    /*****************************************/

    void gsm_init(void)
    { modem_send("AT"); lcd_write_control(0x01);goto_cursor(0x00); lcd_print("AT"); delay(2000); modem_send("ATE0"); lcd_write_control(0x01);goto_cursor(0x00); lcd_print("ATE0"); delay(2000); modem_send("AT+CSMS=0"); lcd_write_control(0x01);goto_cursor(0x00); lcd_print("AT+CSMS=0"); delay(2000); modem_send("AT+IPR=9600"); lcd_write_control(0x01);goto_cursor(0x00); lcd_print("AT+IPR=9600"); delay(2000); modem_send("AT+CMGF=1"); lcd_write_control(0x01);goto_cursor(0x00); lcd_print("AT+CMGF=1"); delay(2000); modem_send("AT&W"); lcd_write_control(0x01);goto_cursor(0x00); lcd_print("AT&W"); delay(2000); lcd_write_control(0x01);goto_cursor(0x00); lcd_print("GSM Initialized"); delay(2000); lcd_write_control(0x01);goto_cursor(0x00);

    }

    void modem_send(unsigned char *ch)
    { unsigned char cha; while(*ch) { U0THR = *ch; while(!(U0LSR&0x20)); ch++; } SEND_CHAR(0X0D); SEND_CHAR(0X0A); while(1) { while(!(U0LSR&0x01)); cha = U0RBR; if(cha == 'O') while(!(U0LSR&0x01)); cha = U0RBR; if(cha == 'K') break; }
    }

    /********************************************************/

    void gsm_fun()
    { unsigned char sim,check;
    sim=msgindicator();
    msgread(sim);
    do
    { check=msgdelete(sim);
    }while(check==0);
    sendsms();
    }

    unsigned char msgdelete(unsigned char sim)
    { unsigned char ch;
    unsigned char x=0;
    unsigned char str0[50];
    unsigned char No[10];

    No[0]=sim;
    lcd_write_control(0x28);
    lcd_write_control(0x01);goto_cursor(0x00);
    lcd_print("Message Deleting At");
    goto_cursor(0x40);
    lcd_print(No);

    delay(700000);
    delay(700000);
    delay(700000);
    delay(400000);
    delay(400000);

    SEND_CHAR('A');
    SEND_CHAR('T');
    SEND_CHAR('+');
    SEND_CHAR('C');
    SEND_CHAR('M');
    SEND_CHAR('G');
    SEND_CHAR('D');
    SEND_CHAR('=');
    SEND_CHAR(sim);
    SEND_CHAR(0X0D);
    SEND_CHAR(0X0A);

    while(!(U0LSR&0X01));
    ch=U0RBR;
    while(ch!='K')
    { str0[x++]=ch;
    while(!(U0LSR&0X01));
    ch=U0RBR;
    } if(ch!='K') { lcd_write_control(0x01);goto_cursor(0x00); lcd_print("Message Deleted"); return(0); }
    return(1);

    } void send_sms(unsigned char *cmd,unsigned char *No,unsigned char *Message)
    { unsigned char ch='X'; while(*cmd) { U0THR = *cmd; while(!(U0LSR&0x20)); cmd++; } while(*No) { U0THR = *No; while(!(U0LSR&0x20)); No++; } SEND_CHAR(0X0D); SEND_CHAR(0X0A); while(ch!='>') { while(!(U0LSR&0x01)); ch = U0RBR; } while(*Message) { U0THR = *Message; while(!(U0LSR&0x20)); Message++; } U0THR = 0x1A; while(!(U0LSR&0x20));
    }

    void gps(void)
    { unsigned char gp='\0',t;

    lcd_write_control(0x01);goto_cursor(0x00); lcd_print("GPS Initialized");

    while(gp!='$') { while(!(U1LSR&0x01)); gp=U1RBR;

    } gp='\0'; while(gp!='G') { while(!(U1LSR&0x01)); gp=U1RBR; } gp='\0'; while(gp!='P') { while(!(U1LSR&0x01)); gp=U1RBR; } gp='\0'; while(gp!='G') { while(!(U1LSR&0x01)); gp=U1RBR; } gp='\0'; while(gp!='G') { while(!(U1LSR&0x01)); gp=U1RBR; } gp='\0'; while(gp!='A') { while(!(U1LSR&0x01)); gp=U1RBR; } gp='\0'; while(!(U1LSR&0x01)); for(t=0;t<18;t++) { while(!(U1LSR&0x01)); } while(!(U1LSR&0x01)); for(t=0;t<12;t++) { while(!(U1LSR&0x01)); LT[t]=U1RBR ; }

    LT[t]='\0';

    while(!(U1LSR&0x01)); for(t=0;t<12;t++) { while(!(U1LSR&0x01)); LT[t]=U1RBR ; }

    lcd_write_control(0x01); goto_cursor(0x00); lcd_print("LATITUDE"); goto_cursor(0x40); lcd_print(LT); while(!(U1LSR&0x01)); for(t=0;t<12;t++) { while(!(U1LSR&0x01)); LG[t]=U1RBR ; } LG[t]='\0'; goto_cursor(0x00); lcd_print("LONGITUDE"); goto_cursor(0x40); lcd_print(LG);
    } int main()
    { lcd_init();
    UART0_INIT();
    lcd_write_control(0x01);
    goto_cursor(0x00);
    lcd_print("Test");
    gsm_init();
    while(1)
    { gsm_fun();
    } }

  • I can see the great care you took in reading the instructions on how to post source code. You think anyone can read your code when you just inlined it?

    If you had read the info just above the message input box, your code would have looked like:

    #include <stdio.h>
    
    void main(void) {
        printf("hello world!\n");
        for (;;) ;
    }
    

    Another thing - you have random loops waiting for multiple characters, but not caring about what to do with them.

    And you have busy-loops waiting for characters to be available. A busyloop to wait for a character only works when you have a single port - or where there is guaranteed to show up some data within a limited time. What do you think on serial port 2, if your program is locked up waiting for nonexisting characters on serial port 1?

    It's all in debugging. You just have to learn how to debug code, and you would quickly realize what goes wrong. It really is up to _you_ to test your code. "programming" isn't the art if writing text. It's the art of producing working routines. That includes design, testing, documentation, ...