Interfacing gsm with LPC2148

0

I am trying to send a message from my ARM7 LPC2148 board. I have connected a SIM900 GSM Modem to the UART0 of the board. But I am not receiving the message on my phone!!I have put print statements here and there so that I know where the system is and where its stuck. But it prints all the messages. It says message sent even though I have not received any SMS. Here is the code:

Main code

#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  
}
arm
gsm
at-command
uart
lpc
asked on Stack Overflow Mar 5, 2014 by user3359953 • edited Mar 5, 2014 by user3359953

1 Answer

0

Break up the problem into three parts - Configuring & sending the command, receiving the correct command, and working together.

  1. Connect your LPC2148 board to a PC, and use a PC terminal program to watch what commands you are sending. Make sure the parts of your program is working correctly. Are you running any optimizing options in your compiler? That will mess up your delay functions for sure. Use a built-in timer to provide the delay, not for loops.
  2. Make sure you are using the correct commands to talk to the GSM card. Connect it to a PC if possible (make sure you convert from logic levels to UART levels if it does not have an RS-232 transceiver on it), or to a kit running an interactive terminal. Make sure your commands actually will send an SMS message with the module you have chosen.
  3. Now connect the kit and the module. By now you should know which signals are actually outputs and which are inputs - RS-232 can be very confusing about this. Most processor UARTs are labelled as DTE (TX==output, RX==input), and I'd expect the comms module labeled as DCE (TX==input, RX==output), which means that you would connect RX<->RX and TX<->TX. If they are both labeled as DTE, then you need a null-modem cable to swap the signals, or do it by hand when attaching the board.
answered on Stack Overflow Mar 5, 2014 by Rich Hendricks

User contributions licensed under CC BY-SA 3.0