Serial.read should read one byte but reads multiple on nano ?

Hello
I have following struct :

struct	type_msgRS485{
	char 		fromAdr;	//1 byte
	char 		toAdr;
	char		cdeC;
	int		cdeN;		//2 byte
	long		param;		//4 byte
	byte 		msgId;
	uint16_t	crc;		//2 byte
};

I try to send it from a mega to a nano (The other direction works perfectly...)

So I use

Serial.write(HEAD);
Serial.write(_msg->fromAdr);
Serial.write(_msg->toAdr);
Serial.write(_msg->cdeC);
Serial.write((byte)(_msg->cdeN>>8));
Serial.write((byte)(_msg->cdeN));
Serial.write((byte)(_msg->param>>24));
Serial.write((byte)(_msg->param>>16));
Serial.write((byte)(_msg->param>>8));
Serial.write((byte)(_msg->param));
Serial.write(_msg->msgId);
Serial.write((byte)(_msg->crc>>8));
Serial.write((byte)(_msg->crc));
Serial.write(TAIL);
Serial.println();
Serial.flush();

As you can see there are 14 bytes + nl.
Out of the 14, 5 are because of conversion (such as long, int) to bytes

What the nano sees is only 6 or 7 (randomly depending of I don't know) incoming bytes from Serial.read();

why is that ?

On the opposite : when I send with the same code from the nano to the mega, I have no problem.

Any Idea ?

Do you need the newline termination? Some of the bytes in the data struct may be equal to the newline characters used for termination and this may cause problems. Try this approach:

void sendMessage(byte* msg, byte cc)
{
  for (byte i = 0; i < cc; i++) Serial.write(msg[i]);
  Serial.flush();
}

bool receiveMessage(byte* msg, byte cc)
{
  byte i = 0;
  while (Serial.available() && (i < cc)) msg[i++] = Serial.read();
  return (i == cc);
}

type_msgRS485 theMessage;

sendMessage(&theMessage, sizeof(theMessage));

if (receiveMessage(&theMessage, sizeof(theMessage))
{
  //Yay!
}

Is that receiving Nano (of which you did not post code) running SoftSerial by any change?

@ septillion : Yes you got it :

as you know there is only one serial port on nano and I said that I was observing the results. I am observing via softserial @ 9600bauds agains serial @115200.
I tried to downsize 115200 to 57600 : I now see about 10 bytes coming.
So I guess that the missing bytes comes from occupied processor
So I upgrade to 57600 both SoftSerial and Serial :
Seems no problem anymore

But do you have any explaination ?

But do you have any explaination ?

Yes. There is something wrong with the code you still haven't posted.

Indeed. And because it's all software serial, even keeping the processor waiting a little to long makes it easy to miss crap.

You may want to switch to the hardware serial. Little bit tricky on a Nano because the USB part but it can be done. Easier on a Pro Mini.

I can't change hardware : I must use a nano. I also must have dual com. So I need softSerial. I confirm that upgrading to 115200 on both solved the pb.
Anyway thanks for your help.
I close the subject

closed

Point of note.

SoftwareSerial, despite claims, only works reliably up to 56,200.

This is the same with any bit-banged soft uart, unless you re-sync after every byte.