Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

11
  • There's no reason why the serial port speed can't be increased. I'm always using 115200 as baud rate, and never had any problems. Commented Oct 20, 2022 at 9:26
  • 2
    @PMF: The OP has a very good reason to not increase the serial port speed: he wants to simulate an industrial device that speaks at 9600 b/s. Commented Oct 20, 2022 at 9:36
  • 1
    @MarkMorganLloyd: The output buffer of the chip in question is one byte deep. Two bytes if you count the shift register holding the remaining bits of the byte being transmitted. And yet, the code I posted has no issues reliably sending the whole message: Serial.write() is smarter than you think. There is no risk of overrun as long as the input pulses are spaced more than 93.6 ms apart, and they only come every 300 ms. Commented Oct 20, 2022 at 12:48
  • 1
    @MarkMorganLloyd: My point is, even with this 64-byte internal buffer, Serial.write() reliably sends a 90-byte string if asked to. Commented Oct 20, 2022 at 18:02
  • 1
    @MarkMorganLloyd: Re “Not in all cases in my experience”: If Serial.write() does not send reliably 90 bytes when asked to, you have a bug in your code. Probably one that is corrupting memory. Re “if the ISR is still clearing the buffer..”: In this case, a new message is due while the previous one has not been sent completely. Of course there will be extra jitter! There is no way around this. Fortunately for the OP, the messages take 93.6 ms to send and are sent every 300 ms. Commented Oct 20, 2022 at 18:44