天天看點

STM32--序列槽

在 STM32F4 固件庫中對序列槽 USART 的描述原文如下:

************************************************************************
  * @brief   This file provides firmware functions to manage the following 
  *          functionalities of the Universal synchronous asynchronous receiver
  *          transmitter (USART):           
  *           + Initialization and Configuration
  *           + Data transfers
  *           + Multi-Processor Communication
  *           + LIN mode
  *           + Half-duplex mode
  *           + Smartcard mode
  *           + IrDA mode
  *           + DMA transfers management
  *           + Interrupts and flags management 
  *           
===================================================================
                        ##### How to use this driver #####
 ===================================================================
    [..]
      (#) Enable peripheral clock using the following functions
          RCC_APB2PeriphClockCmd(RCC_APB2Periph_USARTx, ENABLE) for USART1 and USART6 
          RCC_APB1PeriphClockCmd(RCC_APB1Periph_USARTx, ENABLE) for USART2, USART3, 
          UART4 or UART5. 
      (#) According to the USART mode, enable the GPIO clocks using 
          RCC_AHB1PeriphClockCmd() function. (The I/O can be TX, RX, CTS, 
          or/and SCLK).  
      (#) Peripheral's alternate function: 
        (++) Connect the pin to the desired peripherals' Alternate 
            Function (AF) using GPIO_PinAFConfig() function
        (++) Configure the desired pin in alternate function by:
            GPIO_InitStruct->GPIO_Mode = GPIO_Mode_AF
        (++) Select the type, pull-up/pull-down and output speed via 
            GPIO_PuPd, GPIO_OType and GPIO_Speed members
        (++) Call GPIO_Init() function        
      (#) Program the Baud Rate, Word Length , Stop Bit, Parity, Hardware 
          flow control and Mode(Receiver/Transmitter) using the USART_Init()
          function.  
      (#) For synchronous mode, enable the clock and program the polarity,
          phase and last bit using the USART_ClockInit() function.  
      (#) Enable the NVIC and the corresponding interrupt using the function 
         USART_ITConfig() if you need to use interrupt mode.   
      (#) When using the DMA mode 
        (++) Configure the DMA using DMA_Init() function
        (++) Active the needed channel Request using USART_DMACmd() function  
      (#) Enable the USART using the USART_Cmd() function. 
      (#) Enable the DMA using the DMA_Cmd() function, when using DMA mode.     
      -@- Refer to Multi-Processor, LIN, half-duplex, Smartcard, IrDA sub-sections
          for more details   
    [..]        
    In order to reach higher communication baudrates, it is possible to
    enable the oversampling by 8 mode using the function USART_OverSampling8Cmd().
    This function should be called after enabling the USART clock (RCC_APBxPeriphClockCmd())
    and before calling the function USART_Init().
            
    @endverbatim        
  ******************************************************************************
  * @attention
  *
  * <h2><center>&copy; COPYRIGHT 2014 STMicroelectronics</center></h2>
  *
  * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
  * You may not use this file except in compliance with the License.
  * You may obtain a copy of the License at:
  *
  *        http://www.st.com/software_license_agreement_liberty_v2
  *
  * Unless required by applicable law or agreed to in writing, software 
  * distributed under the License is distributed on an "AS IS" BASIS, 
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
  *
  ******************************************************************************  
           
* @brief 此檔案提供固件功能來管理以下内容
* @通用同步異步接收器的功能

* +初始化和配置
* +資料傳輸
* +多處理器通信
* + LIN模式
* +半雙工模式
* +智能卡模式
* +IrDA模式
* +DMA傳輸管理
* +中斷和标志管理


===============================================================================
#####如何使用這個驅動#####
===============================================================================
[**]
(1.)使用以下功能啟用外圍時鐘
對于USART1和USART6, rcc_apb2periperi_cmd (rcc_apb2peri_usartx, ENABLE)
rcc_apb1periperi_usartcmd (rcc_apb1peri_usartx, ENABLE) for USART2, USART3,UART4或UART5。
根據USART模式,啟用GPIO時鐘使用RCC_AHB1PeriphClockCmd()函數。(I/O可以是TX, RX, CTS,或/和SCLK)。

(2.)外圍裝置的複用功能:
(++)連接配接引腳所需的外設的備用
使用GPIO_PinAFConfig()函數實作
(++)配置所需的引腳在備用功能:
GPIO_InitStruct - > GPIO_Mode = GPIO_Mode_AF
(++)選擇類型,上拉/下拉和輸出速度通過 GPIO_PuPd、GPIO_OType和GPIO_Speed 成員調用 GPIO_Init()函數


(3.)編寫波特率,字長,停止位,奇偶校驗,硬體使用USART_Init()的流量控制和模式(接收/發射)函數。

(4.)同步模式,啟用時鐘和程式極性,使用usart_clockkinit()函數的相位和最後一位。

(5.)啟用NVIC和相應的中斷使用該函數,USART_ITConfig()如果你需要使用中斷模式。

(6.)當使用DMA模式使用DMA_Init()函數配置DMA
    (++)激活所需的通道請求使用USART_DMACmd()函數

(7.)使用USART_Cmd()函數啟用USART。

當使用DMA模式時,使用DMA_Cmd()函數啟用DMA。

-@-參考多處理器、LIN、半雙工、智能卡、IrDA等章節
為更多的細節

[. .]
為了達到更高的通信波特率,可以使用函數 usart_overampling8cmd() 啟用8模式的采樣。
這個函數應該在啟用USART時鐘後調用(rcc_apbxperipericlockcmd ())
在調用函數USART_Init()之前。