0

ARM7 LPC2148 ボードからメッセージを送信しようとしています。SIM900 GSM モデムをボードの UART0 に接続しました。しかし、私は自分の電話でメッセージを受信して​​いません!!システムがどこにあり、どこで動かなくなったかがわかるように、印刷ステートメントをあちこちに置いています。しかし、それはすべてのメッセージを出力します。SMS を受信して​​いないのに、メッセージが送信されたと表示されます。コードは次のとおりです。

メインコード

#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("Accident Alert");                        // Display LCD Line-1  

                        // Display LCD Line-2
                                    // Display Delay

                                // Clear Display  (Clear Display,Set DD RAM Address=0) 
                        // Display LCD Line-1    
    goto_cursor(0x40);                                  // Set Cursor = Line-2
    lcd_print("System");                        // Display LCD Line-2
    delay1(100000000);


gsmperform();

  // Loop Print Message to LCD16 x 2 //
                                                // Loop Continue








sendmsg();
msgflag=0;
lcd_write_control(0x01);                            // Clear Display  (Clear Display,Set DD RAM Address=0) 
    goto_cursor(0x00);                                  // Set Cursor Line-1
    lcd_print("Message sent");                      // Display LCD Line-1  



}

gsm.c

#include<lpc214x.h>                                                  /*Header file*/
#include "gsm.h"                
#include "lcd.h"                                     //header file
extern unsigned char cmgf[]="AT+CMGF=1";                            //Text format in GSM modem
extern unsigned char cmgs[]="AT+CMGS=\"9xxxxxxxxx\"";               //Mobile number to which the msg is sent
extern unsigned char msg[]="hello";                                //secret code
extern unsigned char readall[]="AT+CMGR=\"REC UNREAD\"\r\n";


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; 
}
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 uart1_irq() __irq                    //ISR if anything is recieved in UART1, the same is transmitted through UART0
{
unsigned char p;
p=U1RBR;
if(p=='a')
{
sendmsg();
}
VICVectAddr=0;
}
void sendmsg(void)
{


sendstring(msg);


}
void initgsm()                               //Initialization of UART0,UART1 and ISR
{
U0LCR=0x83;
U0DLL=0x61;
U0DLM=0x00;
U0LCR=0x03;
U1LCR=0x83;
U1DLL=0x61;
U1DLM=0x00;
U1LCR=0x03;
U1IER=0x01;
U1FCR=0x07;
VICIntSelect&=0xffffff7f;
VICVectAddr2=(unsigned int)uart1_irq;
VICIntEnable|=0x00000080;
VICVectCntl2=0x20|7;  
}
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;
initgsm();
sendstring("ATe0\r\n");
delaygsm();
sendstring("AT+CMGD=1,4\r\n");
delaygsm();
sendstring("AT+CNMI=1,0,0,0\r\n");
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  
}
4

1 に答える 1

0

問題を 3 つの部分に分割します。コマンドの構成と送信、正しいコマンドの受信、連携です。

  1. LPC2148 ボードを PC に接続し、PC ターミナル プログラムを使用して、送信しているコマンドを監視します。プログラムの一部が正しく機能していることを確認してください。コンパイラで最適化オプションを実行していますか? それは確かにあなたの遅延機能を台無しにします。forループ ではなく、組み込みのタイマーを使用して遅延を提供します。
  2. GSM カードと通信するために正しいコマンドを使用していることを確認してください。可能であれば PC に接続するか (RS-232 トランシーバーが搭載されていない場合は、ロジック レベルから UART レベルに変換してください)、またはインタラクティブ ターミナルを実行するキットに接続します。コマンドが実際に、選択したモジュールで SMS メッセージを送信することを確認してください。
  3. キットとモジュールを接続します。ここまでで、どの信号が実際に出力で、どの信号が入力であるかがわかったはずです。RS-232 では、これについて非常に混乱する可能性があります。ほとんどのプロセッサ UART は DTE (TX==出力、RX==入力) とラベル付けされており、通信モジュールは DCE (TX==入力、RX==出力) とラベル付けされていると思います。つまり、RX< を接続することを意味します。 ->RX および TX<->TX。両方とも DTE とラベル付けされている場合は、信号を交換するためにヌルモデム ケーブルが必要です。または、ボードを取り付けるときに手動で交換してください。
于 2014-03-05T19:03:22.597 に答える