分享到plurk 分享到twitter 分享到facebook

版本 4b31a6ecf3b606a7d04cbf4d6754808d95d1704d

embedded/USART

Changes from 4b31a6ecf3b606a7d04cbf4d6754808d95d1704d to d18aa5f9d700d0d6bafa37f81ce296393e6f23d4

USART簡介
...................
USART(universal synchronous asynchronous receiver transmitter) 通用同步/非同步收發傳輸器,提供了一種靈活的方法及使用NRZ非同步串行資料格式與外部設備之間進行全雙工資料交換。
同時,USART也提供同步的方式半雙工的通信,另外支持LIN (local interconnection network),Smartcard協定及IrDA (infrared data association紅外通訊技術) SIR ENDEC,Modem(CTS/RTS)的操作。
藉由DMA多重緩衝器的方式,可達到高速資料的通訊。




USART主要特性
...................

- 全雙工的非同步通訊

- NRZ標準資料格式

   NRZ(Nonreturn to Zero):不歸零編碼

   這是一種傳送資訊的編碼方式,它以正脈波代表1,負脈波代表0

   它的特色是編碼解碼較為簡單,可是同步信號必須另外傳播,否則無法提供訊號校正能力

.. image:: /NRZcode.png

圖片來源:`wikipedia<http://zh.wikipedia.org/wiki/%E4%B8%8D%E6%AD%B8%E9%9B%B6>`_

- 可程式化的資料長度 (8 or 9 bits)

- 可程式化的停止位元 (1 or 2 bits)

- 提供同步傳輸的CLK信號

- 藉由DMA的多緩衝器資料傳輸,每個USART都能用DMA發送和接收資料

- 獨立的發送器和接收器的enable bit

- 傳輸檢測標誌

 – 接收緩衝區滿

 – 傳送緩衝區空

 – 傳輸結束

- 校驗控制

 – 發送校驗位

 – 對接收的資料進行校驗

- 4個錯誤檢測標誌

 – 溢出錯誤(Overrun error)

 – 噪音檢測(Noise detection)

 – Frame錯誤

 – 校驗錯誤

- 10個中斷源

 – CTS改變

 – LIN中斷檢測

 – 傳送緩衝區空

 – 傳送完成

 – 接收緩衝區滿

 – 空閒線路檢測

 – 溢出錯誤

 – Frame錯誤

 – 噪音錯誤

 – 校驗錯誤

- 2種喚醒接收器的方式

 - Address bit (MSB, 9th bit)

 - Idle line


USART功能介紹
.................................


USART block diagram
======================================
.. image:: /usart_block_diagram.png
Ref: `RM0090 Reference Manual P.949<http://www.st.com/web/en/resource/technical/document/reference_manual/DM00031020.pdf>`_

   - 任何USART雙向通信至少需要兩個腳位:接收資料輸入(RX)和發送資料輸出(TX)
   - RX: 接收資料輸入,並藉由採樣的技術判斷資料及噪音
   - TX: 發送資料,當發送器被啟動時,如果沒有傳送數據,則TX處於高電位。在single-wire或Smartcard mode時,此I/O同時被用於資料的傳送和接收
   - 根據USART_CR1暫存器中的M位選擇8或9位元決定資料長度(見圖)
   - 使用fractional baud rate generator —— 12位整數和4位小數的表示方法,放在baud rate暫存器(USART_BRR)中
   - 一個狀態暫存器(USART_SR)
   - 資料暫存器(USART_DR)
   
   另外在同步模式中,還需要其他腳位
  
   - SCLK: 發送器的時鐘輸出,用於同步傳輸的時鐘
   
   在Hardware flow control中:
   
   - nCTS: 清除發送,若在高電位,則當目前資料傳送結束後,中斷下一次的資料傳送
   
   - nRTS: 發送請求,若在低電位,則表是USART已經準備好接收資料




USART 特性描述
======================================
資料長度根據USART_CR1暫存器中的M位選擇8或9位元

在起始位期間,TX處於低電位,在停止位期間,TX處於高電位。

另外空閒符號則全由'1'組成,後面接著下一個資料的開始位('1'的位數也包含資料的停止位元位數);

中斷符號則全由'0'所組成(包含資料的停止位也是'0'),在中斷時,發送器會再插入1或2個停止位('0')

.. image:: /idleandbreak.png


傳送器
============================
傳送器依據USART_CR1 M位的狀態來決定發送8或9位元的資料。
當transmit enable bit(TE)被設定時,資料transmit shift register經由TX腳位送出,
傳送器依據USART_CR1的M位狀態來決定發送8或9位元的資料。
當transmit enable bit(TE)被設定時,資料放入transmit shift register後,經由TX腳位送出,
同時,相對應的時鐘脈衝會由SCLK腳位輸出。


資料的傳送
------------------------------------
在USART發送期間,TX首先傳送資料的最低有效位元(least significant bit),因此在此模式中,USART_DR和transmit shift register之間包含一個緩衝器(TDR)。每個資料再傳送前都會有一個低電位的起始位;之後跟著的停止位元數目,則可由使用者決定0.5, 1, 1.5或2
   - 1 bit的停止位: 預設的默認停止位位元數
   - 2 bits的停止位: normal USART, single-wire 和 modem modes
   - 0.5 bits的停止位: Smartcard mode接收數據用
   - 1.5 bits的停止位: Smartcard mode發送數據用

.. image:: /usart_fig298.jpg

Ref: `RM0090 Reference Manual P.952<http://www.st.com/web/en/resource/technical/document/reference_manual/DM00031020.pdf>`_


傳送器的設定
------------------------------------
   1. 設定USART_CR1暫存器的UE位來啟動傳輸
   2. 設定USART_CR1暫存器的M位決定資料長度
   3. 設定USART_CR2暫存器中的STOP位來決定停止位的長度
   4. 採用多緩衝器的話,則須設定USART)CR3的DMAT啟動DMA,並設置DMA的暫存器
   3. 設定USART_CR2暫存器中的STOP位來決定停止位元的長度
   4. 採用多緩衝器的話,則須設定USART_CR3的DMAT啟動DMA,並設置DMA的暫存器
   5. 設置USART_CR1的TE位,在第一筆資料傳送前,傳送一個空閒的frame
   6. 利用USART_BRR暫存器設定baud rate
   7. 將欲發送的資料放入USART_DR中,重複步驟7

當資料放入USART_DR會由硬體清除TXE位,則表示:
   1. 資料已從TDR中進入transmit shift register,資料的發送已開始
   2. TDR暫存器已被清空
   3. 下一筆資料可放入USART_DR中

若TXEIE位的設置,則會產生一個中斷:
   如果USART正在發送資料,對USART_DR的寫入會把資料移到TDR暫存器中,並在目前的資料傳送結束後把該筆資料移進transmit shift register中
   如果USART沒有在發送資料,則對USART_DR的寫入會把資料直接放入transmit shift register中,並啟動傳送,當傳送開始時,硬體會立即設定TXE位
   - 如果USART正在發送資料,對USART_DR的寫入會把資料移到TDR暫存器中,並在目前的資料傳送結束後把該筆資料移進transmit shift register中
   
   - 如果USART沒有在發送資料,則對USART_DR的寫入會把資料直接放入transmit shift register中,並啟動傳送,當傳送開始時,硬體會立即設定TXE位

一個frame的資料發送完畢後,TC位會被設定,如果USART_CR1中的TCIE有被設定,則會產生一個中斷,先讀取USART_SR暫存器,再寫入USART_DR暫存器,則可清除TC位



傳送斷開符號
------------------------------------
(代補)
透過設定USART_CR1的SBK位,可以發送一個斷開符號,斷開符號的長度取決於M位。

如果SBK=1,則在目前的資料發送後,會再TX線上發送一個斷開符號,當傳送完成後,會由硬體恢復SBK位。

USART會在最後一個斷開符號的結束處插入一個'1',確保能辨識下一個資料的起始位。



傳送空閒符號
------------------------------------
(代補)
設置USART_CR1的TE位會使得USART在發送第一筆資料前,發送一個空閒符號






接收器
====================================
接收器依據USART_CR1 M位的狀態來決定接收8或9位元的資料。



接收斷開符號
起始位偵測
------------------------------------
設置SBK可發送一個斷開符號。

When a break character is received, the USART handles it as a framing error.
.. image:: /usart_fig300.jpg

Ref: `RM0090 Reference Manual P.954<http://www.st.com/web/en/resource/technical/document/reference_manual/DM00031020.pdf>`_

在USART中,如果辨認出一個特殊的採樣序列( 1 1 1 0 X 0 X 0 X 0 0 0 0 ),則認定偵測到一個起始位。

接收空閒符號
------------------------------------
When an idle frame is detected, there is the same procedure as a data received character
plus an interrupt if the IDLEIE bit is set.
**如果該序列不完整,則接收端退回起始位偵測並回到空閒狀態,等待下一次的電壓下降。**

如果三個採樣點上有僅有兩個是0(第3、5、7採樣點或8、9、10採樣點),則依然判定為偵測到一個起始位,但NE(噪音標誌)會被設定


溢出錯誤
資料的接收
------------------------------------
An overrun error occurs when a character is received when RXNE has not been reset. Data
can not be transferred from the shift register to the RDR register until the RXNE bit is
cleared.
在USART接收期間,RX從資料最低有效位元(least significant bit)開始接收,因此在此模式中,USART_DR和received shift register之間包含一個緩衝器(RDR)。

The RXNE flag is set after every byte received. An overrun error occurs if RXNE flag is set
when the next data is received or the previous DMA request has not been serviced. When
an overrun error occurs:

● The ORE bit is set.
接收器的設定
------------------------------------
   1. 設定USART_CR1暫存器的UE位來啟動USART接收
   2. 設定USART_CR1暫存器的M位決定資料長度
   3. 設定USART_CR2暫存器中的STOP位來決定停止位元的長度
   4. 採用多緩衝器接收資料,則須設定USART_CR3的DMAR啟動DMA,並設置DMA的暫存器
   5. 利用USART_BRR暫存器設定baud rate
   6. 設定USART_CR1暫存器中的RE位,啟動接收器,並開始偵測起始位

● The RDR content will not be lost. The previous data is available when a read to
USART_DR is performed.
當資料被接收到後:
   1. 硬體會設定RXNE位,表示received shift register中的資料已移入RDR中,亦即資料已被接收並可被讀出
   2. 若USART_CR1中的RXNEIE被設定時,會產生一個中斷
   3. 資料接收期間如檢測到frame錯誤或是噪音、易出錯舞等問題,相關的標誌將被設定(FE、NF、ORE)
   4. 在多緩衝器接收時,RXNE在每個字元接收後被設置,並藉由DMA讀取RDR而被清除
   5. 單緩衝器模式下,藉由讀取USART_DR可清除RXNE位,RXNE位必須要在下一資料接收前被清除,以免產生易出錯誤

● The shift register will be overwritten. After that point, any data received during overrun
is lost.
接收斷開符號
------------------------------------
USART在接收斷開符號後,可像處理frame錯誤一樣處理

● An interrupt is generated if either the RXNEIE bit is set or both the EIE and DMAR bits
are set.

● The ORE bit is reset by a read to the USART_SR register followed by a USART_DR
register read operation.
接收空閒符號
------------------------------------
當空閒符號被偵測到時,USART處理步驟如同一般資料一樣處理,但如果USART_CR1的IDLEIE被設置時,將會產生一個中斷

Note: The ORE bit, when set, indicates that at least 1 data has been lost. There are two
possibilities:

● if RXNE=1, then the last valid data is stored in the receive register RDR and can be
read,
溢出錯誤
------------------------------------
若RXNE沒有被覆位,此時又接收到一個新資料,則會發生溢出錯誤。

● if RXNE=0, then it means that the last valid data has already been read and thus there
is nothing to be read in the RDR. This case can occur when the last valid data is read in
the RDR at the same time as the new (and lost) data is received. It may also occur
when the new data is received during the reading sequence (between the USART_SR
register read access and the USART_DR read access).
當溢出錯誤產生時:
   1. USART_SR中的ORE位將被設置
   2. RDR中的內容將不會被清除,因此讀取USART_DR仍可以得到先前的資料
   3. Received shift register中的資料將被覆蓋
   4. 如果RXNEIE被設置,或是EIE(Error interrupt enable)和DMAR位被設定,則會產生一個中斷
   5. 依序讀取USART_SR和USART_DT暫存器,可清除ORE位

**當ORE位被設置時,表示至少有一個資料已遺失,有以下兩種可能性: **
   1. 如果RXNE=1,表示上一筆資料還在RDR中,且可被讀出
   2. 如果RXNE=0,表示上一筆資料已被讀走,RDR已無資料可被讀取。此種情況發生在讀取RDR中上一筆資料時,又接收到新的資料時,
      也有可能在依序讀取USART_SR到USART_DR之間時發生。

Selecting the proper oversampling method


噪音錯誤
------------------------------------
透過採樣技術,可以區分有效的輸入資料和噪音,並進行資料恢復。

The receiver implements different user-configurable oversampling techniques (except in
synchronous mode) for data recovery by discriminating between valid incoming data and
noise.

The oversampling method can be selected by programming the OVER8 bit in the
USART_CR1 register and can be either 16 or 8 times the baud rate clock (Figure 250 and
Figure 251).

Depending on the application:

● select oversampling by 8 (OVER8=1) to achieve higher speed (up to fPCLK/8). In this
case the maximum receiver tolerance to clock deviation is reduced (refer to
Section 26.3.5: USART receiver tolerance to clock deviation on page 760)

● select oversampling by 16 (OVER8=0) to increase the tolerance of the receiver to clock
deviations. In this case, the maximum speed is limited to maximum fPCLK/16
Programming the ONEBIT bit in the USART_CR3 register selects the method used to
evaluate the logic level. There are two options:

● the majority vote of the three samples in the center of the received bit. In this case,
when the 3 samples used for the majority vote are not equal, the NF bit is set

● a single sample in the center of the received bit

  Depending on the application:

  – select the three samples’ majority vote method (ONEBIT=0) when operating in a
  noisy environment and reject the data when a noise is detected (refer to
  Figure 105) because this indicates that a glitch occurred during the sampling.

  – select the single sample method (ONEBIT=1) when the line is noise-free to
  increase the receiver’s tolerance to clock deviations (see Section 26.3.5: USART
  receiver tolerance to clock deviation on page 760). In this case the NF bit will
  never be set.

When noise is detected in a frame:

● The NF bit is set at the rising edge of the RXNE bit.

● The invalid data is transferred from the Shift register to the USART_DR register.

● No interrupt is generated in case of single byte communication. However this bit rises
at the same time as the RXNE bit which itself generates an interrupt. In case of
multibuffer communication an interrupt will be issued if the EIE bit is set in the
USART_CR3 register.

The NF bit is reset by a USART_SR register read operation followed by a USART_DR
register read operation.

Note: Oversampling by 8 is not available in the Smartcard, IrDA and LIN modes. In those modes,
the OVER8 bit is forced to ‘0 by hardware.

.. image:: /oversampling16.png


.. image:: /oversampling8.png


.. image:: /noisedetection.png

.. image:: /noisedetectionsampledata.png



Fractional baud rate generation的設定
====================================
The baud rate for the receiver and transmitter (Rx and Tx) are both set to the same value as
programmed in the Mantissa and Fraction values of USARTDIV.

.. image:: /baud.png

USARTDIV is an unsigned fixed point number that is coded on the USART_BRR register.

● When OVER8=0, the fractional part is coded on 4 bits and programmed by the
DIV_fraction[3:0] bits in the USART_BRR register

● When OVER8=1, the fractional part is coded on 3 bits and programmed by the
DIV_fraction[2:0] bits in the USART_BRR register, and bit DIV_fraction[3] must be kept
cleared.

Note: The baud counters are updated to the new value in the baud registers after a write operation
to USART_BRR. Hence the baud rate register value should not be changed during
communication.






IrDA SIR ENDEC
............................

IrDA:
=======

IrDA 是一種標準化紅外線數據傳送方式;STM32f4支援利用USART輸出訊號配合轉換電路,轉換成符合IrDA 標準的訊號,實現紅外線傳輸.
 

register 設定:
===============
USART_CR3 : IREN = 1; SCEN, HDSEL = 0.

USART_CR2 : LINEN , STOP, CLKEN = 0.

IrDA SIR 實體層:
=================


.. image:: /irda.PNG

SIR Transmit encoder 會把 USART 的Non Return to Zero 轉換成 IrDA 輸出訊號.

IrDA 輸出是一種 Return-To-Zero,Inverted 形式的訊號, 用一個紅外線 pulse 表示一個 logic 0.

每一個紅外線 pulse 相當於 3/16 的 bit period, 而 IrDA mode 下的 USART 的 bit rate 最高為 115.2 Kbps. 

(下圖 IrDA_OUT).

.. image:: /normal_mode.PNG



USART SYNCHRONOUS MODE
......................
register 設定:

USART_CR2 : CLKEN = 1;LINEN = 0;

USART_CR3 : SCEN, HDSEL, IREN = 0;

特性:

Synchronous 指的是TX 跟 RX 用同一個 Clock, 這個clock(SCLK)由 TX 端送出, 同時需要TE = 1,clock 才會產生;
(UART 4,5 不支援 Synchronous mode)

.. image:: /synchronous_transmission.png

在傳送 start bit, stop bit 時不會有 clock pulse 從 SCLK 送出,clock 處於 logic 0;

Last bit clock pulse(LBCL),確定第8(9,如果 M=1)bit的clock pulse會不會輸出;(FOR WHAT???????)

CPOL = 0: high 為 logic 1 ; CPOL =1 :high 為 logic 0;

CPHA = 0: clock pulse 發生在bit period 的後半段中;CPHA = 1: clock pulse 發生在bit period 的前半段;差別在於bit period中間的edge是正/負緣觸發;

master mode: can't recieve or send data using the input clock;

half-duplex: can't recieve and send at the same time;

因為同步, 所以不需要oversampling(Ws >> 2Wm)

setup time, hold time


HARDWARE FLOW CONTROL
......................
利用 nCTS 跟 nRTS 控制 TX , RX 要不要再傳送或接收 data

.. image:: /hardware_control_2usarts.png


RTS Flow Control
========================
RTSE(RTS flow control enable) , CTSE 為1才開啟hw flow control;

Figure 318
在recieve端register 滿了以後, nRTS轉為 1,表示接收完這個data以後就暫時不接收Data;

.. image:: /rst_flow_control.png


CTS Flow Control
========================
跟上面是對應的, 當nRTS為1, transimitter 端的nCTS就會是1, 表示他知道reciever 目前無法接收data, TX就會在傳送完當前的data以後 idle.

nCTS為1 的時候,  會由硬體去設定CTSIE bit (USART_CR3).

.. image:: /cst_flow_control.png


PARITY CONTROL
..............
Parity control是用來確保傳輸資料的正確性。其原理是在傳輸端產生一個parity bit,然後在接收端可以重新計算parity bit以確保在傳輸過程沒有發生錯誤。在STM32,它可以透過設定USART_CR1 register的PCE bit來打開。STM32的frame長度是由M bit所決定,所以USART的frame有以下這些可能格式:

.. image:: /frame_formats.png

Even/Odd parity
=================================

parity依算方式的不同分成兩種方式,even parity和odd parity

Even parity
--------------------
如果一個frame內1的數量是偶數,則在 even parity的情況下會把parity bit設為0。

E.g.: 假設 data=00110101; 因為有 4 bits被設為1,而且我們選擇的是 even parity(PS bit in USART_CR1 = 0),所以 parity bit被設為0。

Odd parity
-------------------
如果一個frame內1的數量是奇數,則在 odd parity的情況下會把parity bit設為0。

E.g.: 假設 data=00110101; 因為有 4 bits被設為1,而且我們選擇的是 odd parity(PS bit in USART_CR1 = 1),所以 parity bit被設為1。


接收後會做 parity checking
=========================================
如果 parity check 失敗了,USART_SR register的PE flag會被設立,然後如果USART_CR1 register的PEIE bit也有被設立的話,還會產生中斷。PE flag最後在軟體執行(a read from the status register followed by a read or write access to the USART_DR data register)時被清除。


傳送前會做 parity generation
======================================
如果USART_CR1的PCE bit被設立,那麼MSB會被改成parity bit(PS=0 是even parity, PS=1 是odd parity)

小知識:

MSB: Most Significant Bit,代表位數最大的那個bit

LSB: Least Significant Bit,代表位數最小的那個bit

USART Register 總表
................................
Status register(USART_SR)

Data register(USART_DR)

Baud rate register(USART_BRR)

Control Register 1(USART_CR1)

Control Register 2(USART_CR2)

Control Register 3(USART_CR3)

Guard time and prescaler register(USART_GTPR)

.. image:: /USART_register.png

CODE SECTION
.........................

Download sample code : 

.. code-block:: c

    git clone https://github.com/wujiheng/stm32f407.git
    cd stm32f407/USART


To compile code

.. code-block:: c

   make 
   make flash    <-- 記得把USB連上去


這裡採用minicom 超級終端機來接收USART字串

.. code-block:: c
   
   ls /dev       <-- 找device,見圖,這裡找到/dev/ttyUSB0

.. image:: /usart-ls-dev.png

.. code-block:: c

   sudo apt-get install minicom
   sudo minicom -s                   <-- 不一定要用root,不過使用者必須要device node 讀寫的權限,-s表進入setup

.. image:: /usart-minicom-setup.png
.. image:: /usart-minicom-device.png
.. code-block:: c

   選擇第三個"Serial port setup",設定接收的模式及port   
   先按'A'選擇device,並輸入/dev/ttyUSB0(由剛剛的ls /dev)決定

.. image:: /usart-minicom-parameter.png


   再來按'E'設定接收的參數,選擇
.. code-block:: c

   'C' --> Baud rate 9600
   
   'L' --> None parity check

   'V' --> 資料長度 8 bits

   'W' --> 停止位元數 1 bit

   輸入完後按Enter離開

.. image:: /usart-minicom-save.png
  
.. code-block:: c

   回到原本的畫面,選擇 'Save setup as default' ,然後選擇 'Exit from Minicom' 離開

.. image:: /usart-minicom.png

.. code-block:: c
   回到Terminal,重新輸入sudo minicom進入Minicom的畫面

.. image:: /usart-minicom.png


.. image:: /usart-pin.jpg


.. code-block:: c
   
   按照圖上的接法,白色線接PA2、綠色線接PA3
   ** 白色線為USB的RX所以要接上板子的TX(PA2) ** 
   ** 綠色線為USB的TX所以要接上板子的RX(PA3) ** 

此時畫面中的Minicom會顯示出結果,不斷的印出"Init complete! Hello World!"

.. image:: /usart_minicom_results.png

按Ctrl+a,再按x可離開Minicom




















REFERENCE
..................
- `Universal asynchronous receiver/transmitter wikipedia.<http://en.wikipedia.org/wiki/Universal_asynchronous_receiver/transmitter#Special_receiver_conditions>`_

- `STM32F407xx Reference Manual<http://www.st.com/web/en/resource/technical/document/reference_manual/DM00031020.pdf>`_


- `IrDA and RS-232<http://china.maximintegrated.com/app-notes/index.mvp/id/3024>`_

- `Using The DMA controller on STM32<http://www.mind-dump.net/using-the-dma-controller-on-stm32f4>`_

Q&A
...................

***1.UART 原理***

DTE(Data Terminal Equipment)簡稱數據終端設備;DCE(Data Communications Equipment)簡稱數據通信設備。

事實上,RS-232C標準的正規名稱是"數據終端設備和數據通信設備之間串行二進制數據交換的接口"。

通常,將通信線路終端一側的計算機或終端稱為DTE,而把連接通信線路一側的調製解調器稱為DCE。

RS-232C標準中所提到的"發送"和"接收",都是站在DTE立場上,而不是站在DCE的立場來定義的。

由於在計算機系統中往往是CPU和I/O設備之間傳送信息,兩者都是DTE,因此雙方都能發送接收。

所謂"串行通信"是指DTE和DCE之間使用一根數據信號線(另外需要地線,可能還需要控制線)

數據在一根數據信號線上一位一位地進行傳輸,每一位數據都佔據一個固定的時間長度。

這種通信方式使用的數據線少,在遠距離通信中可以節約通信成本,當然,其傳輸速度比並行傳輸慢。

小知識:

DTE英文全稱Data Terminal Equipment,數字終端設備,指一般的終端或是計算機。可能是大、中、小型計算機,也可能是一臺只接收數據的打印機。

DCE英文全稱Data Circuit-terminating Equipment,數字通信設備,通常指調制解調器,多路復用器或數字設備。

DTE,DCE的區別

DCE一方提供時鐘,DTE不提供時鐘,但它依靠DCE提供的時鐘工作。

舉PC機和MODEM之間的連接為例:PC機就是一個DTE,MODEM是一個DCE。

DTE可以從硬件上區別它的接口為針式,DCE的接口為孔式。

參考資料:http://wfeng520.blog.hexun.com.tw/62795095_d.html


***2.USART和SPI的不同***

簡單複習SPI:

SPI:它是主從式的架構,通常一個主設備和多個從設備

由四條信號線組成:SCLK、MISO、MOSI、CS

MOSI:master output, slave input,主設備輸出

MISO:master input, slave output,主設備輸入

SCLK:serial clock,clock信號,由主設備產生

CS:chip select (optional)

USART在全雙工的模式(特別是同步模式)下,也有類似的訊號

TX:傳送訊號給周邊

RX:週邊設備傳送給主設備的訊號

SCLK:由主設備產生的clock訊號

以上是兩者有類似的地方


***3.高速UART及低速UART之應用?***

嵌入在ElanSC520微控制器中的高速UART通信的速度可以高達1.1152Mbps

另外利用計算機軟件技術(EDA技術)和FPGA/CPLD的靈活性可以方便快速地設計高速和低速的UART。

高速的UART可以用在光纖通信上,低速的UART可以用在FPGA/CPLD和單片機的通信上。


***4.USART、COM、RS232之關係***

UART包括了RS232、RS449、RS423、RS422和RS485等介面標準規範和匯流排標準規範,即UART是非同步串列通信口的總稱。

而RS232、RS449、RS423、RS422和RS485等,是對應各種非同步串列通信口的介面標準和匯流排標準,

它規定了通信口的電力特性、傳輸速率、連接特性和介面的機械特性等內容。

實際上這是是屬於通信網路中的物理層(最底層)的概念,與通信協議沒有直接關係。而通信協議,是屬於通信網路中的數據鏈路層(上一層)的概念。

COM是PC(個人計算機)上,非同步串列通信口的簡寫。由於歷史原因,IBM的PC外部介面配置為RS232,成為實際上的PC界默認標準。

所以,現在PC機的COM均為RS232。若配有多個非同步串列通信口,則分別稱為COM1、COM2...。

參考資料:http://ithelp.ithome.com.tw/question/10028134


***5.紅外線高速之應用?***

低速紅外線是指其傳輸速率在每秒115.2Kbits者而言,它適用於傳送簡短的訊息、文字或是檔案。

有低速紅外線也有高速紅外線(Fast IR),它是指傳輸速率在每秒1或是4Mbits者而言,其他更高傳輸速率則仍在發展中。

對於網路解決方案而言,高速紅外線可以說是其基礎,包括檔案傳輸、區域網路連結甚至是多媒體傳輸。