meta data for this page
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
com:basic_uart [2024/05/31 21:11] – vamsan | com:basic_uart [2025/02/11 20:21] (current) – vamsan | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== lamaPLC Communication: | + | ====== lamaPLC Communication: |
+ | ===== USART ===== | ||
+ | A **USART** (// | ||
+ | |||
+ | ===== USART vs. UART ===== | ||
+ | A UART device can use asynchronous communication protocols. A USART device can use both asynchronous and synchronous communication protocols. Therefore, a USART can do anything a UART can do and more. Because a USART requires more complex circuitry and more communication lines to fully implement, many devices may only implement a UART to save on cost, complexity or power usage. | ||
+ | |||
+ | ===== Asynchronous and synchronous serial communication ===== | ||
+ | In serial communication, | ||
+ | |||
+ | ===== Asynchronous serial data ===== | ||
+ | In asynchronous mode, only one data line is used to send data from the transmitter to the receiver. There is no shared synchronization signal from the sender to the receiver. So, the receiver has no way to know how fast or slow the data is coming. To circumvent this, both the sender and receiver must be manually configured beforehand to use the same data rate. A common shared baud rate is 9,600 bits per second. | ||
+ | |||
+ | ===== UART ===== | ||
A //universal asynchronous receiver-transmitter// | A //universal asynchronous receiver-transmitter// | ||
+ | |||
+ | The universal asynchronous receiver-transmitter (UART) takes bytes of data and transmits the individual bits in a sequential fashion. At the destination, | ||
+ | |||
+ | The UART usually does not directly generate or receive the external signals used between different items of equipment. Separate interface devices are used to convert the logic level signals of the UART to and from the external signaling levels, which may be standardized voltage levels, current levels, or other signals. | ||
+ | |||
+ | // | ||
+ | |||
+ | * simplex (in one direction only, with no provision for the receiving device to send information back to the transmitting device) | ||
+ | * full duplex (both devices send and receive at the same time) | ||
+ | * half duplex (devices take turns transmitting and receiving) | ||
+ | |||
+ | For UART to work the following settings need to be the same on both the transmitting and receiving side: | ||
+ | |||
+ | * Voltage level | ||
+ | * Baud Rate | ||
+ | * Parity bit | ||
+ | * Data bits size | ||
+ | * Stop bits size | ||
+ | * Flow Control | ||
+ | |||
+ | For the voltage level, 2 UART modules work well when they both have the same voltage level, e.g 3V-3V between the 2 UART modules. To use 2 UART modules at different voltage levels, a level switch circuit needs to be added externally | ||
+ | |||
+ | |||
+ | ===== Data framing ===== | ||
+ | A UART frame consists of 5 elements: | ||
+ | |||
+ | * Idle (logic high (1)) | ||
+ | * Start bit (logic low (0)) | ||
+ | * Data bits | ||
+ | * Parity bit | ||
+ | * Stop (logic high (1)) | ||
+ | |||
+ | ^UART frame, field length in Bits|||| | ||
+ | ^1^5-9^0-1^1-2| | ||
+ | |Start Bit|Data Frame|Parity Bits|Stop Bits| | ||
+ | |||
+ | In the most common settings of 8 data bits, no parity and 1 stop bit (aka 8N1), the protocol efficiency is 80%. For comparison, Ethernet' | ||
+ | |||
+ | The idle, no data state is high-voltage, | ||
+ | |||
+ | Each character is framed as a logic low start bit, data bits, possibly a parity bit and one or more stop bits. In most applications the least significant data bit (the one on the left in this diagram) is transmitted first, but there are exceptions (such as the IBM 2741 printing terminal). | ||
+ | |||
+ | {{ : | ||
+ | |||
+ | The most typical UART, the 8N1, has the following structure: | ||
+ | |||
+ | {{ : | ||
+ | |||
+ | Telegram of the letter " | ||
+ | |||
+ | {{ : | ||
+ | === Start bit === | ||
+ | The start bit signals to the receiver that a new character is coming. | ||
+ | === Data bit === | ||
+ | The next five to nine bits, depending on the code set employed, represent the character. | ||
+ | === Parity bit === | ||
+ | If a parity bit is used, it would be placed after all of the data bits. \\ | ||
+ | The parity bit is a way for the receiving UART to tell if any data has changed during transmission. | ||
+ | === Stop bit === | ||
+ | The next one or two bits are always in the mark (logic high, i.e., ' | ||
+ | |||
+ | ===== UART (serial) with Arduino ===== | ||
+ | UART (serial) transmission is perhaps the most commonly used communication method by Arduino, along with [[com: | ||
+ | |||
+ | ==== Serial Class ==== | ||
+ | |||
+ | With the Serial class, you can send / receive data to and from your computer over USB, or to a device connected via the Arduino' | ||
+ | |||
+ | When sending data over [[com: | ||
+ | When sending data over RX/TX pins, we use Serial1. \\ | ||
+ | The GIGA R1 WiFi, Mega 2560 and Due boards also have Serial2 and Serial3 \\ | ||
+ | The Serial class have several methods with some of the essentials being: \\ | ||
+ | |||
+ | * begin() - begins serial communication, | ||
+ | * print() - prints the content to the Serial Monitor. | ||
+ | * println() - prints the content to the Serial Monitor, and adds a new line. | ||
+ | * available() - checks if serial data is available (if you send a command from the Serial Monitor). | ||
+ | * read() - reads data from the serial port. | ||
+ | * write() - writes data to the serial port. | ||
+ | |||
+ | For example, to initialize serial communication on both serial ports, we would write it as: \\ | ||
+ | < | ||
+ | Serial.begin(9600); | ||
+ | Serial1.begin(9600); | ||
+ | </ | ||
+ | ===== Sources ===== | ||
+ | Wikipedia ([[https:// | ||
+ | |||
+ | ===== UART topics on lamaPLC ===== | ||
+ | {{topic> | ||
+ | |||
+ | \\ | ||
+ | {{tag> | ||
+ | \\ | ||
+ | This page has been accessed for: Today: {{counter|today}}, |