2014-03-06 60 views
0

我昨天发布了一个类似的问题但我无法编辑代码并发布更多问题,所以我在这里重新发布。我已将gsm调制解调器连接到LPC2148,并且正在向我的手机发送一条简单的消息“车辆”。我已经在两者之间发表了打印声明,以便我知道程序在哪里。它运行所有的打印语句,但不发送消息!发送短信从LPC2148到手机

所以这里是代码

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 all 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 to which the msg is 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 a byte of data through UART1 
{ 
while(!(U1LSR & 0x20));       // Wait until UART1 ready to 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 a 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 a byte from 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 and 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 
} 

回答

0

有几件事情在这里,是从根本上走错了路处理AT命令。

首先,永远不会永远不会使用类似函数delaygsm的延迟。您必须更改处理逻辑,以便在发送命令后,除了读取调制解调器的响应之外,您完全不需要做任何事情,直到您获得最终结果代码,然后才开始执行下一个命令。有关详情,请参阅this answer

用ATE0关闭回声只会让你解析的文本略少,但是没有办法解决。您必须阅读并解析调制解调器给出的回应。这并不复杂,只需按照上面链接中给出的指导。

另请注意,AT命令行应以'\r'(或只写为0x0d)而没有其他内容,详情请参阅this answer