Serial.write();

I have a communication with two arduinos. The first send a to the second.

First:

char Letter = 'D';
int crc_resto = 1011;
int crc = B1001000;

Serial.write(Letter);
Serial.write(crc_resto);
Serial.write(crc);

Second

char m0;
int m1;
int m2;

while(Serial.available() > 0){
m0 = Serial.read();
m1= Serial.read();
m2 = Serial.read();
}

I want that: m0 receive D, m1 receive crc_resto, m2 receive crc, but this doesn't happen. What's wrong?

So, what does happen?

Note that serial read only reads one byte and that write only writes a single byte (in these cases).

In future, please use code tags when posting code; it's also preferred that you post complete code and not snippets.

OK, really basic stuff...

Your receiver checks if there is at least one character in the serial buffer. Then it reads three. How well do you think that is going to work? Remember serial is very very slow compared to the Arduino. You can do a thousand things while you are waiting for the next serial character to arrive.

Then (it appears to) only does it once. What if you didn't start the transmitter at exactly the right time? Getting the two to synchronise is impossible with that scheme.

Read Serial Input Basics

Ok, so, I have to put a delay() below the Serial.read()?

Or, I have to put a Serial.read() in others lines?

Read Robin's thread. It may seem unnecessarily complex, but that is actually the simplest way to do it. There are no reliable shortcuts for proper reception of serial.

Robin2's thread was updated; the below one is a lot shorter and possibly easier to dig through

Serial Input Basics - Updated