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.