Delay between UART TX & RX

I have two arduino boards communicate together using softwareserial library
could you please guide me what should set delay between send command & check rx buffer?

That depends on the bit rate (baud) and the amount of space inserted between characters via the stop bit(s) and any additional added by the software. That then tells you it is also dependent on how many bytes are sent. The Arduino uses an interrupt buffer to send data via the serial interface so it can still be sending while you are executing code. Your receiver processing time enters into the equation as well.

baud rate is 2400 string length include spaces 114 characters

There is no need for waiting because you can test to see how many bytes have been received into the buffer. Keep testing until you have the number you want and then go process them.

1 Like

what Arduino modules are you using?
how are they connected, e.g. what pins are used?
post the code (using code tags </>)

I want to know how to calculate time for sending 114 characters using 2400 baud rate

2400baud is approximatly 240bytes/second (assuming 10bits - a byte + start and stop bits)
give approximatly half a second to transmit 114characters

let me explain more what I want to do
first arduino send command as data0
then need to wait 114 characters from second arduino
then first arduino send command data1
then need to wait 114 characters from second arduino
then first arduino send command data2
then need to wait 114 characters from second arduino

I think need to add delay between sending data0 and receiving

as @Paul_KD7HB states in post 4 there no need to use delay() - use Serial.available() to wait until 114 characters are received then read and process them
something along the lines of

Serial1.write(command);
while(Serial1.available() < 114) delay(1);
char text[150];
Serial1.readBytes(text, 114);

1 Like

I do not want to use while routine because code stop waiting a response

if you need to be doing other things while waiting for the 114 characters try something along the lines of

void loop() {
  static int commandSent = 0;
  if (!commandSent) {
    // get next command
    Serial1.write(command);
    commandSent = 1;
  }
  if (commandSent && Serial1.available() >= 114) {
    // process response
    commandSent=0;
    char text[150];
    Serial1.readBytes(text, 114);
    // process text
  }
  // do other things
}

this allows you to do other processing while waiting for the 114 characters to be received

2 Likes

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.