Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
en:iot-open:embeddedcommunicationprotocols2:uart [2023/06/25 21:17] ktokarzen:iot-open:embeddedcommunicationprotocols2:uart [2024/05/27 11:26] (current) ktokarz
Line 1: Line 1:
-==== UART ====+====== UART ====== 
 +{{:en:iot-open:czapka_b.png?50| General audience classification icon }}{{:en:iot-open:czapka_e.png?50| General audience classification icon }}\\ 
 +UART name is an abbreviation of Universal Asynchronous Receiver Transmitter. It is one of the most often used communication methods, traditionally named serial interface or serial port. In contrast to previously presented interfaces, UART uses direct point-to-point communication.  
 +UART is the communication unit implemented in microcontrollers rather than the communication protocol. It sends the series of bits via the TxD pin and receives a stream of bits with the RxD pin (figure {{ref>uart1}}). It is important to remember that pin TxD from one device should be connected to pin RxD in another device. This is a general rule, but please always check the documentation for some non-standard markings. 
  
-UART name is an abbreviation of Universal Asynchronous Receiver Transmitter. It is one of the most often used communication methods, traditionally named serial interface or serial port. In opposite to previously presented interfaces, UART uses direct point-to-point communication.  +<figure uart1
-UART is the communication unit implemented in microcontrollers rather than the communication protocol. It sends the series of bits via TxD pin and receives a stream of bits with RxD pin. It is important to remember that pin TxD from one device should be connected to pin RxD in another device. This is a general rule but please always check the documentation for some non-standard markings.  +{{ en:iot-open:embeddedcommunicationprotocols2:uart_diagram.png?500 UART connection}} 
- +<caption>UART connection</caption>
-<figure label+
-{{ en:iot-open:embeddedcommunicationprotocols2:uart_diagram.png?nolink&450 |}} +
-<caption>UART connection.</caption>+
 </figure> </figure>
  
  
-To properly transmit data the speed of transmission, otherwise speaking the duration of bit, must be the same at the transmitter and receiver. Although the speed of transmission can be freely chosen, there are some standard, commonly used baudrates. They differ from 300 to 115200 bits per second. In modern microcontrollers, higher baudrates are also available like 230400, 250000, 500000, 1M 2M or 3Mbps. In UART data is sent in frames. The frame begins with the start bit of value “zero”. Next from five to eight data bits are sent. Next optional parity pit can appear. The frame is finished with the stop bit of value “one”. Stop bit can be prolonged to 1,5 or even 2 times the normal bit duration. After at least one stop bit, the next frame can be sent, of course, beginning with a start bit. +The transmission speed and bit duration must be the same at the transmitter and receiver to properly transmit data. Although the transmission speed can be freely chosen, some standard, commonly used baud rates exist. They differ from 300 to 115200 bits per second. Higher baud rates are also available in modern microcontrollers, like 230400, 250000, 500000, 1M2M or 3Mbps. In UARTdata is sent in frames. The frame begins with the start bit of value “zero”. Nextfrom five to eight data bits are transmitted. Next, an optional parity bit can appear. The frame is finished with the stop bit of value “one”. Stop bit can be prolonged to 1.5 or 2 times the standard bit duration. After at least one stop bit, the next frame can be sent, beginning with a start bit. 
-Start and stop bits are used to keep the synchronization between the receiver and transmitter.+Start and stop bits are used to synchronise the receiver and transmitter. Sample transmission flow is present in figure {{ref>uart2}}.
  
-<figure label+<figure uart2
-{{ en:iot-open:embeddedcommunicationprotocols2:uart_frame.png?nolink&450 |}} +{{ en:iot-open:embeddedcommunicationprotocols2:uart_frame.png?550 UART frame}} 
-<caption>UART connection.</caption>+<caption>UART frame</caption>
 </figure> </figure>
  
-UART, is a simplified version - universal asynchronous serial interface. The difference being that USART also uses a clock signal line to synchronize data, but UART only uses data lines. AVR's USART allows the use of full duplex communication5- to 9-bit data words (8-bit word = byte)1 or 2 stop bits, three parity modes and a wide variety of baud rates. AVR microcontrollers typically have up to 2 USART interfaces, although some may have no USART. Data transmission is performed one word at a time - AVR converts the word it gets from the user to bits on the hardware level and transmits it independently and vice versa. The user controls USART by reading and writing configuration, status and data registers. +UART, namely Serial Port, is used in many modern microcontrollers to upload the executable programdebug, and as the standard input/output for the user interfaceFor examplein Arduinofunctions that operate on the serial port are included in common set of built-in functions
- +<note> 
-Every configuration option has corresponding registers, which are quite easy to configure using the datasheet. The baud rate, though, is a bit more difficult to set. The clock signal for data transmission is generated from the controller's own clock, and the user can specify a number from 1 to 4096, by which the controller's clock cycle is dividedThe result is additionally divided by 28 or 16depending on the mode. The problem is, not all clock frequencies can be divided so that the result is a standard baud rate. With some frequencies, the baud rate can differ from the standard by up to 10%. AVR datasheets contain tables with typical clock frequencies, baud rates, the needed multiplier to reach that baud rate and the possible calculation error. +Many modern PC computers (except industrial ones) do not have serial port exposedso USB to serial converters must be usedSome development boards have USB-serial converter on board (e.gArduino UnoNodeMCUSTM Nucleoetc.) 
- +</note
-Since data transmission takes place independently of the processor and much slower, it is necessary to confirm that the interface is ready for the next word before transmitting. This can be done by keeping an eye on the transmit buffer's ready bit, which signifies if the buffer is ready to accept new word or not. The controller starts with the ready bit enabled. As soon as a word is transmitted and the buffer is empty, the ready bit is set high+<note
- +Even if a PC computer has a serial portit is usually compatible with the RS-232 standardIt uses the same frame structure but different voltage levels (with opposite zero-one encodingknown as reverse logic)
-The arrival of word is signified also by a special status bit. In addition to thatthere are status bits to signify framing errors, parity errors and receive buffer overflowsBuffer overflow can occur when the last word is yet to be read from the buffer while new one arrives this is why it is always important to read the incoming words to the program as soon as possible, for example, by using an interruptThere are three possible interrupt reasons: transmit buffer ready, transmit successful and receive successful. +</note>
- +
-The transmit and receive buffers are physically separate registersbut share the same memory address and name. When writing to the shared registerthe data is stored in the transmit bufferand when reading from it, the data is read from the receive bufferWhen using 9-bit words, the 9th bit is transmitted and read using one of the configuration registers. +
- +
-<pagebreak> +
- +
-<box 100% round #EEEEEE|Example+
- +
-Task: Configure an 8 MHz ATmega128's USART0 interface to transmit 8-bit words asynchronously using 9600 bps baud rate1 stop bit and no parity bits. Send the symbol "X"+
- +
-<code c> +
-#include <avr/io.h> +
- +
-int main() +
-+
- // Set baud rate to 9600 bps. Formula: +
- //   multiplier = clock frequency / 16 / baud rate +
- //   UBRR = 8000000 / 16 / 9600 - 1 = ~51 +
- UBRR0H = 0; +
- UBRR0L = 51; +
- +
- // Allow transmitting +
- UCSR0B = (1 << TXEN0); +
- +
- // Configure asynchronous mode, set the word size to 8 bits +
- // 1 stop bit, no parity bits. +
- UCSR0C = (1 << UCSZ01) | (1 << UCSZ00); +
- +
- // Wait for the data buffer to empty (previous word to transmit) +
- // In this example there is no need to wait, as the first symbol is yet +
-        // to be sent, but it should be done when transmitting more symbols+
- while (!(UCSR0A & (1 << UDRE))) continue;+
  
- // Write the symbol to the buffer for transmitting 
- UDR0 = 'X'; 
-  
- // Endless loop 
- while (1) continue; 
-} 
-</code> 
  
-</box> 
en/iot-open/embeddedcommunicationprotocols2/uart.1687727866.txt.gz · Last modified: 2023/06/25 18:17 (external edit)
CC Attribution-Share Alike 4.0 International
www.chimeric.de Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0