1

I have to reproduce a signal (of 6 UART frames) which have 950 µs delay between each of the frames. Than, a delay of 37ms at the end of those frames.

Everything going right except the delay between each frame...The baud rate is at 9600.

Here is my current code :

  Serial1.write(sw_binary_train_1);
  delayMicroseconds(950);
  Serial1.write(sw_binary_train_2);
  delayMicroseconds(950);
  Serial1.write(sw_binary_train_3);
  delayMicroseconds(950);
  Serial1.write(sw_binary_train_4);
  delayMicroseconds(950);
  Serial1.write(sw_binary_train_5);
  delayMicroseconds(950);
  Serial1.write(sw_binary_train_6);
  delay(37);
  • 2
    Is "Serial1" a software-serial? Potentially the timing may be more accurate using hardware serial. Also you may check if making the delay longer or shorter works. Usually, the receiving end would have some kind of 'deadzone' (that it should be between 900-950uS) and with the value of 950uS you may just overshoot that at some moments). Also, you should try to put "Serial1.flush();" to make sure that all bytes are sent (and not only placed in the queue). – Paul Feb 26 at 14:09
  • No, I'm on the Arduino Micro. Ok shoud I use delay(1) instead of delayMicroseconds(950) ? Between each frames or at the end of all frames ? – Martin.G Feb 26 at 14:11
  • After few more tests, for a delay of 950µs i have to set delayMicroseconds(1900)...A bit strange but it works ;) ! – Martin.G Feb 26 at 20:24
0

set delayMicroseconds(1900) do a delay of 950µs between each frames...Strange but works !

  • Good to hear you've found a solution, potentially you still may want to look at serial.flush(); (and then delay). But if the other option works for you, it may just be OK. – Paul Feb 27 at 0:05
  • The delayMicroseconds() is actually not between frames. It is more of less the time for the frame plus the 950 us extra space. The extra 1000 us is the time of the USART ISR to push the character into the output hardware buffer plus the time for the 1+8+1 bits, which happens to be approx. 1 ms @ 9600 bps. The Serial.write() is not synchronous for a hardware USART. – Mikael Patel Mar 29 at 0:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.