setup() not being called in Arduino Sketch

I had build a program that run ceratin AT comands to GSM module through software serial library.I am using 2 software serial as i need to keep hardware serial vaccant for debugging.

i had ceratin question
i) Some time when everything works fine..means both sofwtare serial work fine(1 for GPRS and 1 for GPS) and i remove USB cable from Arduyino Duemilanove, everything stop working(means software serial stop sending data) and as i plug the cable again, they start sending data again.I don't know why this is happening.

ii) Secondly, setup function in my code is not getting executed.Sketch directly start from the void loop function and that is causing me troble.I had searched a lot about it, but maximum i can get is , it is due to declaring too many global variables outside set-up.

Here is my code for getting GPRS coordinates and pusghing themover to a HTTP server.

#include <stdio.h>
#include <SoftwareSerial.h>
#define DATABUFFERSIZE 100
const int ledPin = 13;
char dataBuffer[DATABUFFERSIZE+1]; 
char startChar = '

i used GprsSerial.listen();, so that i can listen what GPRS is reverting and send it across to serial for debugging purpose.I dont know wether it right or wrong.But i need to get the response from server so as to debug whether i am able to send data to server or not.

;
char endChar = '\n';
boolean storeString = false;
SoftwareSerial BTSerial(10, 11);
SoftwareSerial GprsSerial(7, 8);
char *a, *b, *c, *d, *e,*f,*g,*h,*i,*j;

void setup()
{
 
  Serial.begin(9600);
  GprsSerial.begin(9600);

GprsSerial.listen();
  GprsSerial.println("AT+CGATT?");  // attach or detach from GPRS service //if = 1, that means GPRS service is active over SIm and 0 means not.
  toSerial();
  //GprsSerial.flush();
  //Serial.flush();

GprsSerial.println("AT+SAPBR=3,1,"CONTYPE","GPRS"");  // bearer settings
  toSerial();

GprsSerial.println("AT+SAPBR=3,1,"APN","rcomnet""); //here rcomnet is the APN name for reliance in Delhi, you have to change it to the APNname for your provider
    toSerial();

GprsSerial.println("AT+SAPBR=1,1");
    toSerial();
    BTSerial.begin(9600);

}

void loop(){
  if(getSoftwareSerialstring()){
    //GprsSerial.println(dataBuffer);
    if(strstr(dataBuffer,"$GPGGA")){
      Serial.println(dataBuffer);
      char FinalDatatobeSend[500];
      char *a, *b, *c, *d, *e,*f,*g,*h,*i,*j;
      a = strtok(dataBuffer,",");
      b = strtok(NULL,",");
      c = strtok(NULL,",");
      d = strtok(NULL,",");
      e = strtok(NULL,",");
      f = strtok(NULL,",");
      g = strtok(NULL,",");
      h = strtok(NULL,",");
      i = strtok(NULL,",");
      j = strtok(NULL,",");

GprsSerial.listen();

char *URLdatatobeSend="AT+HTTPPARA="URL","http://requestb.in/mzqsddmz?id=1&latitude=%s&latDir=%s&longitude=%s&lonDir=%s&&altitude=%s\"";
      sprintf(FinalDatatobeSend,URLdatatobeSend,c,d,e,f,i);
     
      // initialize http service
      GprsSerial.println("AT+HTTPINIT");
      delay(2000);
      toSerial();

GprsSerial.println("AT+HTTPPARA="CID",1");
      delay(1000);

GprsSerial.println(FinalDatatobeSend); //string embedded with sensor value
      delay(1000);
      toSerial();

// set http action type 0 = GET, 1 = POST, 2 = HEAD
      GprsSerial.println("AT+HTTPACTION=1");
      delay(2000);
      toSerial();

// read server response
      GprsSerial.println("AT+HTTPREAD");
      delay(1000);
     
      toSerial();
 
      GprsSerial.println("");
      GprsSerial.println("AT+HTTPTERM");
      toSerial();
      delay(300);

GprsSerial.println("");
      delay(1000);
      toSerial();

BTSerial.listen();
    }
  }
}
void toSerial()
{
  while(GprsSerial.available()!=0)
  {
    Serial.write(GprsSerial.read());
  }
}

boolean getSoftwareSerialstring(){
static byte dataBufferIndex = 0;

while(BTSerial.available()>0){
    char incomingByte = BTSerial.read();
    if(incomingByte ==startChar){

dataBufferIndex = 0;
      storeString =true;
    }
    if(storeString){
      if(dataBufferIndex == DATABUFFERSIZE){
        dataBufferIndex = 0;
        break;
      }
      if(incomingByte==endChar){
        dataBuffer[dataBufferIndex] = 0;
        return true;
      }
      else{
        dataBuffer[dataBufferIndex++]=incomingByte;
        dataBuffer[dataBufferIndex] = 0;
      }
    }
    else{
    }
  }
  return false;
}


i used GprsSerial.listen();, so that i can listen what GPRS is reverting and send it across to serial for debugging purpose.I dont know wether it right or wrong.But i need to get the response from server so as to debug whether i am able to send data to server or not.
  1. How are you powering things with the USB lead removed? Does the on LED stay on?

  2. setup will always be run on a power up or a reset, what makes you think it isn't.

  1. How are you powering things with the USB lead removed? Does the on LED stay on?

I am powering Board with the help of a Lipo battery with 11.1 V , 2200 Mah specs.

  1. setup will always be run on a power up or a reset, what makes you think it isn't.
    Set-up is not runing as i am not getting any thing printed on the serial port of Arduino IDE.strings inside void loop get printed but not those which are inside the set-up.And those At comamnds which are inside setup are very necessary for initializing the GSm module.

Does the on LED stay on?

What sort of arduino do you have?
Put some code to blink the on board led a few times to see that the code in setup is not being missed.

I don't see any Serial.println() commands in Setup() - but it wouldn't be the first time I missed something obvious.

...R

void setup()
{ 
   Serial.begin(9600);
   Serial.println (F("setup active"));

And now?

I think that was the reason, i wasn't giving any delay inside set-up after sending AT commands to GSM module...and now when i gave delay after every At command being send on the respective Software serial port, it working.

Also now when i am running my code after giving

Serial.println("Configguring SIM 900");

and delay after every AT command .