STM8S/A Standard Peripherals Drivers: stm8s_uart1.h Source File

STM8S/A

stm8s_uart1.h
Go to the documentation of this file.
00001 /**
00002   ********************************************************************************
00003   * @file    stm8s_uart1.h
00004   * @author  MCD Application Team
00005   * @version V2.3.0
00006   * @date    16-June-2017
00007   * @brief   This file contains all functions prototypes and macros for the UART1 peripheral.
00008    ******************************************************************************
00009   * @attention
00010   *
00011   * <h2><center>&copy; COPYRIGHT 2014 STMicroelectronics</center></h2>
00012   *
00013   * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
00014   * You may not use this file except in compliance with the License.
00015   * You may obtain a copy of the License at:
00016   *
00017   *        http://www.st.com/software_license_agreement_liberty_v2
00018   *
00019   * Unless required by applicable law or agreed to in writing, software 
00020   * distributed under the License is distributed on an "AS IS" BASIS, 
00021   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00022   * See the License for the specific language governing permissions and
00023   * limitations under the License.
00024   *
00025   ******************************************************************************
00026   */
00027 
00028 /* Define to prevent recursive inclusion -------------------------------------*/
00029 #ifndef __STM8S_UART1_H
00030 #define __STM8S_UART1_H
00031 
00032 /* Includes ------------------------------------------------------------------*/
00033 #include "stm8s.h"
00034 
00035 /** @addtogroup STM8S_StdPeriph_Driver
00036   * @{
00037   */
00038 
00039 /* Exported types ------------------------------------------------------------*/
00040 
00041 /** @addtogroup UART1_Exported_Types
00042   * @{
00043   */
00044 
00045 
00046 /**
00047   * @brief  UART1 Irda Modes
00048   */
00049 
00050 typedef enum { UART1_IRDAMODE_NORMAL    = (uint8_t)0x00, /**< 0x00 Irda Normal Mode   */
00051                UART1_IRDAMODE_LOWPOWER  = (uint8_t)0x01  /**< 0x01 Irda Low Power Mode */
00052              } UART1_IrDAMode_TypeDef;
00053 
00054 /**
00055   * @brief  UART1 WakeUP Modes
00056   */
00057 typedef enum { UART1_WAKEUP_IDLELINE       = (uint8_t)0x00, /**< 0x01 Idle Line wake up                */
00058                UART1_WAKEUP_ADDRESSMARK    = (uint8_t)0x08  /**< 0x02 Address Mark wake up          */
00059              } UART1_WakeUp_TypeDef;
00060 
00061 /**
00062   * @brief  UART1 LIN Break detection length possible values
00063   */
00064 typedef enum { UART1_LINBREAKDETECTIONLENGTH_10BITS = (uint8_t)0x00, /**< 0x01 10 bits Lin Break detection            */
00065                UART1_LINBREAKDETECTIONLENGTH_11BITS = (uint8_t)0x01  /**< 0x02 11 bits Lin Break detection          */
00066              } UART1_LINBreakDetectionLength_TypeDef;
00067 
00068 /**
00069   * @brief  UART1 stop bits possible values
00070   */
00071 
00072 typedef enum { UART1_STOPBITS_1   = (uint8_t)0x00,    /**< One stop bit is  transmitted at the end of frame*/
00073                UART1_STOPBITS_0_5 = (uint8_t)0x10,    /**< Half stop bits is transmitted at the end of frame*/
00074                UART1_STOPBITS_2   = (uint8_t)0x20,    /**< Two stop bits are  transmitted at the end of frame*/
00075                UART1_STOPBITS_1_5 = (uint8_t)0x30     /**< One and half stop bits*/
00076              } UART1_StopBits_TypeDef;
00077 
00078 /**
00079   * @brief  UART1 parity possible values
00080   */
00081 typedef enum { UART1_PARITY_NO     = (uint8_t)0x00,      /**< No Parity*/
00082                UART1_PARITY_EVEN   = (uint8_t)0x04,      /**< Even Parity*/
00083                UART1_PARITY_ODD    = (uint8_t)0x06       /**< Odd Parity*/
00084              } UART1_Parity_TypeDef;
00085 
00086 /**
00087   * @brief  UART1 Synchrone modes
00088   */
00089 typedef enum { UART1_SYNCMODE_CLOCK_DISABLE    = (uint8_t)0x80, /**< 0x80 Sync mode Disable, SLK pin Disable */
00090                UART1_SYNCMODE_CLOCK_ENABLE     = (uint8_t)0x08, /**< 0x08 Sync mode Enable, SLK pin Enable     */
00091                UART1_SYNCMODE_CPOL_LOW         = (uint8_t)0x40, /**< 0x40 Steady low value on SCLK pin outside transmission window */
00092                UART1_SYNCMODE_CPOL_HIGH        = (uint8_t)0x04, /**< 0x04 Steady high value on SCLK pin outside transmission window */
00093                UART1_SYNCMODE_CPHA_MIDDLE      = (uint8_t)0x20, /**< 0x20 SCLK clock line activated in middle of data bit     */
00094                UART1_SYNCMODE_CPHA_BEGINING    = (uint8_t)0x02, /**< 0x02 SCLK clock line activated at beginning of data bit  */
00095                UART1_SYNCMODE_LASTBIT_DISABLE  = (uint8_t)0x10, /**< 0x10 The clock pulse of the last data bit is not output to the SCLK pin */
00096                UART1_SYNCMODE_LASTBIT_ENABLE   = (uint8_t)0x01  /**< 0x01 The clock pulse of the last data bit is output to the SCLK pin */
00097              } UART1_SyncMode_TypeDef;
00098 
00099 /**
00100   * @brief  UART1 Word length possible values
00101   */
00102 typedef enum { UART1_WORDLENGTH_8D = (uint8_t)0x00,/**< 0x00 8 bits Data  */
00103                UART1_WORDLENGTH_9D = (uint8_t)0x10 /**< 0x10 9 bits Data  */
00104              } UART1_WordLength_TypeDef;
00105 
00106 /**
00107   * @brief  UART1 Mode possible values
00108   */
00109 typedef enum { UART1_MODE_RX_ENABLE     = (uint8_t)0x08,  /**< 0x08 Receive Enable */
00110                UART1_MODE_TX_ENABLE     = (uint8_t)0x04,  /**< 0x04 Transmit Enable */
00111                UART1_MODE_TX_DISABLE    = (uint8_t)0x80,  /**< 0x80 Transmit Disable */
00112                UART1_MODE_RX_DISABLE    = (uint8_t)0x40,  /**< 0x40 Single-wire Half-duplex mode */
00113                UART1_MODE_TXRX_ENABLE   = (uint8_t)0x0C  /**< 0x0C Transmit Enable and Receive Enable */
00114              } UART1_Mode_TypeDef;
00115 
00116 /**
00117   * @brief  UART1 Flag possible values
00118   */
00119 typedef enum { UART1_FLAG_TXE   = (uint16_t)0x0080, /*!< Transmit Data Register Empty flag */
00120                UART1_FLAG_TC    = (uint16_t)0x0040, /*!< Transmission Complete flag */
00121                UART1_FLAG_RXNE  = (uint16_t)0x0020, /*!< Read Data Register Not Empty flag */
00122                UART1_FLAG_IDLE  = (uint16_t)0x0010, /*!< Idle line detected flag */
00123                UART1_FLAG_OR    = (uint16_t)0x0008, /*!< OverRun error flag */
00124                UART1_FLAG_NF    = (uint16_t)0x0004, /*!< Noise error flag */
00125                UART1_FLAG_FE    = (uint16_t)0x0002, /*!< Framing Error flag */
00126                UART1_FLAG_PE    = (uint16_t)0x0001, /*!< Parity Error flag */
00127                UART1_FLAG_LBDF  = (uint16_t)0x0210, /*!< Line Break Detection Flag */
00128                UART1_FLAG_SBK   = (uint16_t)0x0101  /*!< Send Break characters Flag */
00129              } UART1_Flag_TypeDef;
00130 
00131 /**
00132   * @brief  UART1 Interrupt definition
00133   * UART1_IT possible values
00134   * Elements values convention: 0xZYX
00135   * X: Position of the corresponding Interrupt
00136   *   - For the following values, X means the interrupt position in the CR2 register.
00137   *     UART1_IT_TXE
00138   *     UART1_IT_TC
00139   *     UART1_IT_RXNE
00140   *     UART1_IT_IDLE 
00141   *     UART1_IT_OR 
00142   *   - For the UART1_IT_PE value, X means the flag position in the CR1 register.
00143   *   - For the UART1_IT_LBDF value, X means the flag position in the CR4 register.
00144   * Y: Flag position
00145   *  - For the following values, Y means the flag (pending bit) position in the SR register.
00146   *     UART1_IT_TXE
00147   *     UART1_IT_TC
00148   *     UART1_IT_RXNE
00149   *     UART1_IT_IDLE 
00150   *     UART1_IT_OR
00151   *     UART1_IT_PE
00152   *  - For the UART1_IT_LBDF value, Y means the flag position in the CR4 register.
00153   * Z: Register index: indicate in which register the dedicated interrupt source is:
00154   *  - 1==> CR1 register
00155   *  - 2==> CR2 register
00156   *  - 3==> CR4 register
00157   */
00158 typedef enum { UART1_IT_TXE        = (uint16_t)0x0277, /*!< Transmit interrupt */
00159                UART1_IT_TC         = (uint16_t)0x0266, /*!< Transmission Complete interrupt */
00160                UART1_IT_RXNE       = (uint16_t)0x0255, /*!< Receive interrupt */
00161                UART1_IT_IDLE       = (uint16_t)0x0244, /*!< IDLE line interrupt */
00162                UART1_IT_OR         = (uint16_t)0x0235, /*!< Overrun Error interrupt */
00163                UART1_IT_PE         = (uint16_t)0x0100, /*!< Parity Error interrupt */
00164                UART1_IT_LBDF       = (uint16_t)0x0346, /**< LIN break detection interrupt */
00165                UART1_IT_RXNE_OR    = (uint16_t)0x0205  /*!< Receive/Overrun interrupt */
00166              } UART1_IT_TypeDef;
00167 
00168 /**
00169   * @}
00170   */
00171 
00172 /* Exported constants --------------------------------------------------------*/
00173 /* Exported macros ------------------------------------------------------------*/
00174 
00175 /* Private macros ------------------------------------------------------------*/
00176 
00177 /** @addtogroup UART1_Private_Macros
00178   * @{
00179   */
00180 
00181 /**
00182   * @brief  Macro used by the assert function to check the different functions parameters.
00183   */
00184 
00185 /**
00186  * @brief Macro used by the assert_param function in order to check the different
00187  *        sensitivity values for the MODEs possible combination should be one of
00188  *        the following
00189  */
00190 #define IS_UART1_MODE_OK(Mode) \
00191   (((Mode) == (uint8_t)UART1_MODE_RX_ENABLE) || \
00192    ((Mode) == (uint8_t)UART1_MODE_RX_DISABLE) || \
00193    ((Mode) == (uint8_t)UART1_MODE_TX_ENABLE) || \
00194    ((Mode) == (uint8_t)UART1_MODE_TX_DISABLE) || \
00195    ((Mode) == (uint8_t)UART1_MODE_TXRX_ENABLE) || \
00196    ((Mode) == (uint8_t)((uint8_t)UART1_MODE_TX_ENABLE|(uint8_t)UART1_MODE_RX_ENABLE)) || \
00197    ((Mode) == (uint8_t)((uint8_t)UART1_MODE_TX_ENABLE|(uint8_t)UART1_MODE_RX_DISABLE)) || \
00198    ((Mode) == (uint8_t)((uint8_t)UART1_MODE_TX_DISABLE|(uint8_t)UART1_MODE_RX_DISABLE)) || \
00199    ((Mode) == (uint8_t)((uint8_t)UART1_MODE_TX_DISABLE|(uint8_t)UART1_MODE_RX_ENABLE)))
00200 
00201 /**
00202  * @brief Macro used by the assert_param function in order to check the different
00203  *        sensitivity values for the WordLengths
00204  */
00205 #define IS_UART1_WORDLENGTH_OK(WordLength) \
00206   (((WordLength) == UART1_WORDLENGTH_8D) || \
00207    ((WordLength) == UART1_WORDLENGTH_9D))
00208 
00209 /**
00210   * @brief  Macro used by the assert_param function in order to check the different
00211   *         sensitivity values for the SyncModes; it should exclude values such 
00212   *         as  UART1_CLOCK_ENABLE|UART1_CLOCK_DISABLE
00213   */
00214 #define IS_UART1_SYNCMODE_OK(SyncMode) \
00215   (!((((SyncMode)&(((uint8_t)UART1_SYNCMODE_CLOCK_ENABLE)|((uint8_t)UART1_SYNCMODE_CLOCK_DISABLE))) == (((uint8_t)UART1_SYNCMODE_CLOCK_ENABLE)|((uint8_t)UART1_SYNCMODE_CLOCK_DISABLE))) \
00216     || (((SyncMode)&(((uint8_t)UART1_SYNCMODE_CPOL_LOW )|((uint8_t)UART1_SYNCMODE_CPOL_HIGH))) == (((uint8_t)UART1_SYNCMODE_CPOL_LOW )|((uint8_t)UART1_SYNCMODE_CPOL_HIGH))) \
00217     ||(((SyncMode)&(((uint8_t)UART1_SYNCMODE_CPHA_MIDDLE)|((uint8_t)UART1_SYNCMODE_CPHA_BEGINING))) ==  (((uint8_t)UART1_SYNCMODE_CPHA_MIDDLE)|((uint8_t)UART1_SYNCMODE_CPHA_BEGINING))) \
00218     || (((SyncMode)&(((uint8_t)UART1_SYNCMODE_LASTBIT_DISABLE)|((uint8_t)UART1_SYNCMODE_LASTBIT_ENABLE))) == (((uint8_t)UART1_SYNCMODE_LASTBIT_DISABLE)|((uint8_t)UART1_SYNCMODE_LASTBIT_ENABLE)))))
00219 
00220 /**
00221   * @brief  Macro used by the assert_param function in order to check the different
00222   *         sensitivity values for the FLAGs
00223   */
00224 #define IS_UART1_FLAG_OK(Flag) \
00225   (((Flag) == UART1_FLAG_TXE) || \
00226    ((Flag) == UART1_FLAG_TC)  || \
00227    ((Flag) == UART1_FLAG_RXNE) || \
00228    ((Flag) == UART1_FLAG_IDLE) || \
00229    ((Flag) == UART1_FLAG_OR) || \
00230    ((Flag) == UART1_FLAG_NF) || \
00231    ((Flag) == UART1_FLAG_FE) || \
00232    ((Flag) == UART1_FLAG_PE) || \
00233    ((Flag) == UART1_FLAG_SBK) || \
00234    ((Flag) == UART1_FLAG_LBDF))
00235 /**
00236   * @brief  Macro used by the assert_param function in order to check the different
00237   *         sensitivity values for the FLAGs that can be cleared by writing 0
00238   */
00239 #define IS_UART1_CLEAR_FLAG_OK(Flag) \
00240   (((Flag) == UART1_FLAG_RXNE) || \
00241    ((Flag) == UART1_FLAG_LBDF))
00242 
00243 
00244 
00245 /**
00246   * @brief  Macro used by the assert_param function in order to check the different 
00247   *         sensitivity values for the Interrupts
00248   */
00249 
00250 #define IS_UART1_CONFIG_IT_OK(Interrupt) \
00251   (((Interrupt) == UART1_IT_PE) || \
00252    ((Interrupt) == UART1_IT_TXE) || \
00253    ((Interrupt) == UART1_IT_TC) || \
00254    ((Interrupt) == UART1_IT_RXNE_OR ) || \
00255    ((Interrupt) == UART1_IT_IDLE) || \
00256    ((Interrupt) == UART1_IT_LBDF))
00257 
00258 /**
00259   * @brief  Macro used by the assert function in order to check the different 
00260   *         sensitivity values for the pending bit
00261   */
00262 #define IS_UART1_GET_IT_OK(ITPendingBit) \
00263   (((ITPendingBit) == UART1_IT_TXE)  || \
00264    ((ITPendingBit) == UART1_IT_TC)   || \
00265    ((ITPendingBit) == UART1_IT_RXNE) || \
00266    ((ITPendingBit) == UART1_IT_IDLE) || \
00267    ((ITPendingBit) == UART1_IT_OR)  || \
00268    ((ITPendingBit) == UART1_IT_LBDF)  || \
00269    ((ITPendingBit) == UART1_IT_PE))
00270 
00271 /**
00272   * @brief  Macro used by the assert function in order to check the different 
00273   *         sensitivity values for the pending bit that can be cleared by writing 0
00274   */
00275 #define IS_UART1_CLEAR_IT_OK(ITPendingBit) \
00276   (((ITPendingBit) == UART1_IT_RXNE) || \
00277    ((ITPendingBit) == UART1_IT_LBDF))
00278 
00279 
00280 /**
00281  * @brief Macro used by the assert_param function in order to check the different
00282  *        sensitivity values for the IrDAModes
00283  */
00284 #define IS_UART1_IRDAMODE_OK(IrDAMode) \
00285   (((IrDAMode) == UART1_IRDAMODE_LOWPOWER) || \
00286    ((IrDAMode) == UART1_IRDAMODE_NORMAL))
00287 
00288 /**
00289   * @brief  Macro used by the assert_param function in order to check the different
00290   *         sensitivity values for the WakeUps
00291   */
00292 #define IS_UART1_WAKEUP_OK(WakeUp) \
00293   (((WakeUp) == UART1_WAKEUP_IDLELINE) || \
00294    ((WakeUp) == UART1_WAKEUP_ADDRESSMARK))
00295 
00296 /**
00297   * @brief  Macro used by the assert_param function in order to check the different 
00298   *        sensitivity values for the LINBreakDetectionLengths
00299   */
00300 #define IS_UART1_LINBREAKDETECTIONLENGTH_OK(LINBreakDetectionLength) \
00301   (((LINBreakDetectionLength) == UART1_LINBREAKDETECTIONLENGTH_10BITS) || \
00302    ((LINBreakDetectionLength) == UART1_LINBREAKDETECTIONLENGTH_11BITS))
00303 
00304 /**
00305   * @brief  Macro used by the assert_param function in order to check the different
00306   *         sensitivity values for the UART1_StopBits
00307   */
00308 #define IS_UART1_STOPBITS_OK(StopBit) (((StopBit) == UART1_STOPBITS_1) || \
00309                                        ((StopBit) == UART1_STOPBITS_0_5) || \
00310                                        ((StopBit) == UART1_STOPBITS_2) || \
00311                                        ((StopBit) == UART1_STOPBITS_1_5 ))
00312 
00313 /**
00314  * @brief Macro used by the assert_param function in order to check the different
00315  *        sensitivity values for the Parity
00316  */
00317 #define IS_UART1_PARITY_OK(Parity) (((Parity) == UART1_PARITY_NO) || \
00318                                     ((Parity) == UART1_PARITY_EVEN) || \
00319                                     ((Parity) == UART1_PARITY_ODD ))
00320 
00321 /**
00322  * @brief Macro used by the assert_param function in order to check the maximum
00323  *        baudrate value
00324  */
00325 #define IS_UART1_BAUDRATE_OK(NUM) ((NUM) <= (uint32_t)625000)
00326 
00327 
00328 /**
00329  * @brief Macro used by the assert_param function in order to check the address
00330  *        of the UART1 or UART node
00331  */
00332 #define UART1_ADDRESS_MAX ((uint8_t)16)
00333 #define IS_UART1_ADDRESS_OK(node) ((node) < UART1_ADDRESS_MAX )
00334 
00335 /**
00336   * @}
00337   */
00338 
00339 /* Exported functions ------------------------------------------------------- */
00340 
00341 /** @addtogroup UART1_Exported_Functions
00342   * @{
00343   */
00344 
00345 void UART1_DeInit(void);
00346 void UART1_Init(uint32_t BaudRate, UART1_WordLength_TypeDef WordLength, 
00347                 UART1_StopBits_TypeDef StopBits, UART1_Parity_TypeDef Parity, 
00348                 UART1_SyncMode_TypeDef SyncMode, UART1_Mode_TypeDef Mode);
00349 void UART1_Cmd(FunctionalState NewState);
00350 void UART1_ITConfig(UART1_IT_TypeDef UART1_IT, FunctionalState NewState);
00351 void UART1_HalfDuplexCmd(FunctionalState NewState);
00352 void UART1_IrDAConfig(UART1_IrDAMode_TypeDef UART1_IrDAMode);
00353 void UART1_IrDACmd(FunctionalState NewState);
00354 void UART1_LINBreakDetectionConfig(UART1_LINBreakDetectionLength_TypeDef UART1_LINBreakDetectionLength);
00355 void UART1_LINCmd(FunctionalState NewState);
00356 void UART1_SmartCardCmd(FunctionalState NewState);
00357 void UART1_SmartCardNACKCmd(FunctionalState NewState);
00358 void UART1_WakeUpConfig(UART1_WakeUp_TypeDef UART1_WakeUp);
00359 void UART1_ReceiverWakeUpCmd(FunctionalState NewState);
00360 uint8_t UART1_ReceiveData8(void);
00361 uint16_t UART1_ReceiveData9(void);
00362 void UART1_SendData8(uint8_t Data);
00363 void UART1_SendData9(uint16_t Data);
00364 void UART1_SendBreak(void);
00365 void UART1_SetAddress(uint8_t UART1_Address);
00366 void UART1_SetGuardTime(uint8_t UART1_GuardTime);
00367 void UART1_SetPrescaler(uint8_t UART1_Prescaler);
00368 FlagStatus UART1_GetFlagStatus(UART1_Flag_TypeDef UART1_FLAG);
00369 void UART1_ClearFlag(UART1_Flag_TypeDef UART1_FLAG);
00370 ITStatus UART1_GetITStatus(UART1_IT_TypeDef UART1_IT);
00371 void UART1_ClearITPendingBit(UART1_IT_TypeDef UART1_IT);
00372 
00373 /**
00374   * @}
00375   */
00376 
00377 #endif /* __STM8S_UART1_H */
00378 
00379 /**
00380   * @}
00381   */
00382 
00383 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
STM8 Standard Peripherals Library: Footer

 

 

 

      For complete documentation on STM8 8-bit Microcontrollers platform visit www.st.com