0
\$\begingroup\$

According to here, a serial data frame looks like this:

9600 8N1 - 9600 baud, 8 data bits, no parity, and 1 stop bit

So it implies the total data bits are always a multiple of 8 bits.

What if I have only 15 bits to transfer?

Will the 2 data frames be like this?

Frame 1: 8-N-1

Frame 2: 7-N-1

But what if I want to add parity? The number of bits to calculate the parity are different...

\$\endgroup\$
4
  • \$\begingroup\$ You could hide a parity bit covering both frames in the eighth bit of frame 2. You'd have to check it in SW though. \$\endgroup\$
    – user16324
    Commented Feb 12, 2022 at 14:57
  • 1
    \$\begingroup\$ Serial data can be of whatever format you want. On the other hand UART based asynchronous serial data cannot be. \$\endgroup\$
    – Andy aka
    Commented Feb 12, 2022 at 15:06
  • \$\begingroup\$ @Andyaka That's refreshing. Though I don't fully get it yet. \$\endgroup\$ Commented Feb 13, 2022 at 2:48
  • \$\begingroup\$ if you have 15 you would probably send it as 8+8 and somehow know which bit to discard. if using a uart style protocol. you would probably want to wrap a packet around it and send multiple items. It would be very strange to find a uart that can switch on a character by character basis. (you would most likely need to burn three characters to send 16 bits and you go with 8N1 or 7E1, or others. \$\endgroup\$
    – old_timer
    Commented Feb 13, 2022 at 19:25

4 Answers 4

2
\$\begingroup\$

You will need to pad both frames so they have 8 bits of data plus the parity bit (if desired). You also need to figure out how the receiver will be able to tell which frame is supposed to be the first frame.

\$\endgroup\$
4
  • 1
    \$\begingroup\$ I guess the one who arrives first should be the first frame. After all it is serial communication and the frames are sent one by one. \$\endgroup\$ Commented Feb 12, 2022 at 14:57
  • \$\begingroup\$ And I guess all the devices that use serial communication should generate the data in a way that can be encoded as 8-N-1 in the first place... \$\endgroup\$ Commented Feb 12, 2022 at 14:58
  • 2
    \$\begingroup\$ @smwikipedia Will there be a reliable way for the receiver to tell "which one comes first" if it doesn't start receiving at the same time your transmitter starts transmitting, or if one of the frames is garbled in transmission? I guess the receiver will need to measure the time between receiving the frames. \$\endgroup\$ Commented Feb 12, 2022 at 15:22
  • \$\begingroup\$ Yes, adding stop bits for each frame can reduce the damage in the scenarios you mentioned. The damage will be limited to at most one frame. \$\endgroup\$ Commented Feb 13, 2022 at 2:36
1
\$\begingroup\$

Both ends have to have the same parameters. You normally would not change parameters during a session.

If you set the parameters to 8 N 1, then you'd send two frames.

Historically, you'd normally be sending ASCII characters which are 7 bits and parity. This was back in the day of Teletypes. Nowadays, 8-N-1 tends to be the default choice.

\$\endgroup\$
1
\$\begingroup\$

Yes, your serial line parameters can always be 8N1. There is little point in changing it during communications.

If you use 8N1 like most devices do, you are then free to send 8-bit bytes over the serial line, which usually makes most sense for binary data. If you want parity then choose one and the line parameters are 8P1 for all bytes, P being the selected parity scheme, such as odd or even.

Then you are free to choose any method you want to transmit 15 bits as two bytes over the serial link.

\$\endgroup\$
0
\$\begingroup\$

The link you have provided answers your questions: enter image description here

The data size can be from 5 to 9 bits but it has to be agreed before the start of the communication. It cannot be changed during: enter image description here

enter image description here

First the parity bit is not part of the calculation for the parity check. Also, the parity bit is not part of the chunk of data agreed to be transmitted, it is added to the string of bits, after the data, like in the picture: enter image description here

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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