Arduino Serial Communication does not receive the entire message

I have a problem with an Arduino post. It is quite difficult to describe, so I can not fit in the title. Anyway, here's what:

So, I have this code for my receiving end:

if(Serial1.available())
{
    while(Serial1.available())
    {
        uint8_t inByte = Serial1.read();

        inByte = inByte ^ k;

        Serial.write(inByte); 
    }

    Serial.println(" done");
}

It should print on one line and print when it is done. The Serial1.available()following seems to be missing Serial1.available(), I don't know what is going on. Anyway, here is my current, bad conclusion:

h done
e done
l done
l done
o done

done

when it should be:

hello done

I'm sorry if this could have been better formulated, but all I can print now, my brain is a little sick. I have never experienced this behavior in a Windows C ++ console application.

+2
1

(), , , , , .

- char, , , , .

: Arduino , Arduino IDE: : : :

, Serial Arduino. .

, , , , . , char, :

 while(Serial1.available()){
   char c = Serial1.read();

   if (c == '*'){
       Serial.println(" done");
   } else {
       Serial.write(c); 
   } 
 }
+4

Source: https://habr.com/ru/post/1536880/


All Articles