Best approach for Master Timer

I am working on a protocol for a master/slave serial communication over RS-485

when the master sends a message it then waits for the answer,

I want the master after a certain time to realize there is no message coming back and then resend a message.

would the best approach be using an interrupt or using a ((millis(); - time) < 1000) type of deal?

or any other suggestions?

I don't see the need for an interrupt - millis will do the job perfectly well

It depends on how many clock cycles you have to spare. If you can allow to do an active wait it could look like

  do
  {
    RS485send();
    for (int i=0; i< 100 && RS485Available() == 0, i++) delay(10);
  } while (RS485Available() == 0);
}

If the master must do other things you best make a state-machine, something like below

0 = nothingToSend
1 = wantToSend
2 = isSend

transitions meaning
0 → 1 // buffer is filled
1 → 2 // buffer is send
2 → 0 // answer received
2 → 1 // answer not received

void loop()
{
  if (state == 0 && ....)
  {
    fillBuffer();
    state = 1;
  }
  ...
  switch(state)
  {
    case 0: // do nothing;
      break;
    case 1:
      sendBuffer();
      sendTime = millis();
      state = 2;
      break;
    case 2: 
      if (RS485Available() > 0)
      { 
        state = 0;
        break;
      } 
      if (millis() - sendTime > TIMEOUT)
      {
        state = 1;  // effectively resend
        break;
      }
  }
}
}

Get the idea?

thanks for the ideas, i figured out what my issue is

void recieveMSG() {
   
    
    charArray[1] = 0;
    digitalWrite(dirPin, LOW);
   
    
   
    
    while(Serial.available() == 0);
    int start_byte = Serial.read();
	if (start_byte == 0x10) //start convo
                    {
                      while(Serial.available() == 0);
                          int Address_byte = Serial.read();
                              if (Address_byte == address)//address check
                                      {            
		                        for (int i = 0; i < 2; i++) {       
			                while (Serial.available() == 0); // wait for next character
			                charArray[i] = Serial.read();    // load char into array
		                        }
                              
                      
		//checksum
		if ((start_byte + Address_byte + charArray[0]) == charArray[1]) {
			 digitalWrite(5,HIGH);
                         delay(10);
                         digitalWrite(5,LOW);
                          rec_flag=1;
                          //Serial.println(charArray[1], HEX);	
		}
                else
                      {
                         digitalWrite(7,HIGH);
                         delay(10);
                         digitalWrite(7,LOW);
                         rec_flag=0;
                      }
        }
   
  }
  	
 }

in the receive function
I have while(Serial.available() == 0);

this is then canceling what ever i have outside of this function for a time limit, almost seems i would have to put a timer on each wait?

Or would this be ideal for interrupt?

With the state machine you can check the state in every iteration of loop(). There is no need to do delay() or active waitings.

If there is no trigger to change state the state stays the same and you continue with the rest of the sketch (which can be nothing). And the next iteration you just start over again. So the sketch will not block on self introduced delay’s.

Waiting for a string is also not needed as you make a statemachine for that too.
0 = idle
1 = receiving
2 = string complete

0 → 1 // start receiving.
1 → 1 // char received != end of message
1 → 2 // char received == end of message.
2 → 0 // received string processed.

succes
Rob

Perfect, thanks for the help i shall give it a shot.