UART and Interfacing with Arduino
Introduction to UART
- Definition: UART stands for Universal Asynchronous Receiver-Transmitter.
- Purpose: Used for serial communication.
- Transmission Protocol:
- It is a two-wire transmission protocol:
- One wire for transmission
- One wire for reception.
- Data Format: Configurable data format and transmission speed.
- Synchronization: No clock signal is provided for synchronization.
- Speed Comparison: Slower than parallel communication but requires fewer bus interfaces.
Configuration of UART Before Transmission
- Both communicating devices must have the same transmission speed (Baud Rate).
- Settings:
- Fix the data length between 5 to 9 bits.
- Requires a start bit (1 bit) and a stop bit (1 or 2 bits).
- Encoding: Uses Non-Return to Zero (NRZ) encoding for data communication.
- Common Baud Rates: Examples include 9600, 115200.
UART Data Transmission Structure
- Data Format:
- A typical data structure:
- Start Bit: 1 bit
- Data Bits: D1 to D7 (5 to 9 bits)
- Parity Bit (optional)
- Stop Bit: 1 or 2 bits
Interfacing Arduino UNO with UART
- Pins:
- Tx (Transmit) and Rx (Receive) pins used for UART.
- Additional power and ground pins for proper operation.
Example: Arduino UNO with Neo 6m GPS Module
- Connections:
- Connect Tx of Neo 6m to Rx of Arduino and vice versa.
- Follow the pin configurations from the Arduino to ensure correct functioning.
Arduino Code Snippet for UART Communication
#include <SoftwareSerial.h>
SoftwareSerial gpsSerial (4, 3); // RX = 4, TX = 3
void setup() {
Serial.begin(9600);
gpsSerial.begin(9600); // Start GPS module UART at 9600 baud
}
void loop() {
while (gpsSerial.available()) {
Serial.write(gpsSerial.read()); // Read GPS data and print to Serial Monitor
}
}
- Example Output: GPS data in the NMEA format such as
$GPRMC,015915.00, ...