stm32f10x_usart.h

Go to the documentation of this file.
00001 /**
00002   ******************************************************************************
00003   * @file    stm32f10x_usart.h
00004   * @author  MCD Application Team
00005   * @version V3.4.0
00006   * @date    10/15/2010
00007   * @brief   This file contains all the functions prototypes for the USART 
00008   *          firmware library.
00009   ******************************************************************************
00010   * @copy
00011   *
00012   * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
00013   * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
00014   * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
00015   * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
00016   * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
00017   * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
00018   *
00019   * <h2><center>&copy; COPYRIGHT 2010 STMicroelectronics</center></h2>
00020   */ 
00021 
00022 /* Define to prevent recursive inclusion -------------------------------------*/
00023 #ifndef __STM32F10x_USART_H
00024 #define __STM32F10x_USART_H
00025 
00026 #ifdef __cplusplus
00027  extern "C" {
00028 #endif
00029 
00030 /* Includes ------------------------------------------------------------------*/
00031 #include "stm32f10x.h"
00032 
00033 /** @addtogroup STM32F10x_StdPeriph_Driver
00034   * @{
00035   */
00036 
00037 /** @addtogroup USART
00038   * @{
00039   */ 
00040 
00041 /** @defgroup USART_Exported_Types
00042   * @{
00043   */ 
00044 
00045 /** 
00046   * @brief  USART Init Structure definition  
00047   */ 
00048   
00049 typedef struct
00050 {
00051   uint32_t USART_BaudRate;            /*!< This member configures the USART communication baud rate.
00052                                            The baud rate is computed using the following formula:
00053                                             - IntegerDivider = ((PCLKx) / (16 * (USART_InitStruct->USART_BaudRate)))
00054                                             - FractionalDivider = ((IntegerDivider - ((u32) IntegerDivider)) * 16) + 0.5 */
00055 
00056   uint16_t USART_WordLength;          /*!< Specifies the number of data bits transmitted or received in a frame.
00057                                            This parameter can be a value of @ref USART_Word_Length */
00058 
00059   uint16_t USART_StopBits;            /*!< Specifies the number of stop bits transmitted.
00060                                            This parameter can be a value of @ref USART_Stop_Bits */
00061 
00062   uint16_t USART_Parity;              /*!< Specifies the parity mode.
00063                                            This parameter can be a value of @ref USART_Parity
00064                                            @note When parity is enabled, the computed parity is inserted
00065                                                  at the MSB position of the transmitted data (9th bit when
00066                                                  the word length is set to 9 data bits; 8th bit when the
00067                                                  word length is set to 8 data bits). */
00068  
00069   uint16_t USART_Mode;                /*!< Specifies wether the Receive or Transmit mode is enabled or disabled.
00070                                            This parameter can be a value of @ref USART_Mode */
00071 
00072   uint16_t USART_HardwareFlowControl; /*!< Specifies wether the hardware flow control mode is enabled
00073                                            or disabled.
00074                                            This parameter can be a value of @ref USART_Hardware_Flow_Control */
00075 } USART_InitTypeDef;
00076 
00077 /** 
00078   * @brief  USART Clock Init Structure definition  
00079   */ 
00080   
00081 typedef struct
00082 {
00083 
00084   uint16_t USART_Clock;   /*!< Specifies whether the USART clock is enabled or disabled.
00085                                This parameter can be a value of @ref USART_Clock */
00086 
00087   uint16_t USART_CPOL;    /*!< Specifies the steady state value of the serial clock.
00088                                This parameter can be a value of @ref USART_Clock_Polarity */
00089 
00090   uint16_t USART_CPHA;    /*!< Specifies the clock transition on which the bit capture is made.
00091                                This parameter can be a value of @ref USART_Clock_Phase */
00092 
00093   uint16_t USART_LastBit; /*!< Specifies whether the clock pulse corresponding to the last transmitted
00094                                data bit (MSB) has to be output on the SCLK pin in synchronous mode.
00095                                This parameter can be a value of @ref USART_Last_Bit */
00096 } USART_ClockInitTypeDef;
00097 
00098 /**
00099   * @}
00100   */ 
00101 
00102 /** @defgroup USART_Exported_Constants
00103   * @{
00104   */ 
00105   
00106 #define IS_USART_ALL_PERIPH(PERIPH) (((PERIPH) == USART1) || \
00107                                      ((PERIPH) == USART2) || \
00108                                      ((PERIPH) == USART3) || \
00109                                      ((PERIPH) == UART4) || \
00110                                      ((PERIPH) == UART5))
00111 
00112 #define IS_USART_123_PERIPH(PERIPH) (((PERIPH) == USART1) || \
00113                                      ((PERIPH) == USART2) || \
00114                                      ((PERIPH) == USART3))
00115 
00116 #define IS_USART_1234_PERIPH(PERIPH) (((PERIPH) == USART1) || \
00117                                       ((PERIPH) == USART2) || \
00118                                       ((PERIPH) == USART3) || \
00119                                       ((PERIPH) == UART4))
00120 /** @defgroup USART_Word_Length 
00121   * @{
00122   */ 
00123   
00124 #define USART_WordLength_8b                  ((uint16_t)0x0000)
00125 #define USART_WordLength_9b                  ((uint16_t)0x1000)
00126                                     
00127 #define IS_USART_WORD_LENGTH(LENGTH) (((LENGTH) == USART_WordLength_8b) || \
00128                                       ((LENGTH) == USART_WordLength_9b))
00129 /**
00130   * @}
00131   */ 
00132 
00133 /** @defgroup USART_Stop_Bits 
00134   * @{
00135   */ 
00136   
00137 #define USART_StopBits_1                     ((uint16_t)0x0000)
00138 #define USART_StopBits_0_5                   ((uint16_t)0x1000)
00139 #define USART_StopBits_2                     ((uint16_t)0x2000)
00140 #define USART_StopBits_1_5                   ((uint16_t)0x3000)
00141 #define IS_USART_STOPBITS(STOPBITS) (((STOPBITS) == USART_StopBits_1) || \
00142                                      ((STOPBITS) == USART_StopBits_0_5) || \
00143                                      ((STOPBITS) == USART_StopBits_2) || \
00144                                      ((STOPBITS) == USART_StopBits_1_5))
00145 /**
00146   * @}
00147   */ 
00148 
00149 /** @defgroup USART_Parity 
00150   * @{
00151   */ 
00152   
00153 #define USART_Parity_No                      ((uint16_t)0x0000)
00154 #define USART_Parity_Even                    ((uint16_t)0x0400)
00155 #define USART_Parity_Odd                     ((uint16_t)0x0600) 
00156 #define IS_USART_PARITY(PARITY) (((PARITY) == USART_Parity_No) || \
00157                                  ((PARITY) == USART_Parity_Even) || \
00158                                  ((PARITY) == USART_Parity_Odd))
00159 /**
00160   * @}
00161   */ 
00162 
00163 /** @defgroup USART_Mode 
00164   * @{
00165   */ 
00166   
00167 #define USART_Mode_Rx                        ((uint16_t)0x0004)
00168 #define USART_Mode_Tx                        ((uint16_t)0x0008)
00169 #define IS_USART_MODE(MODE) ((((MODE) & (uint16_t)0xFFF3) == 0x00) && ((MODE) != (uint16_t)0x00))
00170 /**
00171   * @}
00172   */ 
00173 
00174 /** @defgroup USART_Hardware_Flow_Control 
00175   * @{
00176   */ 
00177 #define USART_HardwareFlowControl_None       ((uint16_t)0x0000)
00178 #define USART_HardwareFlowControl_RTS        ((uint16_t)0x0100)
00179 #define USART_HardwareFlowControl_CTS        ((uint16_t)0x0200)
00180 #define USART_HardwareFlowControl_RTS_CTS    ((uint16_t)0x0300)
00181 #define IS_USART_HARDWARE_FLOW_CONTROL(CONTROL)\
00182                               (((CONTROL) == USART_HardwareFlowControl_None) || \
00183                                ((CONTROL) == USART_HardwareFlowControl_RTS) || \
00184                                ((CONTROL) == USART_HardwareFlowControl_CTS) || \
00185                                ((CONTROL) == USART_HardwareFlowControl_RTS_CTS))
00186 /**
00187   * @}
00188   */ 
00189 
00190 /** @defgroup USART_Clock 
00191   * @{
00192   */ 
00193 #define USART_Clock_Disable                  ((uint16_t)0x0000)
00194 #define USART_Clock_Enable                   ((uint16_t)0x0800)
00195 #define IS_USART_CLOCK(CLOCK) (((CLOCK) == USART_Clock_Disable) || \
00196                                ((CLOCK) == USART_Clock_Enable))
00197 /**
00198   * @}
00199   */ 
00200 
00201 /** @defgroup USART_Clock_Polarity 
00202   * @{
00203   */
00204   
00205 #define USART_CPOL_Low                       ((uint16_t)0x0000)
00206 #define USART_CPOL_High                      ((uint16_t)0x0400)
00207 #define IS_USART_CPOL(CPOL) (((CPOL) == USART_CPOL_Low) || ((CPOL) == USART_CPOL_High))
00208 
00209 /**
00210   * @}
00211   */ 
00212 
00213 /** @defgroup USART_Clock_Phase
00214   * @{
00215   */
00216 
00217 #define USART_CPHA_1Edge                     ((uint16_t)0x0000)
00218 #define USART_CPHA_2Edge                     ((uint16_t)0x0200)
00219 #define IS_USART_CPHA(CPHA) (((CPHA) == USART_CPHA_1Edge) || ((CPHA) == USART_CPHA_2Edge))
00220 
00221 /**
00222   * @}
00223   */
00224 
00225 /** @defgroup USART_Last_Bit
00226   * @{
00227   */
00228 
00229 #define USART_LastBit_Disable                ((uint16_t)0x0000)
00230 #define USART_LastBit_Enable                 ((uint16_t)0x0100)
00231 #define IS_USART_LASTBIT(LASTBIT) (((LASTBIT) == USART_LastBit_Disable) || \
00232                                    ((LASTBIT) == USART_LastBit_Enable))
00233 /**
00234   * @}
00235   */ 
00236 
00237 /** @defgroup USART_Interrupt_definition 
00238   * @{
00239   */
00240   
00241 #define USART_IT_PE                          ((uint16_t)0x0028)
00242 #define USART_IT_TXE                         ((uint16_t)0x0727)
00243 #define USART_IT_TC                          ((uint16_t)0x0626)
00244 #define USART_IT_RXNE                        ((uint16_t)0x0525)
00245 #define USART_IT_IDLE                        ((uint16_t)0x0424)
00246 #define USART_IT_LBD                         ((uint16_t)0x0846)
00247 #define USART_IT_CTS                         ((uint16_t)0x096A)
00248 #define USART_IT_ERR                         ((uint16_t)0x0060)
00249 #define USART_IT_ORE                         ((uint16_t)0x0360)
00250 #define USART_IT_NE                          ((uint16_t)0x0260)
00251 #define USART_IT_FE                          ((uint16_t)0x0160)
00252 #define IS_USART_CONFIG_IT(IT) (((IT) == USART_IT_PE) || ((IT) == USART_IT_TXE) || \
00253                                ((IT) == USART_IT_TC) || ((IT) == USART_IT_RXNE) || \
00254                                ((IT) == USART_IT_IDLE) || ((IT) == USART_IT_LBD) || \
00255                                ((IT) == USART_IT_CTS) || ((IT) == USART_IT_ERR))
00256 #define IS_USART_GET_IT(IT) (((IT) == USART_IT_PE) || ((IT) == USART_IT_TXE) || \
00257                             ((IT) == USART_IT_TC) || ((IT) == USART_IT_RXNE) || \
00258                             ((IT) == USART_IT_IDLE) || ((IT) == USART_IT_LBD) || \
00259                             ((IT) == USART_IT_CTS) || ((IT) == USART_IT_ORE) || \
00260                             ((IT) == USART_IT_NE) || ((IT) == USART_IT_FE))
00261 #define IS_USART_CLEAR_IT(IT) (((IT) == USART_IT_TC) || ((IT) == USART_IT_RXNE) || \
00262                                ((IT) == USART_IT_LBD) || ((IT) == USART_IT_CTS))
00263 /**
00264   * @}
00265   */
00266 
00267 /** @defgroup USART_DMA_Requests 
00268   * @{
00269   */
00270 
00271 #define USART_DMAReq_Tx                      ((uint16_t)0x0080)
00272 #define USART_DMAReq_Rx                      ((uint16_t)0x0040)
00273 #define IS_USART_DMAREQ(DMAREQ) ((((DMAREQ) & (uint16_t)0xFF3F) == 0x00) && ((DMAREQ) != (uint16_t)0x00))
00274 
00275 /**
00276   * @}
00277   */ 
00278 
00279 /** @defgroup USART_WakeUp_methods
00280   * @{
00281   */
00282 
00283 #define USART_WakeUp_IdleLine                ((uint16_t)0x0000)
00284 #define USART_WakeUp_AddressMark             ((uint16_t)0x0800)
00285 #define IS_USART_WAKEUP(WAKEUP) (((WAKEUP) == USART_WakeUp_IdleLine) || \
00286                                  ((WAKEUP) == USART_WakeUp_AddressMark))
00287 /**
00288   * @}
00289   */
00290 
00291 /** @defgroup USART_LIN_Break_Detection_Length 
00292   * @{
00293   */
00294   
00295 #define USART_LINBreakDetectLength_10b      ((uint16_t)0x0000)
00296 #define USART_LINBreakDetectLength_11b      ((uint16_t)0x0020)
00297 #define IS_USART_LIN_BREAK_DETECT_LENGTH(LENGTH) \
00298                                (((LENGTH) == USART_LINBreakDetectLength_10b) || \
00299                                 ((LENGTH) == USART_LINBreakDetectLength_11b))
00300 /**
00301   * @}
00302   */
00303 
00304 /** @defgroup USART_IrDA_Low_Power 
00305   * @{
00306   */
00307 
00308 #define USART_IrDAMode_LowPower              ((uint16_t)0x0004)
00309 #define USART_IrDAMode_Normal                ((uint16_t)0x0000)
00310 #define IS_USART_IRDA_MODE(MODE) (((MODE) == USART_IrDAMode_LowPower) || \
00311                                   ((MODE) == USART_IrDAMode_Normal))
00312 /**
00313   * @}
00314   */ 
00315 
00316 /** @defgroup USART_Flags 
00317   * @{
00318   */
00319 
00320 #define USART_FLAG_CTS                       ((uint16_t)0x0200)
00321 #define USART_FLAG_LBD                       ((uint16_t)0x0100)
00322 #define USART_FLAG_TXE                       ((uint16_t)0x0080)
00323 #define USART_FLAG_TC                        ((uint16_t)0x0040)
00324 #define USART_FLAG_RXNE                      ((uint16_t)0x0020)
00325 #define USART_FLAG_IDLE                      ((uint16_t)0x0010)
00326 #define USART_FLAG_ORE                       ((uint16_t)0x0008)
00327 #define USART_FLAG_NE                        ((uint16_t)0x0004)
00328 #define USART_FLAG_FE                        ((uint16_t)0x0002)
00329 #define USART_FLAG_PE                        ((uint16_t)0x0001)
00330 #define IS_USART_FLAG(FLAG) (((FLAG) == USART_FLAG_PE) || ((FLAG) == USART_FLAG_TXE) || \
00331                              ((FLAG) == USART_FLAG_TC) || ((FLAG) == USART_FLAG_RXNE) || \
00332                              ((FLAG) == USART_FLAG_IDLE) || ((FLAG) == USART_FLAG_LBD) || \
00333                              ((FLAG) == USART_FLAG_CTS) || ((FLAG) == USART_FLAG_ORE) || \
00334                              ((FLAG) == USART_FLAG_NE) || ((FLAG) == USART_FLAG_FE))
00335                               
00336 #define IS_USART_CLEAR_FLAG(FLAG) ((((FLAG) & (uint16_t)0xFC9F) == 0x00) && ((FLAG) != (uint16_t)0x00))
00337 #define IS_USART_PERIPH_FLAG(PERIPH, USART_FLAG) ((((*(uint32_t*)&(PERIPH)) != UART4_BASE) &&\
00338                                                   ((*(uint32_t*)&(PERIPH)) != UART5_BASE)) \
00339                                                   || ((USART_FLAG) != USART_FLAG_CTS)) 
00340 #define IS_USART_BAUDRATE(BAUDRATE) (((BAUDRATE) > 0) && ((BAUDRATE) < 0x0044AA21))
00341 #define IS_USART_ADDRESS(ADDRESS) ((ADDRESS) <= 0xF)
00342 #define IS_USART_DATA(DATA) ((DATA) <= 0x1FF)
00343 
00344 /**
00345   * @}
00346   */ 
00347 
00348 /**
00349   * @}
00350   */ 
00351 
00352 /** @defgroup USART_Exported_Macros
00353   * @{
00354   */ 
00355 
00356 /**
00357   * @}
00358   */ 
00359 
00360 /** @defgroup USART_Exported_Functions
00361   * @{
00362   */
00363 
00364 void USART_DeInit(USART_TypeDef* USARTx);
00365 void USART_Init(USART_TypeDef* USARTx, USART_InitTypeDef* USART_InitStruct);
00366 void USART_StructInit(USART_InitTypeDef* USART_InitStruct);
00367 void USART_ClockInit(USART_TypeDef* USARTx, USART_ClockInitTypeDef* USART_ClockInitStruct);
00368 void USART_ClockStructInit(USART_ClockInitTypeDef* USART_ClockInitStruct);
00369 void USART_Cmd(USART_TypeDef* USARTx, FunctionalState NewState);
00370 void USART_ITConfig(USART_TypeDef* USARTx, uint16_t USART_IT, FunctionalState NewState);
00371 void USART_DMACmd(USART_TypeDef* USARTx, uint16_t USART_DMAReq, FunctionalState NewState);
00372 void USART_SetAddress(USART_TypeDef* USARTx, uint8_t USART_Address);
00373 void USART_WakeUpConfig(USART_TypeDef* USARTx, uint16_t USART_WakeUp);
00374 void USART_ReceiverWakeUpCmd(USART_TypeDef* USARTx, FunctionalState NewState);
00375 void USART_LINBreakDetectLengthConfig(USART_TypeDef* USARTx, uint16_t USART_LINBreakDetectLength);
00376 void USART_LINCmd(USART_TypeDef* USARTx, FunctionalState NewState);
00377 void USART_SendData(USART_TypeDef* USARTx, uint16_t Data);
00378 uint16_t USART_ReceiveData(USART_TypeDef* USARTx);
00379 void USART_SendBreak(USART_TypeDef* USARTx);
00380 void USART_SetGuardTime(USART_TypeDef* USARTx, uint8_t USART_GuardTime);
00381 void USART_SetPrescaler(USART_TypeDef* USARTx, uint8_t USART_Prescaler);
00382 void USART_SmartCardCmd(USART_TypeDef* USARTx, FunctionalState NewState);
00383 void USART_SmartCardNACKCmd(USART_TypeDef* USARTx, FunctionalState NewState);
00384 void USART_HalfDuplexCmd(USART_TypeDef* USARTx, FunctionalState NewState);
00385 void USART_OverSampling8Cmd(USART_TypeDef* USARTx, FunctionalState NewState);
00386 void USART_OneBitMethodCmd(USART_TypeDef* USARTx, FunctionalState NewState);
00387 void USART_IrDAConfig(USART_TypeDef* USARTx, uint16_t USART_IrDAMode);
00388 void USART_IrDACmd(USART_TypeDef* USARTx, FunctionalState NewState);
00389 FlagStatus USART_GetFlagStatus(USART_TypeDef* USARTx, uint16_t USART_FLAG);
00390 void USART_ClearFlag(USART_TypeDef* USARTx, uint16_t USART_FLAG);
00391 ITStatus USART_GetITStatus(USART_TypeDef* USARTx, uint16_t USART_IT);
00392 void USART_ClearITPendingBit(USART_TypeDef* USARTx, uint16_t USART_IT);
00393 
00394 #ifdef __cplusplus
00395 }
00396 #endif
00397 
00398 #endif /* __STM32F10x_USART_H */
00399 /**
00400   * @}
00401   */ 
00402 
00403 /**
00404   * @}
00405   */ 
00406 
00407 /**
00408   * @}
00409   */ 
00410 
00411 /******************* (C) COPYRIGHT 2010 STMicroelectronics *****END OF FILE****/
STM32F10x Standard Peripherals Library: Footer

 

 

 

      For complete documentation on STM32(CORTEX M3) 32-bit Microcontrollers platform visit  www.st.com/STM32