stm32f10x_usart.c

Go to the documentation of this file.
00001 /**
00002   ******************************************************************************
00003   * @file    stm32f10x_usart.c
00004   * @author  MCD Application Team
00005   * @version V3.4.0
00006   * @date    10/15/2010
00007   * @brief   This file provides all the USART firmware functions.
00008   ******************************************************************************
00009   * @copy
00010   *
00011   * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
00012   * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
00013   * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
00014   * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
00015   * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
00016   * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
00017   *
00018   * <h2><center>&copy; COPYRIGHT 2010 STMicroelectronics</center></h2>
00019   */ 
00020 
00021 /* Includes ------------------------------------------------------------------*/
00022 #include "stm32f10x_usart.h"
00023 #include "stm32f10x_rcc.h"
00024 
00025 /** @addtogroup STM32F10x_StdPeriph_Driver
00026   * @{
00027   */
00028 
00029 /** @defgroup USART 
00030   * @brief USART driver modules
00031   * @{
00032   */
00033 
00034 /** @defgroup USART_Private_TypesDefinitions
00035   * @{
00036   */
00037 
00038 /**
00039   * @}
00040   */
00041 
00042 /** @defgroup USART_Private_Defines
00043   * @{
00044   */
00045 
00046 #define CR1_UE_Set                ((uint16_t)0x2000)  /*!< USART Enable Mask */
00047 #define CR1_UE_Reset              ((uint16_t)0xDFFF)  /*!< USART Disable Mask */
00048 
00049 #define CR1_WAKE_Mask             ((uint16_t)0xF7FF)  /*!< USART WakeUp Method Mask */
00050 
00051 #define CR1_RWU_Set               ((uint16_t)0x0002)  /*!< USART mute mode Enable Mask */
00052 #define CR1_RWU_Reset             ((uint16_t)0xFFFD)  /*!< USART mute mode Enable Mask */
00053 #define CR1_SBK_Set               ((uint16_t)0x0001)  /*!< USART Break Character send Mask */
00054 #define CR1_CLEAR_Mask            ((uint16_t)0xE9F3)  /*!< USART CR1 Mask */
00055 #define CR2_Address_Mask          ((uint16_t)0xFFF0)  /*!< USART address Mask */
00056 
00057 #define CR2_LINEN_Set              ((uint16_t)0x4000)  /*!< USART LIN Enable Mask */
00058 #define CR2_LINEN_Reset            ((uint16_t)0xBFFF)  /*!< USART LIN Disable Mask */
00059 
00060 #define CR2_LBDL_Mask             ((uint16_t)0xFFDF)  /*!< USART LIN Break detection Mask */
00061 #define CR2_STOP_CLEAR_Mask       ((uint16_t)0xCFFF)  /*!< USART CR2 STOP Bits Mask */
00062 #define CR2_CLOCK_CLEAR_Mask      ((uint16_t)0xF0FF)  /*!< USART CR2 Clock Mask */
00063 
00064 #define CR3_SCEN_Set              ((uint16_t)0x0020)  /*!< USART SC Enable Mask */
00065 #define CR3_SCEN_Reset            ((uint16_t)0xFFDF)  /*!< USART SC Disable Mask */
00066 
00067 #define CR3_NACK_Set              ((uint16_t)0x0010)  /*!< USART SC NACK Enable Mask */
00068 #define CR3_NACK_Reset            ((uint16_t)0xFFEF)  /*!< USART SC NACK Disable Mask */
00069 
00070 #define CR3_HDSEL_Set             ((uint16_t)0x0008)  /*!< USART Half-Duplex Enable Mask */
00071 #define CR3_HDSEL_Reset           ((uint16_t)0xFFF7)  /*!< USART Half-Duplex Disable Mask */
00072 
00073 #define CR3_IRLP_Mask             ((uint16_t)0xFFFB)  /*!< USART IrDA LowPower mode Mask */
00074 #define CR3_CLEAR_Mask            ((uint16_t)0xFCFF)  /*!< USART CR3 Mask */
00075 
00076 #define CR3_IREN_Set              ((uint16_t)0x0002)  /*!< USART IrDA Enable Mask */
00077 #define CR3_IREN_Reset            ((uint16_t)0xFFFD)  /*!< USART IrDA Disable Mask */
00078 #define GTPR_LSB_Mask             ((uint16_t)0x00FF)  /*!< Guard Time Register LSB Mask */
00079 #define GTPR_MSB_Mask             ((uint16_t)0xFF00)  /*!< Guard Time Register MSB Mask */
00080 #define IT_Mask                   ((uint16_t)0x001F)  /*!< USART Interrupt Mask */
00081 
00082 /* USART OverSampling-8 Mask */
00083 #define CR1_OVER8_Set             ((u16)0x8000)  /* USART OVER8 mode Enable Mask */
00084 #define CR1_OVER8_Reset           ((u16)0x7FFF)  /* USART OVER8 mode Disable Mask */
00085 
00086 /* USART One Bit Sampling Mask */
00087 #define CR3_ONEBITE_Set           ((u16)0x0800)  /* USART ONEBITE mode Enable Mask */
00088 #define CR3_ONEBITE_Reset         ((u16)0xF7FF)  /* USART ONEBITE mode Disable Mask */
00089 
00090 /**
00091   * @}
00092   */
00093 
00094 /** @defgroup USART_Private_Macros
00095   * @{
00096   */
00097 
00098 /**
00099   * @}
00100   */
00101 
00102 /** @defgroup USART_Private_Variables
00103   * @{
00104   */
00105 
00106 /**
00107   * @}
00108   */
00109 
00110 /** @defgroup USART_Private_FunctionPrototypes
00111   * @{
00112   */
00113 
00114 /**
00115   * @}
00116   */
00117 
00118 /** @defgroup USART_Private_Functions
00119   * @{
00120   */
00121 
00122 /**
00123   * @brief  Deinitializes the USARTx peripheral registers to their default reset values.
00124   * @param  USARTx: Select the USART or the UART peripheral. 
00125   *   This parameter can be one of the following values: USART1, USART2, USART3, UART4 or UART5.
00126   * @retval None
00127   */
00128 void USART_DeInit(USART_TypeDef* USARTx)
00129 {
00130   /* Check the parameters */
00131   assert_param(IS_USART_ALL_PERIPH(USARTx));
00132 
00133   if (USARTx == USART1)
00134   {
00135     RCC_APB2PeriphResetCmd(RCC_APB2Periph_USART1, ENABLE);
00136     RCC_APB2PeriphResetCmd(RCC_APB2Periph_USART1, DISABLE);
00137   }
00138   else if (USARTx == USART2)
00139   {
00140     RCC_APB1PeriphResetCmd(RCC_APB1Periph_USART2, ENABLE);
00141     RCC_APB1PeriphResetCmd(RCC_APB1Periph_USART2, DISABLE);
00142   }
00143   else if (USARTx == USART3)
00144   {
00145     RCC_APB1PeriphResetCmd(RCC_APB1Periph_USART3, ENABLE);
00146     RCC_APB1PeriphResetCmd(RCC_APB1Periph_USART3, DISABLE);
00147   }    
00148   else if (USARTx == UART4)
00149   {
00150     RCC_APB1PeriphResetCmd(RCC_APB1Periph_UART4, ENABLE);
00151     RCC_APB1PeriphResetCmd(RCC_APB1Periph_UART4, DISABLE);
00152   }    
00153   else
00154   {
00155     if (USARTx == UART5)
00156     { 
00157       RCC_APB1PeriphResetCmd(RCC_APB1Periph_UART5, ENABLE);
00158       RCC_APB1PeriphResetCmd(RCC_APB1Periph_UART5, DISABLE);
00159     }
00160   }
00161 }
00162 
00163 /**
00164   * @brief  Initializes the USARTx peripheral according to the specified
00165   *   parameters in the USART_InitStruct .
00166   * @param  USARTx: Select the USART or the UART peripheral. 
00167   *   This parameter can be one of the following values:
00168   *   USART1, USART2, USART3, UART4 or UART5.
00169   * @param  USART_InitStruct: pointer to a USART_InitTypeDef structure
00170   *   that contains the configuration information for the specified USART peripheral.
00171   * @retval None
00172   */
00173 void USART_Init(USART_TypeDef* USARTx, USART_InitTypeDef* USART_InitStruct)
00174 {
00175   uint32_t tmpreg = 0x00, apbclock = 0x00;
00176   uint32_t integerdivider = 0x00;
00177   uint32_t fractionaldivider = 0x00;
00178   uint32_t usartxbase = 0;
00179   RCC_ClocksTypeDef RCC_ClocksStatus;
00180   /* Check the parameters */
00181   assert_param(IS_USART_ALL_PERIPH(USARTx));
00182   assert_param(IS_USART_BAUDRATE(USART_InitStruct->USART_BaudRate));  
00183   assert_param(IS_USART_WORD_LENGTH(USART_InitStruct->USART_WordLength));
00184   assert_param(IS_USART_STOPBITS(USART_InitStruct->USART_StopBits));
00185   assert_param(IS_USART_PARITY(USART_InitStruct->USART_Parity));
00186   assert_param(IS_USART_MODE(USART_InitStruct->USART_Mode));
00187   assert_param(IS_USART_HARDWARE_FLOW_CONTROL(USART_InitStruct->USART_HardwareFlowControl));
00188   /* The hardware flow control is available only for USART1, USART2 and USART3 */
00189   if (USART_InitStruct->USART_HardwareFlowControl != USART_HardwareFlowControl_None)
00190   {
00191     assert_param(IS_USART_123_PERIPH(USARTx));
00192   }
00193 
00194   usartxbase = (uint32_t)USARTx;
00195 
00196 /*---------------------------- USART CR2 Configuration -----------------------*/
00197   tmpreg = USARTx->CR2;
00198   /* Clear STOP[13:12] bits */
00199   tmpreg &= CR2_STOP_CLEAR_Mask;
00200   /* Configure the USART Stop Bits, Clock, CPOL, CPHA and LastBit ------------*/
00201   /* Set STOP[13:12] bits according to USART_StopBits value */
00202   tmpreg |= (uint32_t)USART_InitStruct->USART_StopBits;
00203   
00204   /* Write to USART CR2 */
00205   USARTx->CR2 = (uint16_t)tmpreg;
00206 
00207 /*---------------------------- USART CR1 Configuration -----------------------*/
00208   tmpreg = USARTx->CR1;
00209   /* Clear M, PCE, PS, TE and RE bits */
00210   tmpreg &= CR1_CLEAR_Mask;
00211   /* Configure the USART Word Length, Parity and mode ----------------------- */
00212   /* Set the M bits according to USART_WordLength value */
00213   /* Set PCE and PS bits according to USART_Parity value */
00214   /* Set TE and RE bits according to USART_Mode value */
00215   tmpreg |= (uint32_t)USART_InitStruct->USART_WordLength | USART_InitStruct->USART_Parity |
00216             USART_InitStruct->USART_Mode;
00217   /* Write to USART CR1 */
00218   USARTx->CR1 = (uint16_t)tmpreg;
00219 
00220 /*---------------------------- USART CR3 Configuration -----------------------*/  
00221   tmpreg = USARTx->CR3;
00222   /* Clear CTSE and RTSE bits */
00223   tmpreg &= CR3_CLEAR_Mask;
00224   /* Configure the USART HFC -------------------------------------------------*/
00225   /* Set CTSE and RTSE bits according to USART_HardwareFlowControl value */
00226   tmpreg |= USART_InitStruct->USART_HardwareFlowControl;
00227   /* Write to USART CR3 */
00228   USARTx->CR3 = (uint16_t)tmpreg;
00229 
00230 /*---------------------------- USART BRR Configuration -----------------------*/
00231   /* Configure the USART Baud Rate -------------------------------------------*/
00232   RCC_GetClocksFreq(&RCC_ClocksStatus);
00233   if (usartxbase == USART1_BASE)
00234   {
00235     apbclock = RCC_ClocksStatus.PCLK2_Frequency;
00236   }
00237   else
00238   {
00239     apbclock = RCC_ClocksStatus.PCLK1_Frequency;
00240   }
00241   
00242   /* Determine the integer part */
00243   if ((USARTx->CR1 & CR1_OVER8_Set) != 0)
00244   {
00245     /* Integer part computing in case Oversampling mode is 8 Samples */
00246     integerdivider = ((25 * apbclock) / (2 * (USART_InitStruct->USART_BaudRate)));    
00247   }
00248   else /* if ((USARTx->CR1 & CR1_OVER8_Set) == 0) */
00249   {
00250     /* Integer part computing in case Oversampling mode is 16 Samples */
00251     integerdivider = ((25 * apbclock) / (4 * (USART_InitStruct->USART_BaudRate)));    
00252   }
00253   tmpreg = (integerdivider / 100) << 4;
00254 
00255   /* Determine the fractional part */
00256   fractionaldivider = integerdivider - (100 * (tmpreg >> 4));
00257 
00258   /* Implement the fractional part in the register */
00259   if ((USARTx->CR1 & CR1_OVER8_Set) != 0)
00260   {
00261     tmpreg |= ((((fractionaldivider * 8) + 50) / 100)) & ((uint8_t)0x07);
00262   }
00263   else /* if ((USARTx->CR1 & CR1_OVER8_Set) == 0) */
00264   {
00265     tmpreg |= ((((fractionaldivider * 16) + 50) / 100)) & ((uint8_t)0x0F);
00266   }
00267   
00268   /* Write to USART BRR */
00269   USARTx->BRR = (uint16_t)tmpreg;
00270 }
00271 
00272 /**
00273   * @brief  Fills each USART_InitStruct member with its default value.
00274   * @param  USART_InitStruct: pointer to a USART_InitTypeDef structure
00275   *   which will be initialized.
00276   * @retval None
00277   */
00278 void USART_StructInit(USART_InitTypeDef* USART_InitStruct)
00279 {
00280   /* USART_InitStruct members default value */
00281   USART_InitStruct->USART_BaudRate = 9600;
00282   USART_InitStruct->USART_WordLength = USART_WordLength_8b;
00283   USART_InitStruct->USART_StopBits = USART_StopBits_1;
00284   USART_InitStruct->USART_Parity = USART_Parity_No ;
00285   USART_InitStruct->USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
00286   USART_InitStruct->USART_HardwareFlowControl = USART_HardwareFlowControl_None;  
00287 }
00288 
00289 /**
00290   * @brief  Initializes the USARTx peripheral Clock according to the 
00291   *   specified parameters in the USART_ClockInitStruct .
00292   * @param  USARTx: where x can be 1, 2, 3 to select the USART peripheral.
00293   * @param  USART_ClockInitStruct: pointer to a USART_ClockInitTypeDef
00294   *   structure that contains the configuration information for the specified 
00295   *   USART peripheral.  
00296   * @note The Smart Card mode is not available for UART4 and UART5.
00297   * @retval None
00298   */
00299 void USART_ClockInit(USART_TypeDef* USARTx, USART_ClockInitTypeDef* USART_ClockInitStruct)
00300 {
00301   uint32_t tmpreg = 0x00;
00302   /* Check the parameters */
00303   assert_param(IS_USART_123_PERIPH(USARTx));
00304   assert_param(IS_USART_CLOCK(USART_ClockInitStruct->USART_Clock));
00305   assert_param(IS_USART_CPOL(USART_ClockInitStruct->USART_CPOL));
00306   assert_param(IS_USART_CPHA(USART_ClockInitStruct->USART_CPHA));
00307   assert_param(IS_USART_LASTBIT(USART_ClockInitStruct->USART_LastBit));
00308   
00309 /*---------------------------- USART CR2 Configuration -----------------------*/
00310   tmpreg = USARTx->CR2;
00311   /* Clear CLKEN, CPOL, CPHA and LBCL bits */
00312   tmpreg &= CR2_CLOCK_CLEAR_Mask;
00313   /* Configure the USART Clock, CPOL, CPHA and LastBit ------------*/
00314   /* Set CLKEN bit according to USART_Clock value */
00315   /* Set CPOL bit according to USART_CPOL value */
00316   /* Set CPHA bit according to USART_CPHA value */
00317   /* Set LBCL bit according to USART_LastBit value */
00318   tmpreg |= (uint32_t)USART_ClockInitStruct->USART_Clock | USART_ClockInitStruct->USART_CPOL | 
00319                  USART_ClockInitStruct->USART_CPHA | USART_ClockInitStruct->USART_LastBit;
00320   /* Write to USART CR2 */
00321   USARTx->CR2 = (uint16_t)tmpreg;
00322 }
00323 
00324 /**
00325   * @brief  Fills each USART_ClockInitStruct member with its default value.
00326   * @param  USART_ClockInitStruct: pointer to a USART_ClockInitTypeDef
00327   *   structure which will be initialized.
00328   * @retval None
00329   */
00330 void USART_ClockStructInit(USART_ClockInitTypeDef* USART_ClockInitStruct)
00331 {
00332   /* USART_ClockInitStruct members default value */
00333   USART_ClockInitStruct->USART_Clock = USART_Clock_Disable;
00334   USART_ClockInitStruct->USART_CPOL = USART_CPOL_Low;
00335   USART_ClockInitStruct->USART_CPHA = USART_CPHA_1Edge;
00336   USART_ClockInitStruct->USART_LastBit = USART_LastBit_Disable;
00337 }
00338 
00339 /**
00340   * @brief  Enables or disables the specified USART peripheral.
00341   * @param  USARTx: Select the USART or the UART peripheral. 
00342   *   This parameter can be one of the following values:
00343   *   USART1, USART2, USART3, UART4 or UART5.
00344   * @param  NewState: new state of the USARTx peripheral.
00345   *   This parameter can be: ENABLE or DISABLE.
00346   * @retval None
00347   */
00348 void USART_Cmd(USART_TypeDef* USARTx, FunctionalState NewState)
00349 {
00350   /* Check the parameters */
00351   assert_param(IS_USART_ALL_PERIPH(USARTx));
00352   assert_param(IS_FUNCTIONAL_STATE(NewState));
00353   
00354   if (NewState != DISABLE)
00355   {
00356     /* Enable the selected USART by setting the UE bit in the CR1 register */
00357     USARTx->CR1 |= CR1_UE_Set;
00358   }
00359   else
00360   {
00361     /* Disable the selected USART by clearing the UE bit in the CR1 register */
00362     USARTx->CR1 &= CR1_UE_Reset;
00363   }
00364 }
00365 
00366 /**
00367   * @brief  Enables or disables the specified USART interrupts.
00368   * @param  USARTx: Select the USART or the UART peripheral. 
00369   *   This parameter can be one of the following values:
00370   *   USART1, USART2, USART3, UART4 or UART5.
00371   * @param  USART_IT: specifies the USART interrupt sources to be enabled or disabled.
00372   *   This parameter can be one of the following values:
00373   *     @arg USART_IT_CTS:  CTS change interrupt (not available for UART4 and UART5)
00374   *     @arg USART_IT_LBD:  LIN Break detection interrupt
00375   *     @arg USART_IT_TXE:  Tansmit Data Register empty interrupt
00376   *     @arg USART_IT_TC:   Transmission complete interrupt
00377   *     @arg USART_IT_RXNE: Receive Data register not empty interrupt
00378   *     @arg USART_IT_IDLE: Idle line detection interrupt
00379   *     @arg USART_IT_PE:   Parity Error interrupt
00380   *     @arg USART_IT_ERR:  Error interrupt(Frame error, noise error, overrun error)
00381   * @param  NewState: new state of the specified USARTx interrupts.
00382   *   This parameter can be: ENABLE or DISABLE.
00383   * @retval None
00384   */
00385 void USART_ITConfig(USART_TypeDef* USARTx, uint16_t USART_IT, FunctionalState NewState)
00386 {
00387   uint32_t usartreg = 0x00, itpos = 0x00, itmask = 0x00;
00388   uint32_t usartxbase = 0x00;
00389   /* Check the parameters */
00390   assert_param(IS_USART_ALL_PERIPH(USARTx));
00391   assert_param(IS_USART_CONFIG_IT(USART_IT));
00392   assert_param(IS_FUNCTIONAL_STATE(NewState));
00393   /* The CTS interrupt is not available for UART4 and UART5 */
00394   if (USART_IT == USART_IT_CTS)
00395   {
00396     assert_param(IS_USART_123_PERIPH(USARTx));
00397   }   
00398   
00399   usartxbase = (uint32_t)USARTx;
00400 
00401   /* Get the USART register index */
00402   usartreg = (((uint8_t)USART_IT) >> 0x05);
00403 
00404   /* Get the interrupt position */
00405   itpos = USART_IT & IT_Mask;
00406   itmask = (((uint32_t)0x01) << itpos);
00407     
00408   if (usartreg == 0x01) /* The IT is in CR1 register */
00409   {
00410     usartxbase += 0x0C;
00411   }
00412   else if (usartreg == 0x02) /* The IT is in CR2 register */
00413   {
00414     usartxbase += 0x10;
00415   }
00416   else /* The IT is in CR3 register */
00417   {
00418     usartxbase += 0x14; 
00419   }
00420   if (NewState != DISABLE)
00421   {
00422     *(__IO uint32_t*)usartxbase  |= itmask;
00423   }
00424   else
00425   {
00426     *(__IO uint32_t*)usartxbase &= ~itmask;
00427   }
00428 }
00429 
00430 /**
00431   * @brief  Enables or disables the USARTís DMA interface.
00432   * @param  USARTx: Select the USART or the UART peripheral. 
00433   *   This parameter can be one of the following values:
00434   *   USART1, USART2, USART3, UART4 or UART5.
00435   * @param  USART_DMAReq: specifies the DMA request.
00436   *   This parameter can be any combination of the following values:
00437   *     @arg USART_DMAReq_Tx: USART DMA transmit request
00438   *     @arg USART_DMAReq_Rx: USART DMA receive request
00439   * @param  NewState: new state of the DMA Request sources.
00440   *   This parameter can be: ENABLE or DISABLE.
00441   * @note The DMA mode is not available for UART5 except in the STM32
00442   *       High density value line devices(STM32F10X_HD_VL).  
00443   * @retval None
00444   */
00445 void USART_DMACmd(USART_TypeDef* USARTx, uint16_t USART_DMAReq, FunctionalState NewState)
00446 {
00447   /* Check the parameters */
00448   assert_param(IS_USART_ALL_PERIPH(USARTx));
00449   assert_param(IS_USART_DMAREQ(USART_DMAReq));  
00450   assert_param(IS_FUNCTIONAL_STATE(NewState)); 
00451   if (NewState != DISABLE)
00452   {
00453     /* Enable the DMA transfer for selected requests by setting the DMAT and/or
00454        DMAR bits in the USART CR3 register */
00455     USARTx->CR3 |= USART_DMAReq;
00456   }
00457   else
00458   {
00459     /* Disable the DMA transfer for selected requests by clearing the DMAT and/or
00460        DMAR bits in the USART CR3 register */
00461     USARTx->CR3 &= (uint16_t)~USART_DMAReq;
00462   }
00463 }
00464 
00465 /**
00466   * @brief  Sets the address of the USART node.
00467   * @param  USARTx: Select the USART or the UART peripheral. 
00468   *   This parameter can be one of the following values:
00469   *   USART1, USART2, USART3, UART4 or UART5.
00470   * @param  USART_Address: Indicates the address of the USART node.
00471   * @retval None
00472   */
00473 void USART_SetAddress(USART_TypeDef* USARTx, uint8_t USART_Address)
00474 {
00475   /* Check the parameters */
00476   assert_param(IS_USART_ALL_PERIPH(USARTx));
00477   assert_param(IS_USART_ADDRESS(USART_Address)); 
00478     
00479   /* Clear the USART address */
00480   USARTx->CR2 &= CR2_Address_Mask;
00481   /* Set the USART address node */
00482   USARTx->CR2 |= USART_Address;
00483 }
00484 
00485 /**
00486   * @brief  Selects the USART WakeUp method.
00487   * @param  USARTx: Select the USART or the UART peripheral. 
00488   *   This parameter can be one of the following values:
00489   *   USART1, USART2, USART3, UART4 or UART5.
00490   * @param  USART_WakeUp: specifies the USART wakeup method.
00491   *   This parameter can be one of the following values:
00492   *     @arg USART_WakeUp_IdleLine: WakeUp by an idle line detection
00493   *     @arg USART_WakeUp_AddressMark: WakeUp by an address mark
00494   * @retval None
00495   */
00496 void USART_WakeUpConfig(USART_TypeDef* USARTx, uint16_t USART_WakeUp)
00497 {
00498   /* Check the parameters */
00499   assert_param(IS_USART_ALL_PERIPH(USARTx));
00500   assert_param(IS_USART_WAKEUP(USART_WakeUp));
00501   
00502   USARTx->CR1 &= CR1_WAKE_Mask;
00503   USARTx->CR1 |= USART_WakeUp;
00504 }
00505 
00506 /**
00507   * @brief  Determines if the USART is in mute mode or not.
00508   * @param  USARTx: Select the USART or the UART peripheral. 
00509   *   This parameter can be one of the following values:
00510   *   USART1, USART2, USART3, UART4 or UART5.
00511   * @param  NewState: new state of the USART mute mode.
00512   *   This parameter can be: ENABLE or DISABLE.
00513   * @retval None
00514   */
00515 void USART_ReceiverWakeUpCmd(USART_TypeDef* USARTx, FunctionalState NewState)
00516 {
00517   /* Check the parameters */
00518   assert_param(IS_USART_ALL_PERIPH(USARTx));
00519   assert_param(IS_FUNCTIONAL_STATE(NewState)); 
00520   
00521   if (NewState != DISABLE)
00522   {
00523     /* Enable the USART mute mode  by setting the RWU bit in the CR1 register */
00524     USARTx->CR1 |= CR1_RWU_Set;
00525   }
00526   else
00527   {
00528     /* Disable the USART mute mode by clearing the RWU bit in the CR1 register */
00529     USARTx->CR1 &= CR1_RWU_Reset;
00530   }
00531 }
00532 
00533 /**
00534   * @brief  Sets the USART LIN Break detection length.
00535   * @param  USARTx: Select the USART or the UART peripheral. 
00536   *   This parameter can be one of the following values:
00537   *   USART1, USART2, USART3, UART4 or UART5.
00538   * @param  USART_LINBreakDetectLength: specifies the LIN break detection length.
00539   *   This parameter can be one of the following values:
00540   *     @arg USART_LINBreakDetectLength_10b: 10-bit break detection
00541   *     @arg USART_LINBreakDetectLength_11b: 11-bit break detection
00542   * @retval None
00543   */
00544 void USART_LINBreakDetectLengthConfig(USART_TypeDef* USARTx, uint16_t USART_LINBreakDetectLength)
00545 {
00546   /* Check the parameters */
00547   assert_param(IS_USART_ALL_PERIPH(USARTx));
00548   assert_param(IS_USART_LIN_BREAK_DETECT_LENGTH(USART_LINBreakDetectLength));
00549   
00550   USARTx->CR2 &= CR2_LBDL_Mask;
00551   USARTx->CR2 |= USART_LINBreakDetectLength;  
00552 }
00553 
00554 /**
00555   * @brief  Enables or disables the USARTís LIN mode.
00556   * @param  USARTx: Select the USART or the UART peripheral. 
00557   *   This parameter can be one of the following values:
00558   *   USART1, USART2, USART3, UART4 or UART5.
00559   * @param  NewState: new state of the USART LIN mode.
00560   *   This parameter can be: ENABLE or DISABLE.
00561   * @retval None
00562   */
00563 void USART_LINCmd(USART_TypeDef* USARTx, FunctionalState NewState)
00564 {
00565   /* Check the parameters */
00566   assert_param(IS_USART_ALL_PERIPH(USARTx));
00567   assert_param(IS_FUNCTIONAL_STATE(NewState));
00568   
00569   if (NewState != DISABLE)
00570   {
00571     /* Enable the LIN mode by setting the LINEN bit in the CR2 register */
00572     USARTx->CR2 |= CR2_LINEN_Set;
00573   }
00574   else
00575   {
00576     /* Disable the LIN mode by clearing the LINEN bit in the CR2 register */
00577     USARTx->CR2 &= CR2_LINEN_Reset;
00578   }
00579 }
00580 
00581 /**
00582   * @brief  Transmits single data through the USARTx peripheral.
00583   * @param  USARTx: Select the USART or the UART peripheral. 
00584   *   This parameter can be one of the following values:
00585   *   USART1, USART2, USART3, UART4 or UART5.
00586   * @param  Data: the data to transmit.
00587   * @retval None
00588   */
00589 void USART_SendData(USART_TypeDef* USARTx, uint16_t Data)
00590 {
00591   /* Check the parameters */
00592   assert_param(IS_USART_ALL_PERIPH(USARTx));
00593   assert_param(IS_USART_DATA(Data)); 
00594     
00595   /* Transmit Data */
00596   USARTx->DR = (Data & (uint16_t)0x01FF);
00597 }
00598 
00599 /**
00600   * @brief  Returns the most recent received data by the USARTx peripheral.
00601   * @param  USARTx: Select the USART or the UART peripheral. 
00602   *   This parameter can be one of the following values:
00603   *   USART1, USART2, USART3, UART4 or UART5.
00604   * @retval The received data.
00605   */
00606 uint16_t USART_ReceiveData(USART_TypeDef* USARTx)
00607 {
00608   /* Check the parameters */
00609   assert_param(IS_USART_ALL_PERIPH(USARTx));
00610   
00611   /* Receive Data */
00612   return (uint16_t)(USARTx->DR & (uint16_t)0x01FF);
00613 }
00614 
00615 /**
00616   * @brief  Transmits break characters.
00617   * @param  USARTx: Select the USART or the UART peripheral. 
00618   *   This parameter can be one of the following values:
00619   *   USART1, USART2, USART3, UART4 or UART5.
00620   * @retval None
00621   */
00622 void USART_SendBreak(USART_TypeDef* USARTx)
00623 {
00624   /* Check the parameters */
00625   assert_param(IS_USART_ALL_PERIPH(USARTx));
00626   
00627   /* Send break characters */
00628   USARTx->CR1 |= CR1_SBK_Set;
00629 }
00630 
00631 /**
00632   * @brief  Sets the specified USART guard time.
00633   * @param  USARTx: where x can be 1, 2 or 3 to select the USART peripheral.
00634   * @param  USART_GuardTime: specifies the guard time.
00635   * @note The guard time bits are not available for UART4 and UART5.   
00636   * @retval None
00637   */
00638 void USART_SetGuardTime(USART_TypeDef* USARTx, uint8_t USART_GuardTime)
00639 {    
00640   /* Check the parameters */
00641   assert_param(IS_USART_123_PERIPH(USARTx));
00642   
00643   /* Clear the USART Guard time */
00644   USARTx->GTPR &= GTPR_LSB_Mask;
00645   /* Set the USART guard time */
00646   USARTx->GTPR |= (uint16_t)((uint16_t)USART_GuardTime << 0x08);
00647 }
00648 
00649 /**
00650   * @brief  Sets the system clock prescaler.
00651   * @param  USARTx: Select the USART or the UART peripheral. 
00652   *   This parameter can be one of the following values:
00653   *   USART1, USART2, USART3, UART4 or UART5.
00654   * @param  USART_Prescaler: specifies the prescaler clock.  
00655   * @note   The function is used for IrDA mode with UART4 and UART5.
00656   * @retval None
00657   */
00658 void USART_SetPrescaler(USART_TypeDef* USARTx, uint8_t USART_Prescaler)
00659 { 
00660   /* Check the parameters */
00661   assert_param(IS_USART_ALL_PERIPH(USARTx));
00662   
00663   /* Clear the USART prescaler */
00664   USARTx->GTPR &= GTPR_MSB_Mask;
00665   /* Set the USART prescaler */
00666   USARTx->GTPR |= USART_Prescaler;
00667 }
00668 
00669 /**
00670   * @brief  Enables or disables the USARTís Smart Card mode.
00671   * @param  USARTx: where x can be 1, 2 or 3 to select the USART peripheral.
00672   * @param  NewState: new state of the Smart Card mode.
00673   *   This parameter can be: ENABLE or DISABLE.     
00674   * @note The Smart Card mode is not available for UART4 and UART5. 
00675   * @retval None
00676   */
00677 void USART_SmartCardCmd(USART_TypeDef* USARTx, FunctionalState NewState)
00678 {
00679   /* Check the parameters */
00680   assert_param(IS_USART_123_PERIPH(USARTx));
00681   assert_param(IS_FUNCTIONAL_STATE(NewState));
00682   if (NewState != DISABLE)
00683   {
00684     /* Enable the SC mode by setting the SCEN bit in the CR3 register */
00685     USARTx->CR3 |= CR3_SCEN_Set;
00686   }
00687   else
00688   {
00689     /* Disable the SC mode by clearing the SCEN bit in the CR3 register */
00690     USARTx->CR3 &= CR3_SCEN_Reset;
00691   }
00692 }
00693 
00694 /**
00695   * @brief  Enables or disables NACK transmission.
00696   * @param  USARTx: where x can be 1, 2 or 3 to select the USART peripheral. 
00697   * @param  NewState: new state of the NACK transmission.
00698   *   This parameter can be: ENABLE or DISABLE.  
00699   * @note The Smart Card mode is not available for UART4 and UART5.
00700   * @retval None
00701   */
00702 void USART_SmartCardNACKCmd(USART_TypeDef* USARTx, FunctionalState NewState)
00703 {
00704   /* Check the parameters */
00705   assert_param(IS_USART_123_PERIPH(USARTx));  
00706   assert_param(IS_FUNCTIONAL_STATE(NewState));
00707   if (NewState != DISABLE)
00708   {
00709     /* Enable the NACK transmission by setting the NACK bit in the CR3 register */
00710     USARTx->CR3 |= CR3_NACK_Set;
00711   }
00712   else
00713   {
00714     /* Disable the NACK transmission by clearing the NACK bit in the CR3 register */
00715     USARTx->CR3 &= CR3_NACK_Reset;
00716   }
00717 }
00718 
00719 /**
00720   * @brief  Enables or disables the USARTís Half Duplex communication.
00721   * @param  USARTx: Select the USART or the UART peripheral. 
00722   *   This parameter can be one of the following values:
00723   *   USART1, USART2, USART3, UART4 or UART5.
00724   * @param  NewState: new state of the USART Communication.
00725   *   This parameter can be: ENABLE or DISABLE.
00726   * @retval None
00727   */
00728 void USART_HalfDuplexCmd(USART_TypeDef* USARTx, FunctionalState NewState)
00729 {
00730   /* Check the parameters */
00731   assert_param(IS_USART_ALL_PERIPH(USARTx));
00732   assert_param(IS_FUNCTIONAL_STATE(NewState));
00733   
00734   if (NewState != DISABLE)
00735   {
00736     /* Enable the Half-Duplex mode by setting the HDSEL bit in the CR3 register */
00737     USARTx->CR3 |= CR3_HDSEL_Set;
00738   }
00739   else
00740   {
00741     /* Disable the Half-Duplex mode by clearing the HDSEL bit in the CR3 register */
00742     USARTx->CR3 &= CR3_HDSEL_Reset;
00743   }
00744 }
00745 
00746 
00747 /**
00748   * @brief  Enables or disables the USART's 8x oversampling mode.
00749   * @param  USARTx: Select the USART or the UART peripheral.
00750   *   This parameter can be one of the following values:
00751   *   USART1, USART2, USART3, UART4 or UART5.
00752   * @param  NewState: new state of the USART one bit sampling methode.
00753   *   This parameter can be: ENABLE or DISABLE.
00754   * @note
00755   *     This function has to be called before calling USART_Init()
00756   *     function in order to have correct baudrate Divider value.   
00757   * @retval None
00758   */
00759 void USART_OverSampling8Cmd(USART_TypeDef* USARTx, FunctionalState NewState)
00760 {
00761   /* Check the parameters */
00762   assert_param(IS_USART_ALL_PERIPH(USARTx));
00763   assert_param(IS_FUNCTIONAL_STATE(NewState));
00764   
00765   if (NewState != DISABLE)
00766   {
00767     /* Enable the 8x Oversampling mode by setting the OVER8 bit in the CR1 register */
00768     USARTx->CR1 |= CR1_OVER8_Set;
00769   }
00770   else
00771   {
00772     /* Disable the 8x Oversampling mode by clearing the OVER8 bit in the CR1 register */
00773     USARTx->CR1 &= CR1_OVER8_Reset;
00774   }
00775 }
00776 
00777 /**
00778   * @brief  Enables or disables the USART's one bit sampling methode.
00779   * @param  USARTx: Select the USART or the UART peripheral.
00780   *   This parameter can be one of the following values:
00781   *   USART1, USART2, USART3, UART4 or UART5.
00782   * @param  NewState: new state of the USART one bit sampling methode.
00783   *   This parameter can be: ENABLE or DISABLE.
00784   * @retval None
00785   */
00786 void USART_OneBitMethodCmd(USART_TypeDef* USARTx, FunctionalState NewState)
00787 {
00788   /* Check the parameters */
00789   assert_param(IS_USART_ALL_PERIPH(USARTx));
00790   assert_param(IS_FUNCTIONAL_STATE(NewState));
00791   
00792   if (NewState != DISABLE)
00793   {
00794     /* Enable the one bit method by setting the ONEBITE bit in the CR3 register */
00795     USARTx->CR3 |= CR3_ONEBITE_Set;
00796   }
00797   else
00798   {
00799     /* Disable tthe one bit method by clearing the ONEBITE bit in the CR3 register */
00800     USARTx->CR3 &= CR3_ONEBITE_Reset;
00801   }
00802 }
00803 
00804 /**
00805   * @brief  Configures the USARTís IrDA interface.
00806   * @param  USARTx: Select the USART or the UART peripheral. 
00807   *   This parameter can be one of the following values:
00808   *   USART1, USART2, USART3, UART4 or UART5.
00809   * @param  USART_IrDAMode: specifies the IrDA mode.
00810   *   This parameter can be one of the following values:
00811   *     @arg USART_IrDAMode_LowPower
00812   *     @arg USART_IrDAMode_Normal
00813   * @retval None
00814   */
00815 void USART_IrDAConfig(USART_TypeDef* USARTx, uint16_t USART_IrDAMode)
00816 {
00817   /* Check the parameters */
00818   assert_param(IS_USART_ALL_PERIPH(USARTx));
00819   assert_param(IS_USART_IRDA_MODE(USART_IrDAMode));
00820     
00821   USARTx->CR3 &= CR3_IRLP_Mask;
00822   USARTx->CR3 |= USART_IrDAMode;
00823 }
00824 
00825 /**
00826   * @brief  Enables or disables the USARTís IrDA interface.
00827   * @param  USARTx: Select the USART or the UART peripheral. 
00828   *   This parameter can be one of the following values:
00829   *   USART1, USART2, USART3, UART4 or UART5.
00830   * @param  NewState: new state of the IrDA mode.
00831   *   This parameter can be: ENABLE or DISABLE.
00832   * @retval None
00833   */
00834 void USART_IrDACmd(USART_TypeDef* USARTx, FunctionalState NewState)
00835 {
00836   /* Check the parameters */
00837   assert_param(IS_USART_ALL_PERIPH(USARTx));
00838   assert_param(IS_FUNCTIONAL_STATE(NewState));
00839     
00840   if (NewState != DISABLE)
00841   {
00842     /* Enable the IrDA mode by setting the IREN bit in the CR3 register */
00843     USARTx->CR3 |= CR3_IREN_Set;
00844   }
00845   else
00846   {
00847     /* Disable the IrDA mode by clearing the IREN bit in the CR3 register */
00848     USARTx->CR3 &= CR3_IREN_Reset;
00849   }
00850 }
00851 
00852 /**
00853   * @brief  Checks whether the specified USART flag is set or not.
00854   * @param  USARTx: Select the USART or the UART peripheral. 
00855   *   This parameter can be one of the following values:
00856   *   USART1, USART2, USART3, UART4 or UART5.
00857   * @param  USART_FLAG: specifies the flag to check.
00858   *   This parameter can be one of the following values:
00859   *     @arg USART_FLAG_CTS:  CTS Change flag (not available for UART4 and UART5)
00860   *     @arg USART_FLAG_LBD:  LIN Break detection flag
00861   *     @arg USART_FLAG_TXE:  Transmit data register empty flag
00862   *     @arg USART_FLAG_TC:   Transmission Complete flag
00863   *     @arg USART_FLAG_RXNE: Receive data register not empty flag
00864   *     @arg USART_FLAG_IDLE: Idle Line detection flag
00865   *     @arg USART_FLAG_ORE:  OverRun Error flag
00866   *     @arg USART_FLAG_NE:   Noise Error flag
00867   *     @arg USART_FLAG_FE:   Framing Error flag
00868   *     @arg USART_FLAG_PE:   Parity Error flag
00869   * @retval The new state of USART_FLAG (SET or RESET).
00870   */
00871 FlagStatus USART_GetFlagStatus(USART_TypeDef* USARTx, uint16_t USART_FLAG)
00872 {
00873   FlagStatus bitstatus = RESET;
00874   /* Check the parameters */
00875   assert_param(IS_USART_ALL_PERIPH(USARTx));
00876   assert_param(IS_USART_FLAG(USART_FLAG));
00877   /* The CTS flag is not available for UART4 and UART5 */
00878   if (USART_FLAG == USART_FLAG_CTS)
00879   {
00880     assert_param(IS_USART_123_PERIPH(USARTx));
00881   }  
00882   
00883   if ((USARTx->SR & USART_FLAG) != (uint16_t)RESET)
00884   {
00885     bitstatus = SET;
00886   }
00887   else
00888   {
00889     bitstatus = RESET;
00890   }
00891   return bitstatus;
00892 }
00893 
00894 /**
00895   * @brief  Clears the USARTx's pending flags.
00896   * @param  USARTx: Select the USART or the UART peripheral. 
00897   *   This parameter can be one of the following values:
00898   *   USART1, USART2, USART3, UART4 or UART5.
00899   * @param  USART_FLAG: specifies the flag to clear.
00900   *   This parameter can be any combination of the following values:
00901   *     @arg USART_FLAG_CTS:  CTS Change flag (not available for UART4 and UART5).
00902   *     @arg USART_FLAG_LBD:  LIN Break detection flag.
00903   *     @arg USART_FLAG_TC:   Transmission Complete flag.
00904   *     @arg USART_FLAG_RXNE: Receive data register not empty flag.
00905   *   
00906   * @note
00907   *   - PE (Parity error), FE (Framing error), NE (Noise error), ORE (OverRun 
00908   *     error) and IDLE (Idle line detected) flags are cleared by software 
00909   *     sequence: a read operation to USART_SR register (USART_GetFlagStatus()) 
00910   *     followed by a read operation to USART_DR register (USART_ReceiveData()).
00911   *   - RXNE flag can be also cleared by a read to the USART_DR register 
00912   *     (USART_ReceiveData()).
00913   *   - TC flag can be also cleared by software sequence: a read operation to 
00914   *     USART_SR register (USART_GetFlagStatus()) followed by a write operation
00915   *     to USART_DR register (USART_SendData()).
00916   *   - TXE flag is cleared only by a write to the USART_DR register 
00917   *     (USART_SendData()).
00918   * @retval None
00919   */
00920 void USART_ClearFlag(USART_TypeDef* USARTx, uint16_t USART_FLAG)
00921 {
00922   /* Check the parameters */
00923   assert_param(IS_USART_ALL_PERIPH(USARTx));
00924   assert_param(IS_USART_CLEAR_FLAG(USART_FLAG));
00925   /* The CTS flag is not available for UART4 and UART5 */
00926   if ((USART_FLAG & USART_FLAG_CTS) == USART_FLAG_CTS)
00927   {
00928     assert_param(IS_USART_123_PERIPH(USARTx));
00929   } 
00930    
00931   USARTx->SR = (uint16_t)~USART_FLAG;
00932 }
00933 
00934 /**
00935   * @brief  Checks whether the specified USART interrupt has occurred or not.
00936   * @param  USARTx: Select the USART or the UART peripheral. 
00937   *   This parameter can be one of the following values:
00938   *   USART1, USART2, USART3, UART4 or UART5.
00939   * @param  USART_IT: specifies the USART interrupt source to check.
00940   *   This parameter can be one of the following values:
00941   *     @arg USART_IT_CTS:  CTS change interrupt (not available for UART4 and UART5)
00942   *     @arg USART_IT_LBD:  LIN Break detection interrupt
00943   *     @arg USART_IT_TXE:  Tansmit Data Register empty interrupt
00944   *     @arg USART_IT_TC:   Transmission complete interrupt
00945   *     @arg USART_IT_RXNE: Receive Data register not empty interrupt
00946   *     @arg USART_IT_IDLE: Idle line detection interrupt
00947   *     @arg USART_IT_ORE:  OverRun Error interrupt
00948   *     @arg USART_IT_NE:   Noise Error interrupt
00949   *     @arg USART_IT_FE:   Framing Error interrupt
00950   *     @arg USART_IT_PE:   Parity Error interrupt
00951   * @retval The new state of USART_IT (SET or RESET).
00952   */
00953 ITStatus USART_GetITStatus(USART_TypeDef* USARTx, uint16_t USART_IT)
00954 {
00955   uint32_t bitpos = 0x00, itmask = 0x00, usartreg = 0x00;
00956   ITStatus bitstatus = RESET;
00957   /* Check the parameters */
00958   assert_param(IS_USART_ALL_PERIPH(USARTx));
00959   assert_param(IS_USART_GET_IT(USART_IT));
00960   /* The CTS interrupt is not available for UART4 and UART5 */ 
00961   if (USART_IT == USART_IT_CTS)
00962   {
00963     assert_param(IS_USART_123_PERIPH(USARTx));
00964   }   
00965   
00966   /* Get the USART register index */
00967   usartreg = (((uint8_t)USART_IT) >> 0x05);
00968   /* Get the interrupt position */
00969   itmask = USART_IT & IT_Mask;
00970   itmask = (uint32_t)0x01 << itmask;
00971   
00972   if (usartreg == 0x01) /* The IT  is in CR1 register */
00973   {
00974     itmask &= USARTx->CR1;
00975   }
00976   else if (usartreg == 0x02) /* The IT  is in CR2 register */
00977   {
00978     itmask &= USARTx->CR2;
00979   }
00980   else /* The IT  is in CR3 register */
00981   {
00982     itmask &= USARTx->CR3;
00983   }
00984   
00985   bitpos = USART_IT >> 0x08;
00986   bitpos = (uint32_t)0x01 << bitpos;
00987   bitpos &= USARTx->SR;
00988   if ((itmask != (uint16_t)RESET)&&(bitpos != (uint16_t)RESET))
00989   {
00990     bitstatus = SET;
00991   }
00992   else
00993   {
00994     bitstatus = RESET;
00995   }
00996   
00997   return bitstatus;  
00998 }
00999 
01000 /**
01001   * @brief  Clears the USARTxís interrupt pending bits.
01002   * @param  USARTx: Select the USART or the UART peripheral. 
01003   *   This parameter can be one of the following values:
01004   *   USART1, USART2, USART3, UART4 or UART5.
01005   * @param  USART_IT: specifies the interrupt pending bit to clear.
01006   *   This parameter can be one of the following values:
01007   *     @arg USART_IT_CTS:  CTS change interrupt (not available for UART4 and UART5)
01008   *     @arg USART_IT_LBD:  LIN Break detection interrupt
01009   *     @arg USART_IT_TC:   Transmission complete interrupt. 
01010   *     @arg USART_IT_RXNE: Receive Data register not empty interrupt.
01011   *   
01012   * @note
01013   *   - PE (Parity error), FE (Framing error), NE (Noise error), ORE (OverRun 
01014   *     error) and IDLE (Idle line detected) pending bits are cleared by 
01015   *     software sequence: a read operation to USART_SR register 
01016   *     (USART_GetITStatus()) followed by a read operation to USART_DR register 
01017   *     (USART_ReceiveData()).
01018   *   - RXNE pending bit can be also cleared by a read to the USART_DR register 
01019   *     (USART_ReceiveData()).
01020   *   - TC pending bit can be also cleared by software sequence: a read 
01021   *     operation to USART_SR register (USART_GetITStatus()) followed by a write 
01022   *     operation to USART_DR register (USART_SendData()).
01023   *   - TXE pending bit is cleared only by a write to the USART_DR register 
01024   *     (USART_SendData()).
01025   * @retval None
01026   */
01027 void USART_ClearITPendingBit(USART_TypeDef* USARTx, uint16_t USART_IT)
01028 {
01029   uint16_t bitpos = 0x00, itmask = 0x00;
01030   /* Check the parameters */
01031   assert_param(IS_USART_ALL_PERIPH(USARTx));
01032   assert_param(IS_USART_CLEAR_IT(USART_IT));
01033   /* The CTS interrupt is not available for UART4 and UART5 */
01034   if (USART_IT == USART_IT_CTS)
01035   {
01036     assert_param(IS_USART_123_PERIPH(USARTx));
01037   }   
01038   
01039   bitpos = USART_IT >> 0x08;
01040   itmask = ((uint16_t)0x01 << (uint16_t)bitpos);
01041   USARTx->SR = (uint16_t)~itmask;
01042 }
01043 /**
01044   * @}
01045   */
01046 
01047 /**
01048   * @}
01049   */
01050 
01051 /**
01052   * @}
01053   */
01054 
01055 /******************* (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