what does -1 mean when receing after reading data Serial.read()

I am playing with serial port but it seems to have the data synchronized is difficult.

when receiving data I get on occasion -1 instead of the transmitted data.

is this some transmission error ?

I have STM32 nucleo sending data to arduino mega. sometimes last 10 numbers would be received as first 10 when transmiting like 100 numbers at once.

The -1 means there is no data to be read. If there is data, the return is the number of bytes in the buffer and may be read by your code.

Paul

RTFM early, RTFM often

ED201:
I am playing with serial port but it seems to have the data synchronized is difficult.

when receiving data I get on occasion -1 instead of the transmitted data.

is this some transmission error ?

I have STM32 nucleo sending data to arduino mega. sometimes last 10 numbers would be received as first 10 when transmiting like 100 numbers at once.

As has been pointed out, the answer is in the online documentation which is really very easy to find if you know how to use a Google search. A Google search on;

Arduino Seria.read()

points to the answer, and its much quicker to use Google than type a message in the forums.

To go direct to the appropriate reference use a slightly longer Google search term;

Arduino Seria.read() reference

Paul_KD7HB:
The -1 means there is no data to be read. If there is data, the return is the number of bytes in the buffer and may be read by your code.

Paul

read() without parameters returns a byte of data or -1 if no data is available. read() into buffer returns the count of bytes put into buffer, 0 if no data was available and some implementations return a negative value on error