rs485 and analogRead problem.

hi to all,
i am using Gammon’s rs485 protocol for a simple project that i read an analog input from an joystick and send this value to another arduino via rs485. but there is a very interesting problem. Every time sendMsg function called, analogRead function gets interrupted. my serial monitor output is like;

179
179
179
179
179
1 -----> this is where sendMsg is called
179
179
179
179
179
179

when i comment sendMsg, code is working perfectly. Also when i uncomment the function data is sent perfectly too. i cant understand why they dont work at the same time.

void loop()
{

int t5 = analogRead(A7);



  t5 = map(t5,0,1023,10,160);

 if(t5<=100 && t5>= 86)

  t5= 100;

  if(t5>=60&&t5<=78)

  t5=60;

Serial.println(t5);

motor.write(t5);

byte snd = (byte) t5;

  byte msg [] = { 
     snd
  };
sendMsg (fWrite, msg, sizeof msg);
}

Welcome to the forum. The output you show is from the receiving side and the posted code is from the transmitter?

Please post all of the code, per forum guidelines (transmit and receive).

Since you didn’t post all of your code, I can only guess so:

Call Serial.flush(); after your Serial.print();

lg, couka