## How is a binary value of "0" transmitted in serial communication?

16 posts / 0 new
Author
Message

I'm going to use a simple LED circuit to demonstrate this (I know it's not a good example but I need to keep this simple).

I'm also going to use USART, and more specifically the Tx pin for this example.

We have two computers A and B. B is going to send two binary values of "1" and "0" to computer A:

- Ground is the "-" side of power shared by both computers.

- To send a "1" we just send 1.5 volts from power (battery voltage).

- To send a "0" we connect both ends to ground (the - side of power). We can't just disconnect the the lines as the receiving value will float and will not be a static 0V.

- The sender and receiver work on a fixed (pre-agreed upon) clock rate. The receiver will interpret the data (0 or 1) as it reads them per (agreed upon) clock.

Is my understanding of this correct?

This topic has a solution.
Last Edited: Sun. Jan 16, 2022 - 10:56 PM

CMOS logic of all kinds (gates to microprocessors) have outputs that look like this:

There are two transistors. Each functions like a switch. One has the function of S0 in the schematic, above. The other is like S1. One or the other can be closed; never both closed. This is the same for all outputs, whether UART or a PWM output or what-ever. To be fully correct, there is an output style that has no S1 but which has, instead, a resistor where S1 would be, either inside the IC or externally.  We won't talk about inputs which does other things with these switches.

EDIT: Though it should be obvious, a "1" is generated when S1 is closed and S0 is open. A "0" is generated when S0 is closed and S1 is open. !EDIT

You only need to know that this is what a general logic output looks like.

Jim

Until Black Lives Matter, we do not have "All Lives Matter"!

Last Edited: Sat. Jan 15, 2022 - 07:12 PM

@ka7ehk

Thank you for the information. So my understanding is correct. More specifically to send a 0 you connect both ends to ground.

Correct. There needs to be a common ground connection between the two devices.

Jim

Until Black Lives Matter, we do not have "All Lives Matter"!

@Jim

Could I confirm one more detail regarding UART?

This manual has this line:

Data bits:

This parameter defines the number of data bits transmitted between start and stop of a single UART transaction. Options are 5, 6, 7, 8 (default), or 9.

But `a single UART transaction` doesn't happen in 1 clock cycle of course? If we use say a byte (8 bits) we need 8 clocks to send the entire buffer over correct?

Typically a UART will output a "mark" condition when it is idle (usually a logic '1'), When it is ready to output data it will send a "space" condition (usually a logical '0') followed by the data bits. Once the data has been sent, the UART will output a "mark" (stop bit(s)) signifying  the end of that block of data. The output will remain at the "mark" level until ready to send another set of data bits.

Both the transmitter and receiver must use an agreed upon timing for the spacing of individual bits. In addition, the UART may transmit a parity bit (either even or odd) along with the data bits.

A UART transmission configured as 8N1, indicates transmission of 8 data bits, No parity and 1 stop bit. This would require a minimum of 10 bits of information to be transmitted for each 8-bit data (1 start bit, 8 data bits, and 1 stop bit).

Edit: I say "minimum of 10 bits" since if no data is immediately available, the UART will still be sending the "mark" for all bit times until new data is available for transmission.

David

Last Edited: Sat. Jan 15, 2022 - 08:42 PM

frog_jr wrote:
This would require a minimum of 10 bits of information to be transmitted

So sending over 1 byte (a single UART transaction in this case) needs 10 clock cycles. Essentially we need a busy loop to check for  empty transmit buffer before sending the next byte (or maybe use an interrupt).

avruser1523 wrote:
Essentially we need a busy loop to check for  empty transmit buffer before sending the next byte (or maybe use an interrupt).

Depending on the system requirements, yes...

Sometimes you can send data, go back to other processes that need to be accomplished and then (either by polling or interrupt) send the next data to be transferred.

David

This reply has been marked as the solution.

There may be some or a lot of confusion, here.

UART has its own clock. Almost aways, the UART clock is obtained from the MCU clock by dividing the MCU clock frequency by some integer. For some devices, such as Mega328 and most other "classic AVRs", the clock divider has a limited set of possible division values. For newer ones (such as Mega4809), there are many more possible divisions.

So, here is how the UART works. When you write to the UART data register, it starts by generating a start bit. That logic level lasts one UART CLOCK interval. Then, a number of data bits are sent, each one lasts for one UART CLOCK interval. These data bits can be followed by a parity bit, if you choose; it also lasts one UART CLOCK interval. Finally, there are one or more stop bits; again, each one lasts one UART CLOCK interval. The frequency of the UART CLOCK, when described this way, is called the "baud rate". A common baud rate is 9600 baud; at this rate, each bit lasts for about 104 microseconds.

Using configuration registers for the USART (the more correct name in an AVR), you can set the baud rate divider value, whether 7 or 8 bits of data are sent, whether a parity bit is sent (and which kind), and how many stop bits are sent. The number of clock cycles used to send one character of data depends on these settings.

Jim

Until Black Lives Matter, we do not have "All Lives Matter"!

Last Edited: Sat. Jan 15, 2022 - 09:43 PM

@Jim

Thank you so much for the details. This is actually pretty much how I had pictured it in mind. Could I ask which part of my conversation sounded misleading? Oh maybe i didn't clarify UART clock is separate from the actual CPU clock and its configurable and must match in both participating machines, it's usually much slower than CPU clock.

Last Edited: Sat. Jan 15, 2022 - 09:49 PM

Yes, the text confusion was about the lack of distinction between MCU clock and UART clock.

Note that I wrote nothing about bit order or what happens during the time between characters. Nor did I write anything about the difference between characters and number values.

Jim

Until Black Lives Matter, we do not have "All Lives Matter"!

Once again this thread suggests you may be "over thinking" things. In computers 1 is Vcc level, 0 is Gnd. If you want to send an 'A' that has binary pattern 0x41 = 0b01000001 the in the first period you send 0 (gnd) then in the next you send 1 (Vcc), then the next five periods are '0' (so Gnd) and I the last period you send 1 (Vcc)

(except that usually you sent the bits in the other order)

The "period" is just some agreed time when the other end will be looking at the line to see if it is at Gnd or Vcc level.

To add to this, the receiving UART signal is "typically" sampled at a higher frequency than the actual bit frequency (baud).

For example, the receiver may sample the incoming data at 16 times the baud rate. When it first detects the presence of the start bit (space, '0') it will sample the input 8 clocks later (1/2 bit time) and then sample every 16 clocks thereafter. This is so that it can attempt to sample each bit in the middle of the bit time. Some UARTs will take multiple samples near the middle of the bit period and utilize a "voting" scheme to determine whether the bit should be interpreted as '0' or '1'.

Attempting to get a transmit and receive UART to actually clock data at the actual baud rate (1 clock per bit) is not practical unless they are operating as a synchronous system sharing the same bit clock.

David

How is a binary value of "0" transmitted

..... More specifically to send a 0 you connect both ends to ground.

Rather strange question....you imply you believe there is only one way to do so (comparing ways to communicate a value of zero)?

We could define 0 to be represented by any voltage from 6.73 to 8.44 Volts ...get that, you just got a zero, get something else, it is not a zero.

We could send the message apple for zero and hotdog for one.  Pick the best match upon reception...even with some dropped characters, the chance of a mistake is lowered.

As mentioned, to send serially, you will typically divide that into 2 method types: synchronous (separate clock signal), or asynchronous  methods.

You can think of several way to indicate sending one or the other & you should do so!

When in the dark remember-the future looks brighter than ever.   I look forward to being able to predict the future!

Thanks again for all the help.

Standard RS232 (serial data) used a voltage around +12V for one logic level and around -12V for the other.  In a turn-about, +12V represented LOGIC ZERO.

Also consider the original Motorola ECL (emitter coupled logic). The low voltage level was logic zero. But, often times, the gates were connected between ground and -5.2V. The logic swing was around a volt, as I recall, and logic high "1" was about -0.7V, making "0" at -1.7V  or so.

Jim

Until Black Lives Matter, we do not have "All Lives Matter"!