0

I have used AT commands to read incoming bytes from serial buffer from SIM900A but I cannot get the complete message using the code below:

while(ss.available()>0)
{
 inChar=ss.read();
 inString+=inChar;
}

Serial.println("Received messaged: ");
Serial.println(inString);

inString="";

However this one below works:

if(ss.available()>0)
{
  inString=ss.readString();
}

Serial.println("Received messaged: ");
Serial.println(inString);

inString="";

I wonder what is the difference?

0

The data arrive over serial very slow compared to MCU speed. In the first snippet you stop reading at first gap between bytes (available is 0). In the second snippet the function readString will wait for the next byte until a second (at default).

  • I misread the question, sorry. Message deleted. – sa_leinad May 29 at 14:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.