Software Serial.available breaking hardware Serial.available

Hi.

I’m having a strange problem. It seems as if the software serial.available is breaking the hardware serial.available. After a few commenting-outs, I’ve isolated the part of sendData() that’s causing the problem, being the sendATcommand function (hint: it uses softwareserial.available!)

Code:

#include <LCD5110_Graph.h>
LCD5110 myGLCD(6,8,9,10,11);
extern uint8_t SmallFont[];

#include <SoftwareSerial.h>
SoftwareSerial GPRS(2, 3);


void setup(){
  pinMode(13,OUTPUT);
  myGLCD.InitLCD();
  myGLCD.setFont(SmallFont);
  GPRS.begin(4800);  
  Serial.begin(9600);
  sendData(); 
}
  
  int a=0;
  char item [300];
void loop(){ 
  //uncommenting this code breaks the sendData function!
//  while(Serial.available()>0){
//  item[a] = Serial.read();
//  a++;
//  if(a==250){
//    a=0; //reset array
//    //traverse through list to R
//    for(int i=0;i<250;++i){
//      if(item[i]=='R'){
//          show(String(item[i+1]));
//        }
//      }  
//    }
//  }
}

And the offending function within the sendData:

int8_t sendATcommand(char* ATcommand, char* expected_answer1, unsigned int timeout){

    uint8_t x=0,  answer=0;
    char response[500];
    unsigned long previous;

    memset(response, '\0', 100);    // Initialize the string

    delay(100);

    while( GPRS.available() > 0) GPRS.read();    // Clean the input buffer

    // Send the AT command 
   // Serial.print("Sending: ");
   // Serial.println(ATcommand);
    GPRS.println(ATcommand);
   // Serial.println(" (Sent) ");

        x = 0;
    previous = millis();

    // this loop waits for the answer
    do{
        if(GPRS.available() != 0){    
            response[x] = GPRS.read();
            x++;
            // check if the desired answer is in the response of the module
            
            if (strstr(response, expected_answer1) != NULL)    
            {
                answer = 1;
               // Serial.println(response);
            }
            
        }
        // Waits for the asnwer with time out
    }
    while((answer == 0) && ((millis() - previous) < timeout));    

    return answer;
}

If sendData is commented out, the stuff in “loop” works fine. If the stuff in loop is commented out, sendData works fine.

Thanks in advance.

After some more isolation, it crashes at this line (within sendATcommand):

while( GPRS.available() > 0) GPRS.read();    // Clean the input buffer

Perhaps that while loops forever. Add a timeout?

I don't think so - I've put an LED in to blink after the while loop and it blinks fine...

Solved!

Change the length of the response array down to 250.

I have no clue why this works - anyone have any ideas?

You were short of memory ? The item array was already using 300 bytes even before you squandered 500 more for the response array. What board are you using ?

Good ol’ Uno. The sketch size is 12000 bytes, but I guess at it runs the sketch things fill up?

Sketch is in 32k flash, but there's only 2k RAM...