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

STM8S/A

stm8s_uart3.h
Go to the documentation of this file.
00001 /**
00002   ********************************************************************************
00003   * @file    stm8s_uart3.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 UART3 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_UART3_H
00030 #define __STM8S_UART3_H
00031 
00032 /* Includes ------------------------------------------------------------------*/
00033 #include "stm8s.h"
00034 
00035 /** @addtogroup STM8S_StdPeriph_Driver
00036   * @{
00037   */
00038 
00039 /* Exported types ------------------------------------------------------------*/
00040 
00041 /** @addtogroup UART3_Exported_Types
00042   * @{
00043   */
00044 
00045 /**
00046   * @brief  UART3 WakeUP Modes
00047   */
00048 typedef enum { UART3_WAKEUP_IDLELINE      = (uint8_t)0x00,  /**< 0x01 Idle Line wake up*/
00049                UART3_WAKEUP_ADDRESSMARK   = (uint8_t)0x08   /**< 0x02 Address Mark wake up*/
00050              } UART3_WakeUp_TypeDef;
00051 
00052 /**
00053   * @brief  UART3 LIN Break detection length possible values
00054   */
00055 typedef enum { UART3_LINBREAKDETECTIONLENGTH_10BITS = (uint8_t)0x00, /**< 10 bits Lin Break detection */
00056                UART3_LINBREAKDETECTIONLENGTH_11BITS = (uint8_t)0x01  /**< 11 bits Lin Break detection */
00057              } UART3_LINBreakDetectionLength_TypeDef;
00058 
00059 
00060 /**
00061   * @brief  UART3 stop bits possible values
00062   */
00063 typedef enum { UART3_STOPBITS_1  = (uint8_t)0x00,  /**< One stop bit is  transmitted at the end of frame*/
00064                UART3_STOPBITS_2  = (uint8_t)0x20   /**< Two stop bits are  transmitted at the end of frame*/
00065              } UART3_StopBits_TypeDef;
00066 
00067 /**
00068   * @brief  UART3 parity possible values
00069   */
00070 typedef enum { UART3_PARITY_NO    = (uint8_t)0x00,    /**< No Parity*/
00071                UART3_PARITY_EVEN  = (uint8_t)0x04,    /**< Even Parity*/
00072                UART3_PARITY_ODD   = (uint8_t)0x06     /**< Odd Parity*/
00073              } UART3_Parity_TypeDef;
00074 
00075 /**
00076   * @brief  UART3 Word length possible values
00077   */
00078 typedef enum { UART3_WORDLENGTH_8D = (uint8_t)0x00,    /**< 0x00 8 bits Data*/
00079                UART3_WORDLENGTH_9D = (uint8_t)0x10     /**< 0x10 9 bits Data*/
00080              } UART3_WordLength_TypeDef;
00081 
00082 /**
00083   * @brief  UART3 Mode Transmit/Receive possible values
00084   */
00085 typedef enum { UART3_MODE_RX_ENABLE    = (uint8_t)0x08,  /**< 0x08 Receive Enable*/
00086                UART3_MODE_TX_ENABLE    = (uint8_t)0x04,  /**< 0x04 Transmit Enable*/
00087                UART3_MODE_TX_DISABLE   = (uint8_t)0x80,  /**< 0x80 Receive Enable*/
00088                UART3_MODE_RX_DISABLE   = (uint8_t)0x40,  /**< 0x40 Single-wire Half-duplex mode*/
00089                UART3_MODE_TXRX_ENABLE  = (uint8_t)0x0C   /**< 0x0C Receive Enable and Transmit enable*/
00090              } UART3_Mode_TypeDef;
00091 
00092 /**
00093   * @brief  UART3 Mode possible values
00094   */
00095 typedef enum { UART3_LIN_MODE_MASTER  = (uint8_t)0x00, /**<  LIN Master Mode*/
00096                UART3_LIN_MODE_SLAVE   = (uint8_t)0x01  /**<  LIN Slave Mode*/
00097              } UART3_LinMode_TypeDef;
00098 /**
00099   * @brief  UART3 automatic resynchronisation possible values
00100   */
00101 typedef enum { UART3_LIN_AUTOSYNC_DISABLE   = (uint8_t)0x00,  /**< LIN Autosynchronization Disable*/
00102                UART3_LIN_AUTOSYNC_ENABLE    = (uint8_t)0x01   /**< LIN Autosynchronization Enable*/
00103              } UART3_LinAutosync_TypeDef;
00104 /**
00105   * @brief  UART3 Divider Update Method possible values
00106   */
00107 typedef enum { UART3_LIN_DIVUP_LBRR1    = (uint8_t)0x00, /**<  LIN LDIV is updated as soon as LBRR1 is written*/
00108                UART3_LIN_DIVUP_NEXTRXNE = (uint8_t)0x01  /**<  LIN LDIV is updated at the next received character*/
00109              } UART3_LinDivUp_TypeDef;
00110 
00111 
00112 /**
00113   * @brief  UART3 Flag possible values
00114   */
00115 typedef enum
00116 {
00117   UART3_FLAG_TXE         = (uint16_t)0x0080, /*!< Transmit Data Register Empty flag */
00118   UART3_FLAG_TC          = (uint16_t)0x0040, /*!< Transmission Complete flag */
00119   UART3_FLAG_RXNE        = (uint16_t)0x0020, /*!< Read Data Register Not Empty flag */
00120   UART3_FLAG_IDLE        = (uint16_t)0x0010, /*!< Idle line detected flag */
00121   UART3_FLAG_OR_LHE      = (uint16_t)0x0008, /*!< OverRun error flag */
00122   UART3_FLAG_NF          = (uint16_t)0x0004, /*!< Noise error flag */
00123   UART3_FLAG_FE          = (uint16_t)0x0002, /*!< Framing Error flag */
00124   UART3_FLAG_PE          = (uint16_t)0x0001, /*!< Parity Error flag */
00125   UART3_FLAG_SBK         = (uint16_t)0x0101,  /**< Send Break Complete interrupt flag */
00126   UART3_FLAG_LBDF        = (uint16_t)0x0210, /**< LIN Break Detection Flag           */
00127   UART3_FLAG_LHDF        = (uint16_t)0x0302, /**< LIN Header Detection Flag*/
00128   UART3_FLAG_LSF         = (uint16_t)0x0301  /**< LIN Sync Field Flag*/
00129 } UART3_Flag_TypeDef;
00130 
00131 /**
00132   * @brief  UART3 Interrupt definition
00133   * UART3_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   *     UART3_IT_TXE
00138   *     UART3_IT_TC
00139   *     UART3_IT_RXNE
00140   *     UART3_IT_IDLE 
00141   *     UART3_IT_OR 
00142   *   - For the UART3_IT_PE value, X means the flag position in the CR1 register.
00143   *   - For the UART3_IT_LBDF value, X means the flag position in the CR4 register.
00144   *   - For the UART3_IT_LHDF value, X means the flag position in the CR6 register.
00145   * Y: Flag position
00146   *  - For the following values, Y means the flag (pending bit) position in the SR register.
00147   *     UART3_IT_TXE
00148   *     UART3_IT_TC
00149   *     UART3_IT_RXNE
00150   *     UART3_IT_IDLE 
00151   *     UART3_IT_OR
00152   *     UART3_IT_PE
00153   *  - For the UART3_IT_LBDF value, Y means the flag position in the CR4 register.
00154   *  - For the UART3_IT_LHDF value, Y means the flag position in the CR6 register.
00155   * Z: Register index: indicate in which register the dedicated interrupt source is:
00156   *  - 1==> CR1 register
00157   *  - 2==> CR2 register
00158   *  - 3==> CR4 register
00159   *  - 4==> CR6 register
00160   */
00161 typedef enum { UART3_IT_TXE        = (uint16_t)0x0277, /**< Transmit interrupt */
00162                UART3_IT_TC         = (uint16_t)0x0266, /**< Transmission Complete interrupt */
00163                UART3_IT_RXNE       = (uint16_t)0x0255, /**< Data Register Not Empty interrupt */
00164                UART3_IT_IDLE       = (uint16_t)0x0244, /**< Idle line detected interrupt */
00165                UART3_IT_OR         = (uint16_t)0x0235, /**< OverRun error interrupt */
00166                UART3_IT_PE         = (uint16_t)0x0100, /**< Parity Error interrupt */
00167                UART3_IT_LBDF       = (uint16_t)0x0346, /**< LIN Break Detection interrupt */
00168                UART3_IT_LHDF       = (uint16_t)0x0412, /**< LIN Header Detection interrupt*/
00169                UART3_IT_RXNE_OR    = (uint16_t)0x0205  /*!< Receive/Overrun interrupt */
00170              } UART3_IT_TypeDef;
00171 
00172 
00173 /**
00174   * @}
00175   */
00176 
00177 /* Exported constants --------------------------------------------------------*/
00178 /* Exported macros ------------------------------------------------------------*/
00179 
00180 /* Private macros ------------------------------------------------------------*/
00181 
00182 /** @addtogroup UART3_Private_Macros
00183   * @{
00184   */
00185 
00186 /**
00187   * @brief  Macro used by the assert_param function in order to check the 
00188   *         different sensitivity values for the FLAGs
00189   */
00190 #define IS_UART3_FLAG_OK(Flag) \
00191   (((Flag) == UART3_FLAG_TXE) || \
00192    ((Flag) == UART3_FLAG_TC)  || \
00193    ((Flag) == UART3_FLAG_RXNE) || \
00194    ((Flag) == UART3_FLAG_IDLE) || \
00195    ((Flag) == UART3_FLAG_OR_LHE) || \
00196    ((Flag) == UART3_FLAG_NF) || \
00197    ((Flag) == UART3_FLAG_FE) || \
00198    ((Flag) == UART3_FLAG_PE) || \
00199    ((Flag) == UART3_FLAG_SBK) || \
00200    ((Flag) == UART3_FLAG_LSF) || \
00201    ((Flag) == UART3_FLAG_LHDF) || \
00202    ((Flag) == UART3_FLAG_LBDF))
00203 
00204 
00205 /**
00206   * @brief  Macro used by the assert_param function in order to check the 
00207   *         different sensitivity values for the FLAGs that can be cleared by writing 0
00208   */
00209 #define IS_UART3_CLEAR_FLAG_OK(Flag) \
00210   (((Flag) == UART3_FLAG_RXNE) || \
00211    ((Flag) == UART3_FLAG_LHDF) || \
00212    ((Flag) == UART3_FLAG_LSF) || \
00213    ((Flag) == UART3_FLAG_LBDF))
00214 
00215 /**
00216   * @brief  Macro used by the assert_param function in order to check the 
00217   *         different sensitivity values for the Interrupts
00218   */
00219 
00220 #define IS_UART3_CONFIG_IT_OK(Interrupt) \
00221   (((Interrupt) == UART3_IT_PE) || \
00222    ((Interrupt) == UART3_IT_TXE) || \
00223    ((Interrupt) == UART3_IT_TC) || \
00224    ((Interrupt) == UART3_IT_RXNE_OR ) || \
00225    ((Interrupt) == UART3_IT_IDLE) || \
00226    ((Interrupt) == UART3_IT_LHDF) || \
00227    ((Interrupt) == UART3_IT_LBDF))
00228 
00229 /**
00230   * @brief  Macro used by the assert function in order to check the different 
00231   *         sensitivity values for the pending bit
00232   */
00233 #define IS_UART3_GET_IT_OK(ITPendingBit) \
00234   (((ITPendingBit) == UART3_IT_TXE)  || \
00235    ((ITPendingBit) == UART3_IT_TC)   || \
00236    ((ITPendingBit) == UART3_IT_RXNE) || \
00237    ((ITPendingBit) == UART3_IT_IDLE) || \
00238    ((ITPendingBit) == UART3_IT_OR)  || \
00239    ((ITPendingBit) == UART3_IT_LBDF)  || \
00240    ((ITPendingBit) == UART3_IT_LHDF)  || \
00241    ((ITPendingBit) == UART3_IT_PE))
00242 
00243 /**
00244   * @brief  Macro used by the assert function in order to check the different 
00245   *         sensitivity values for the pending bit that can be cleared by writing 0
00246   */
00247 #define IS_UART3_CLEAR_IT_OK(ITPendingBit) \
00248   (((ITPendingBit) == UART3_IT_RXNE) || \
00249    ((ITPendingBit) == UART3_IT_LHDF) || \
00250    ((ITPendingBit) == UART3_IT_LBDF))
00251 
00252 /**
00253  * @brief Macro used by the assert_param function in order to check the different
00254  *        sensitivity values for the MODEs
00255  */
00256 #define IS_UART3_MODE_OK(Mode) \
00257   (((Mode) == (uint8_t)UART3_MODE_RX_ENABLE) || \
00258    ((Mode) == (uint8_t)UART3_MODE_RX_DISABLE) || \
00259    ((Mode) == (uint8_t)UART3_MODE_TX_ENABLE) || \
00260    ((Mode) == (uint8_t)UART3_MODE_TX_DISABLE) || \
00261    ((Mode) == (uint8_t)UART3_MODE_TXRX_ENABLE) || \
00262    ((Mode) == (uint8_t)((uint8_t)UART3_MODE_TX_ENABLE|(uint8_t)UART3_MODE_RX_ENABLE)) || \
00263    ((Mode) == (uint8_t)((uint8_t)UART3_MODE_TX_ENABLE|(uint8_t)UART3_MODE_RX_DISABLE)) || \
00264    ((Mode) == (uint8_t)((uint8_t)UART3_MODE_TX_DISABLE|(uint8_t)UART3_MODE_RX_DISABLE)) || \
00265    ((Mode) == (uint8_t)((uint8_t)UART3_MODE_TX_DISABLE|(uint8_t)UART3_MODE_RX_ENABLE)))
00266 
00267 /**
00268  * @brief Macro used by the assert_param function in order to check the different
00269  *        sensitivity values for the WordLengths
00270  */
00271 #define IS_UART3_WORDLENGTH_OK(WordLength) \
00272   (((WordLength) == UART3_WORDLENGTH_8D) || \
00273    ((WordLength) == UART3_WORDLENGTH_9D))
00274 
00275 
00276 /**
00277   * @brief  Macro used by the assert_param function in order to check the different
00278   *         sensitivity values for the WakeUps
00279   */
00280 #define IS_UART3_WAKEUP_OK(WakeUpMode) \
00281   (((WakeUpMode) == UART3_WAKEUP_IDLELINE) || \
00282    ((WakeUpMode) == UART3_WAKEUP_ADDRESSMARK))
00283 
00284 /**
00285   * @brief  Macro used by the assert_param function in order to check the different
00286   *         sensitivity values for the LINBreakDetectionLengths
00287   */
00288 #define IS_UART3_LINBREAKDETECTIONLENGTH_OK(LINBreakDetectionLengths) \
00289   (((LINBreakDetectionLengths) == UART3_LINBREAKDETECTIONLENGTH_10BITS) || \
00290    ((LINBreakDetectionLengths) == UART3_LINBREAKDETECTIONLENGTH_11BITS))
00291 
00292 /**
00293   * @brief  Macro used by the assert_param function in order to check the different
00294   *         sensitivity values for the UART3_StopBits
00295   */
00296 #define IS_UART3_STOPBITS_OK(StopBit) \
00297   (((StopBit) == UART3_STOPBITS_1) || \
00298    ((StopBit) == UART3_STOPBITS_2))
00299 
00300 /**
00301  * @brief Macro used by the assert_param function in order to check the different
00302  *        sensitivity values for the Parity
00303  */
00304 #define IS_UART3_PARITY_OK(Parity) \
00305   (((Parity) == UART3_PARITY_NO) || \
00306    ((Parity) == UART3_PARITY_EVEN) || \
00307    ((Parity) == UART3_PARITY_ODD ))
00308 
00309 /**
00310  * @brief Macro used by the assert_param function in order to check the maximum 
00311  *        baudrate value
00312  */
00313 #define IS_UART3_BAUDRATE_OK(NUM) ((NUM) <= (uint32_t)625000)
00314 
00315 /**
00316  * @brief Macro used by the assert_param function in order to check the address 
00317  *        of the UART3 or UART node
00318  */
00319 #define UART3_ADDRESS_MAX ((uint8_t)16)
00320 #define IS_UART3_ADDRESS_OK(Node) ((Node) < UART3_ADDRESS_MAX)
00321 
00322 /**
00323  * @brief Macro used by the assert_param function in order to check the LIN mode
00324  */
00325 #define IS_UART3_SLAVE_OK(Mode) \
00326   (((Mode) == UART3_LIN_MODE_MASTER) || \
00327    ((Mode) == UART3_LIN_MODE_SLAVE))
00328 
00329 /**
00330  * @brief Macro used by the assert_param function in order to check the LIN 
00331  *        automatic resynchronization mode
00332  */
00333 #define IS_UART3_AUTOSYNC_OK(AutosyncMode) \
00334   (((AutosyncMode) ==  UART3_LIN_AUTOSYNC_ENABLE) || \
00335    ((AutosyncMode) == UART3_LIN_AUTOSYNC_DISABLE))
00336 
00337 /**
00338  * @brief Macro used by the assert_param function in order to check the LIN 
00339  *        divider update method
00340  */
00341 #define IS_UART3_DIVUP_OK(DivupMethod) \
00342   (((DivupMethod) == UART3_LIN_DIVUP_LBRR1) || \
00343    ((DivupMethod) == UART3_LIN_DIVUP_NEXTRXNE))
00344 
00345 /**
00346   * @}
00347   */
00348 
00349 /* Exported functions ------------------------------------------------------- */
00350 
00351 /** @addtogroup UART3_Exported_Functions
00352   * @{
00353   */
00354 
00355 void UART3_DeInit(void);
00356 void UART3_Init(uint32_t BaudRate, UART3_WordLength_TypeDef WordLength, 
00357                 UART3_StopBits_TypeDef StopBits, UART3_Parity_TypeDef Parity, 
00358                 UART3_Mode_TypeDef Mode);
00359 void UART3_Cmd(FunctionalState NewState);
00360 void UART3_ITConfig(UART3_IT_TypeDef UART3_IT, FunctionalState NewState);
00361 void UART3_LINBreakDetectionConfig(UART3_LINBreakDetectionLength_TypeDef UART3_LINBreakDetectionLength);
00362 void UART3_LINConfig(UART3_LinMode_TypeDef UART3_Mode, 
00363                      UART3_LinAutosync_TypeDef UART3_Autosync, 
00364                      UART3_LinDivUp_TypeDef UART3_DivUp);
00365 void UART3_LINCmd(FunctionalState NewState);
00366 void UART3_ReceiverWakeUpCmd(FunctionalState NewState);
00367 void UART3_WakeUpConfig( UART3_WakeUp_TypeDef UART3_WakeUp);
00368 uint8_t UART3_ReceiveData8(void);
00369 uint16_t UART3_ReceiveData9(void);
00370 void UART3_SendData8(uint8_t Data);
00371 void UART3_SendData9(uint16_t Data);
00372 void UART3_SendBreak(void);
00373 void UART3_SetAddress(uint8_t UART3_Address);
00374 FlagStatus UART3_GetFlagStatus(UART3_Flag_TypeDef UART3_FLAG);
00375 void UART3_ClearFlag(UART3_Flag_TypeDef UART3_FLAG);
00376 ITStatus UART3_GetITStatus(UART3_IT_TypeDef UART3_IT);
00377 void UART3_ClearITPendingBit(UART3_IT_TypeDef UART3_IT);
00378 /**
00379   * @}
00380   */
00381 
00382 #endif /* __STM8S_UART3_H */
00383 
00384 /**
00385   * @}
00386   */
00387 
00388 
00389 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
STM8 Standard Peripherals Library: Footer

 

 

 

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