Shop OBEX P1 Docs P2 Docs Learn Events
Baudrate - Can someone check my math please.. — Parallax Forums

Baudrate - Can someone check my math please..

pacmanpacman Posts: 327
edited 2010-08-08 22:45 in General Discussion
Ok,

I'm writing a modbus (slave) implementation and I need to figure out the 3.5 character spacing at the end of an RTU frame.

Now, I _think_ I've got the right maths, but can someone please check my thinking before I madly code...

9600 baud = 1 bit in 1/9600 of a second.

A character (7,E,2) is 11 bits long.

Thus a 3.5 character 'frame end' space is 3.5 * 11 * 1/9600 of a second.

Which would be just a shade over 4mS.

Am I correct?

Comments

  • kwinnkwinn Posts: 8,697
    edited 2010-08-08 08:41
    7,E,2 would be 7 data bits, one parity bit (even) and 2 stop bits. With one start bit that comes to 11 bits. At 9600 bps each character would take 1.14583333...etc milliseconds.
  • pacmanpacman Posts: 327
    edited 2010-08-08 22:17
    Thanks Kwinn. means my 'maffs' is right.

    Modbus RTU uses a 3.5 character space of no transmission to signify the end of a message/start of the next message.

    So if I get no data for 3.5 * 1.14583333...etc milliseconds, then the message is over and I should actually process it.

    Thanks again for the sanity check.....
  • kwinnkwinn Posts: 8,697
    edited 2010-08-08 22:45
    Yes, and you can use something like "char := uarts.rxtime (0, 4)" to see if the time between characters is 3.5 character times (4.01042mS at 9600 baud) if you are using "pcFullDuplexSerial4FC" (the 4 port version of "FullDuplexSerial") for communications.

    FullDuplexSerial has a similar function with a slight difference in the parameters.

    The call returns the next character or -1 if it timed out.

    Oops....uarts.rxtime function accepts only integer mS values for timeout. I've got to stop posting answers so late. Make too many silly mistakes.
Sign In or Register to comment.