嵌入式系統 Introduction to Embedded System Design: Part 5: Serial Communication (UART)
嵌入式系統 Introduction to Embedded System Design: Part 5: Serial Communication (UART)
授課教師
Che-Wei LIN (林哲偉)
Embedded System-1
Introduction
Asynchronous
Synchronous
Embedded System-2
Serial Communication Buses
Embedded System-3
Asynchronous Serial Communication
Shifts the parallel data onto Extracts the data using its own
the serial line using its own clock
clock
Converts the serial data back to
Also adds the start, stop and
the parallel form after stripping
parity check bits
off the start, stop and parity bits
Embedded System-4
Asynchronous Serial Communication
Embedded System-5
Asynchronous Serial Communication
Embedded System-6
Synchronous Serial Communication
Shifts the data onto the serial Extracts the data using the
line using its own clock clock provided by the
transmitter
Provides the clock as a separate
signal Converts the serial data back
to the parallel form
No start, stop, or parity bits
added to data
Embedded System-7
Introduction of UART in UNO
UART uses two wirelines, one for transmitting and the other one
for receiving, so as to make the data transmission bidirectional.
If we use the hardware UART for other purposes, the Log UART
does not have resources to do its job.
Embedded System-8
Introduction of UART in UNO
Embedded System-9
Example01 - SerialEvent
Open this example code from Introduction
"File" -> SerialEvent occurs whenever a new data comes in
the hardware serial RX. This routine is run between
"Examples" -> each time loop() runs.
“04.Communication" ->
“SerialEvent" Test and Result.
Embedded System-10
Example02 - SoftwareSerialExample
Open this example code from
"File" ->
"Examples" ->
“SoftwareSerial" ->
“SoftwareSerial Example"
Embedded System-11
Example02 - SoftwareSerialExample
Materials
Arduino UNO Board × 1
Embedded System-12
Example02 - SoftwareSerialExample
Introduction of CP2102
The CP2102 is a highly-integrated USB-to-UART Bridge Controller
providing a simple solution for updating RS-232 designs to USB using a
minimum of components and PCB space.
Embedded System-15
Example02 - SoftwareSerialExample
https://ttssh2.osdn.jp/index.html.en
Result:
從mySerial輸入,會顯示在Serial視窗上;從Serial輸入,會顯示在mySerial視窗上。
Embedded System-16
Example03 - Master Reader/Slave Sender
Embedded System-17
Example03 - Master Reader/Slave Sender
Materials
Arduino UNO Board × 2
Code1: Code2:
https://www.arduino.cc/en/Tutorial/MasterReader? https://www.arduino.cc/en/Tutorial/MasterReader?
action=sourceblock&num=1 action=sourceblock&num=2
Embedded System-18
Example03 - Master Reader/Slave Sender
Embedded System-19
Example03 - Master Reader/Slave Sender
Embedded System-20
Example03 - Master Reader/Slave Sender
Embedded System-21
To output data via serial port (1)
Notice:
To write “binary” data or “ASCII” data in the Arduino are different
https://www.arduino.cc/en/serial/write
Embedded System-22
To output data via serial port (2)
Notice:
To write “binary” data or “ASCII” data in the Arduino are different
https://www.arduino.cc/en/serial/print
Embedded System-23
Lab Requirements
Please establish the communication between Arduino and PC first.
Please transmit AA16 between from Arduino to PC continuously, than check the
signal from oscilloscope to explain the physical meaning of the signal (High/Low,
Baudrate)
Once the Arduino receives one of the words: “A”, “B”, “C”, “D”, “R”, transmits current state to PC
(Please display current state of FSM in the Tera-Term software terminal).
Start Bit Parity Bit 1 or 2 Stop Bits
D0 D1 D2 D3 D4 D5 D6 D7
1 Asynchronous Byte
Embedded System-24
ASCII Code
http://www.asciitable.com/
Embedded System-25
Code Reference
https://www.arduino.cc/reference/en/language/functions/com
munication/serial/
https://www.arduino.cc/en/Reference/SoftwareSerialExample
https://www.arduino.cc/en/Tutorial/MasterReader
https://www.arduino.cc/en/Reference/WireRequestFrom
https://www.arduino.cc/en/Reference/WireOnRequest
Embedded System-26