arm - Sending an SMS from LPC2148 to a mobile phone -


i posted similar question yesterday not able edit code , post more problems, reposting here. have connected gsm modem lpc2148 , sending simple message "vehicle" mobile. have put in print statements in between know program is. runs print statements message not sent!

so here code

main.c

    #include "i2c.h"                           #include "lpc214x.h"                                    // lpc2148 mpu register     #include <stdio.h>     #include "gsm.h"     #include "lcd.h"     #include "buzzer.h"       extern int msgflag;                                                          /* main program start here */     int main(void)     {           pinsel0 = 0x00000000;        // enable gpio on pins     pinsel1 = 0x00000000;     pinsel2 = 0x00000000;         lcd_init();                                           // initial lcd       lcd_write_control(0x01);                              // clear display  (clear display,set dd ram address=0)          goto_cursor(0x00);                                  // set cursor line-1         //lcd_print("gps");                     // display lcd line-1            lcd_print("gsm");          gsmperform();     } 

gsm.c

#include<lpc214x.h>                                                  /*header file*/ #include "gsm.h"                                                     //header file #include "lcd.h" extern unsigned char cmgf[]="at+cmgf=1";                            //text format in gsm modem extern unsigned char cmgs[]="at+cmgs=\"+919844420844\"";            //mobile number msg sent //extern unsigned char msg[]="*\0";                                //secret code extern unsigned char msg[]="vehicle";                                  //secret code extern unsigned char readall[]="at+cmgr=\"rec unread\"\r\n"; //static unsigned char lat[10]; //static unsigned char lon[11]; //extern int blink; unsigned char content[7]; void txu1(unsigned char data)                 //transmit byte of data through uart1 { while(!(u1lsr & 0x20));                         // wait until uart1 ready send character       u1thr = data;      lcd_write_control(0x01);                            // clear display  (clear display,set dd ram address=0)      goto_cursor(0x00);                                  // set cursor line-1     lcd_print("data");                      // display lcd line-1   } unsigned char rxu1() { unsigned char p; while ((u1lsr&0x01)!=1); p=u1rbr; return p; } /*unsigned char rxu0() { unsigned char p; while ((u0lsr&0x01)!=1); p=u0rbr; return p; } */ void sendstring(unsigned char *p)            //sends string of data through uart1 { while(1) { if(*p=='\0') break; txu1(*p++); } } void delaygsm()                           //delay function { int i,j; for(i=0;i<60000;i++) for(j=0;j<51;j++); } void delay2()                             //delay function { int i,j; for(i=0;i<60000;i++) for(j=0;j<200;j++); } unsigned char recuart1()             //recieves byte uart1 { unsigned char p; while ((u1lsr&0x01)!=1); p=u1rbr; return p; }       void sendmsg(void) {  sendstring(cmgf); lcd_write_control(0x01);                            // clear display  (clear display,set dd ram address=0)      goto_cursor(0x00);                                  // set cursor line-1     lcd_print("cmgf");                      // display lcd line-1   txu1(0x0d);                                     // equivalent of  txu1(0x0a);                                     //   enter key delaygsm(); sendstring(cmgs); lcd_write_control(0x01);                            // clear display  (clear display,set dd ram address=0)      goto_cursor(0x00);                                  // set cursor line-1     lcd_print("cmgs");                      // display lcd line-1   txu1(0x0d); txu1(0x0a);   delaygsm(); sendstring(msg); lcd_write_control(0x01);                            // clear display  (clear display,set dd ram address=0)      goto_cursor(0x00);                                  // set cursor line-1     lcd_print("msg");                       // display lcd line-1   //sendstring(lat); //sendstring(lon); txu1(0x1a); delay2(); txu1(0x1a); } void initgsm()                               //initialization of uart0,uart1 , isr { lcd_write_control(0x01);                            // clear display  (clear display,set dd ram address=0)      goto_cursor(0x00);                                  // set cursor line-1     lcd_print("begin init");                        // display lcd line-1       u0lcr=0x83; u0dll=0x61; u0dlm=0x00; u0lcr=0x03; u1lcr=0x83; u1dll=0x61; u1dlm=0x00; u1lcr=0x03; u1ier=0x01; u1fcr=0x07;  */ lcd_write_control(0x01);                            // clear display  (clear display,set dd ram address=0)      goto_cursor(0x00);                                  // set cursor line-1     lcd_print("end init");                      // display lcd line-1      sendmsg(); lcd_write_control(0x01);                            // clear display  (clear display,set dd ram address=0)      goto_cursor(0x00);                                  // set cursor line-1     lcd_print("in sendmsg");                        // display lcd line-1    } void gsmperform(void) { lcd_write_control(0x01);                            // clear display  (clear display,set dd ram address=0)      goto_cursor(0x00);                                  // set cursor line-1     lcd_print("begin gsm");                     // display lcd line-1   pinsel0|=0x00050005; pinsel1|=0x00000000; pinsel2|=0x00000000;  /* nsk   pinsel0 &= 0xfff0ffff;                                 // reset p0.8,p0.9 pin config   pinsel0 |= 0x00010000;                                    // select p0.8 = txd(uart1)   pinsel0 |= 0x00040000;                                    // select p0.9 = rxd(uart1)   */   initgsm(); sendstring("ate0\r\n"); lcd_write_control(0x01);                            // clear display  (clear display,set dd ram address=0)      goto_cursor(0x00);                                  // set cursor line-1     lcd_print("ate0");                      // display lcd line-1   delaygsm(); sendstring("at+cmgd=1,4\r\n"); lcd_write_control(0x01);                            // clear display  (clear display,set dd ram address=0)      goto_cursor(0x00);                                  // set cursor line-1     lcd_print("at+cmgd");                       // display lcd line-1   delaygsm(); sendstring("at+cnmi=1,0,0,0\r\n"); lcd_write_control(0x01);                            // clear display  (clear display,set dd ram address=0)      goto_cursor(0x00);                                  // set cursor line-1     lcd_print("at+cnmi");                       // display lcd line-1   delaygsm(); lcd_write_control(0x01);                            // clear display  (clear display,set dd ram address=0)      goto_cursor(0x00);                                  // set cursor line-1     lcd_print("end gsm");                       // display lcd line-1   } 

there couple of things here fundamentally wrong way handle @ commands.

first of all, never, never, never, ever use delays function delaygsm. must change logic processing after sending command, absolutely nothing reading responses modem until final result code before starting on next command. see this answer details on that.

turning off echo ate0 gives less text parse, there no way around. must read , parse responses given modem. not complicated, follow directions given in answer linked above.

also notice @ command lines should terminated '\r' (or written 0x0d) , nothing else, see this answer details.


Comments

Popular posts from this blog

c# - How to get the current UAC mode -

postgresql - Lazarus + Postgres: incomplete startup packet -

javascript - Ajax jqXHR.status==0 fix error -