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

I am not able to get this code work. the function gsmcall(); does not get called at all. Please help me rectify my errors.

#include <lpc214x.h>
#include <stdio.h>


#define PLOCK 0x00000400 // for PLL
#define THRE (1<<5) // Transmit Holding Register Empty
#define RDR (1<<0) // Receiver Data Ready
#define MULVAL 15
#define DIVADDVAL 1
#define NEW_LINE 0xA // Character for new line, analogous to '\n'
#define ENTER 0xD // ASCII code for ENTER


void sysInit();
void gsminit();
void gsmcall();
void string_0(unsigned char *);
unsigned char gsmrec();
void delay(unsigned int);
void eval(unsigned char, int);
void initClocks(void);
void setupPLL0(void);
void feedSeq(void);
void connectPLL0(void);


int main(void)
{
      int flag=0;
       unsigned char ch1='\0';
       //initClocks(); // Set CCLK=60Mhz and PCLK=60Mhz
       sysInit();
       gsminit();
       gsmcall();
       delay(5000);
       ch1=gsmrec();
       delay(50000000);
       if(ch1=='\0')
      flag=1;
       eval(ch1,flag);
       return 0;
}


void sysInit()
{
       PINSEL0 |= 0X00000005;
       PINSEL1 = 0x00000000;
       IO1DIR = 0xFFFFFFFF;
       IO1SET = 0xFFFFFFFF;
       U0LCR  = 0x00000083; //8-bit data, no parity, 1-stop bit   
      U0DLL   = 0x00000061;  //for Baud rate=9600,DLL=82   
      U0LCR   = 0x00000003;  //DLAB = 0
       //U0LCR = 3 | (1<<7) ; /* 8 bits, no Parity, 1 Stop bit | DLAB set to 1  */
       //U0DLL = 110;
       //U0DLM = 1;  
       //U0FDR = (MULVAL<<4) | DIVADDVAL; /* MULVAL=15(bits - 7:4) , DIVADDVAL=0(bits - 3:0)  */
       //U0LCR &= 0x0F; // Set DLAB=0 to lock MULVAL and DIVADDVAL, BaudRate is now ~9600
}


unsigned char recch(void)
{
       while( !(U0LSR & RDR ) ) // wait till any data arrives into Rx FIFO
          {;}
       return U0RBR;
}


void gsminit()
{
       unsigned char rec=0;
       while(1)
       {
        string_0("AT\r\n");
        rec=recch();
        if((rec=='0')||(rec=='K'))
        {break;}
       }
  string_0("AT+IPR=9600\r"); // AT COMMAND FOR BAUD RATE
       delay(2000);
       string_0("AT+CREG?\r\n");
       delay(2000);
       string_0("AT+CMGF=1\r\n");
       delay(2000);
       string_0("AT+CNMI = 2,1,0,0,0\r\n");
       delay(2000);
}
void gsmcall()
{
       string_0("ATD+919757257894;\r\n");//AT COMMAND FOR CALL DIALING
       delay(2000);
}


void sendch(unsigned char ch)
{
       while ( !(U0LSR & THRE ) )
       {;}
       U0THR = ch;
}


void string_0(unsigned char *str)
{
  unsigned int i=0;
  while(str[i]!='\0')
  {
  sendch(str[i]);
  i++;
  }
}


unsigned char gsmrec()
{
  unsigned char chh;
  string_0("AT+CMGD=1,4\r\n");    
  string_0("AT+CMGR=1\r\n");
  delay(2000);
  chh=recch();
  return chh;
}


void delay(unsigned int n)
{
        int i,j,c=0;
       for(i=0;i<n;i++)
       {
              for(j=0;j<n;j++)
  { c++;}
       }
}


void eval(unsigned char ch, int flag)
{
       if((ch =='s')||(ch=='S')||(flag==1))
       {
  while(1)
  {
        IO1SET = 0xFFFFFFFF;
         delay(2000);
         IO1CLR = 0xFFFFFFFF;
         delay(2000);
               }
}
               else
{
                     IO1CLR = 0xFFFFFFFF;
}
}
void initClocks(void)
{
  setupPLL0();
  feedSeq(); //sequence for locking PLL to desired freq.
  connectPLL0();
  feedSeq(); //sequence for connecting the PLL as system clock


  //SysClock is now ticking @ 60Mhz!
   
  VPBDIV = 0x01; // PCLK is same as CCLK i.e 60Mhz


  //Using PLL settings as shown in : www.ocfreaks.com/.../
  //PLL0 Now configured!
}

//---------PLL Related Functions :---------------

void setupPLL0(void)
{
  //Note : Assuming 12Mhz Xtal is connected to LPC2148.


  PLL0CON = 0x01; // PPLE=1 & PPLC=0 so it will be enabled
  // but not connected after FEED sequence
  PLL0CFG = 0x24; // set the multipler to 5 (i.e actually 4)
  // i.e 12x5 = 60 Mhz (M - 1 = 4)!!!
  // Set P=2 since we want FCCO in range!!!
  // So , Assign PSEL =01 in PLL0CFG as per the table.
}


void feedSeq(void)
{
  PLL0FEED = 0xAA;
  PLL0FEED = 0x55;
}


void connectPLL0(void)
{
  // check whether PLL has locked on to the desired freq by reading the lock bit
  // in the PPL0STAT register


  while( !( PLL0STAT & PLOCK ));


  // now enable(again) and connect
  PLL0CON = 0x03;
}
  • Hi ritvija,

    If the function gsmcall() does not get called, program execution does not exit the function gsminit(). Inside gsminit() there are spots where your code may get confined in a loop:

    • The while(1) loop from gsminit() itself
    • The function recch() contains a while loop.
    • The function string_0() contains a while loop and string_0() calls sendch() which has a while loop.

    You should step your code so you can identify which among these loops is the cause of the problem.

    Also, here are additional pointers which may not be directly related to the cause of the main problem but may help make your program work properly.

    • The recurrent (compiler) optimization-induced problems. Check your program for portions that may get optimized out by the compiler.
    • Are you testing if the GSM modem has responded with "OK" through the if block?

           while(1) 

           { 

            string_0("AT\r\n"); 

            rec=recch(); 

            if((rec=='0')||(rec=='K'))

            {break;} 

           } 

    Note that the first test expression (rec=='0'), compares rec to 0 (zero) not O (letter O).

    Regards,

    Goodwin