STM8L15x Standard Peripherals Drivers
|
stm8l15x_usart.h
Go to the documentation of this file.
00001 /** 00002 ******************************************************************************** 00003 * @file stm8l15x_usart.h 00004 * @author MCD Application Team 00005 * @version V1.5.0 00006 * @date 13-May-2011 00007 * @brief This file contains all the functions prototypes for the USART firmware 00008 * library. 00009 ****************************************************************************** 00010 * @attention 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>© COPYRIGHT 2011 STMicroelectronics</center></h2> 00020 ****************************************************************************** 00021 */ 00022 00023 /* Define to prevent recursive inclusion -------------------------------------*/ 00024 #ifndef __STM8L15x_USART_H 00025 #define __STM8L15x_USART_H 00026 00027 /* Includes ------------------------------------------------------------------*/ 00028 #include "stm8l15x.h" 00029 #include "stm8l15x_clk.h" 00030 00031 /** @addtogroup STM8L15x_StdPeriph_Driver 00032 * @{ 00033 */ 00034 /** @addtogroup USART 00035 * @{ 00036 */ 00037 00038 /* Exported types ------------------------------------------------------------*/ 00039 00040 /** @defgroup USART_Exported_Types 00041 * @{ 00042 */ 00043 00044 /** @defgroup USART_Flags 00045 * @{ 00046 */ 00047 typedef enum 00048 { 00049 USART_FLAG_TXE = (uint16_t)0x0080, /*!< Transmit Data Register Empty flag */ 00050 USART_FLAG_TC = (uint16_t)0x0040, /*!< Transmission Complete flag */ 00051 USART_FLAG_RXNE = (uint16_t)0x0020, /*!< Read Data Register Not Empty flag */ 00052 USART_FLAG_IDLE = (uint16_t)0x0010, /*!< Idle line detected flag */ 00053 USART_FLAG_OR = (uint16_t)0x0008, /*!< OverRun error flag */ 00054 USART_FLAG_NF = (uint16_t)0x0004, /*!< Noise error flag */ 00055 USART_FLAG_FE = (uint16_t)0x0002, /*!< Framing Error flag */ 00056 USART_FLAG_PE = (uint16_t)0x0001, /*!< Parity Error flag */ 00057 USART_FLAG_SBK = (uint16_t)0x0101 /*!< Send Break characters Flag */ 00058 } USART_FLAG_TypeDef; 00059 00060 #define IS_USART_FLAG(Flag) \ 00061 (((Flag) == USART_FLAG_TXE) || \ 00062 ((Flag) == USART_FLAG_TC) || \ 00063 ((Flag) == USART_FLAG_RXNE) || \ 00064 ((Flag) == USART_FLAG_IDLE) || \ 00065 ((Flag) == USART_FLAG_OR) || \ 00066 ((Flag) == USART_FLAG_NF) || \ 00067 ((Flag) == USART_FLAG_FE) || \ 00068 ((Flag) == USART_FLAG_PE) || \ 00069 ((Flag) == USART_FLAG_SBK)) 00070 00071 #define IS_USART_CLEAR_FLAG(Flag) \ 00072 (((Flag) == USART_FLAG_TC) || \ 00073 ((Flag) == USART_FLAG_RXNE)) 00074 00075 /** 00076 * @} 00077 */ 00078 00079 /** @defgroup USART_Interrupts 00080 * @{ 00081 */ 00082 00083 /** 00084 * @brief USART Interrupt definition 00085 * USART_IT possible values 00086 * Elements values convention: 0x0ZYX 00087 * X: Position of the corresponding Interrupt 00088 * Y: Flag position 00089 * Z: Register index 00090 */ 00091 typedef enum 00092 { 00093 USART_IT_TXE = (uint16_t)0x0277, /*!< Transmit interrupt */ 00094 USART_IT_TC = (uint16_t)0x0266, /*!< Transmission Complete interrupt */ 00095 USART_IT_RXNE = (uint16_t)0x0255, /*!< Receive interrupt */ 00096 USART_IT_IDLE = (uint16_t)0x0244, /*!< IDLE line interrupt */ 00097 USART_IT_OR = (uint16_t)0x0235, /*!< Overrun Error interrupt */ 00098 USART_IT_PE = (uint16_t)0x0100, /*!< Parity Error interrupt */ 00099 USART_IT_ERR = (uint16_t)0x0500, /*!< Error interrupt */ 00100 USART_IT_NF = (uint16_t)0x0102, /*!< Noise Error interrupt */ 00101 USART_IT_FE = (uint16_t)0x0101 /*!< Frame Error interrupt */ 00102 } USART_IT_TypeDef; 00103 00104 #define IS_USART_CONFIG_IT(Interrupt) \ 00105 (((Interrupt) == USART_IT_PE) || \ 00106 ((Interrupt) == USART_IT_TXE) || \ 00107 ((Interrupt) == USART_IT_TC) || \ 00108 ((Interrupt) == USART_IT_RXNE) || \ 00109 ((Interrupt) == USART_IT_OR) || \ 00110 ((Interrupt) == USART_IT_ERR) || \ 00111 ((Interrupt) == USART_IT_IDLE)) 00112 00113 #define IS_USART_GET_IT(ITPendingBit) \ 00114 (((ITPendingBit) == USART_IT_TXE) || \ 00115 ((ITPendingBit) == USART_IT_TC) || \ 00116 ((ITPendingBit) == USART_IT_RXNE) || \ 00117 ((ITPendingBit) == USART_IT_IDLE) || \ 00118 ((ITPendingBit) == USART_IT_OR) || \ 00119 ((ITPendingBit) == USART_IT_PE)) 00120 00121 #define IS_USART_CLEAR_IT(IT) (((IT) == USART_IT_TC) || ((IT) == USART_IT_RXNE)) 00122 /** 00123 * @} 00124 */ 00125 00126 /** @defgroup USART_Wakeup_Modes 00127 * @{ 00128 */ 00129 typedef enum 00130 { 00131 USART_WakeUp_IdleLine = (uint8_t)0x00, /*!< 0x01 Idle Line wake up */ 00132 USART_WakeUp_AddressMark = (uint8_t)0x08 /*!< 0x02 Address Mark wake up */ 00133 } USART_WakeUp_TypeDef; 00134 00135 #define IS_USART_WAKEUP(WakeUpMode)(((WakeUpMode) == USART_WakeUp_IdleLine) || \ 00136 ((WakeUpMode) == USART_WakeUp_AddressMark)) 00137 /** 00138 * @} 00139 */ 00140 00141 /** @defgroup USART_Stop_Bits 00142 * @{ 00143 */ 00144 typedef enum 00145 { 00146 USART_StopBits_1 = (uint8_t)0x00, /*!< One stop bit is transmitted at the end of frame*/ 00147 USART_StopBits_2 = (uint8_t)0x20, /*!< Two stop bits are transmitted at the end of frame*/ 00148 USART_StopBits_1_5 = (uint8_t)0x30 /*!< One and half stop bits*/ 00149 } USART_StopBits_TypeDef; 00150 00151 #define IS_USART_STOPBITS(StopBit)(((StopBit) == USART_StopBits_1) || \ 00152 ((StopBit) == USART_StopBits_1_5) || \ 00153 ((StopBit) == USART_StopBits_2)) 00154 /** 00155 * @} 00156 */ 00157 00158 /** @defgroup USART_Parity 00159 * @{ 00160 */ 00161 typedef enum 00162 { 00163 USART_Parity_No = (uint8_t)0x00, /*!< No Parity*/ 00164 USART_Parity_Even = (uint8_t)0x04, /*!< Even Parity*/ 00165 USART_Parity_Odd = (uint8_t)0x06 /*!< Odd Parity*/ 00166 } USART_Parity_TypeDef; 00167 00168 #define IS_USART_PARITY(Parity)(((Parity) == USART_Parity_No) || \ 00169 ((Parity) == USART_Parity_Even) || \ 00170 ((Parity) == USART_Parity_Odd )) 00171 /** 00172 * @} 00173 */ 00174 00175 /** @defgroup USART_Lin_Break_Detection_Length 00176 * @{ 00177 */ 00178 typedef enum 00179 { 00180 USART_LINBreakDetectionLength_10BITS = (uint8_t)0x00, /*!< 10 bits Lin Break detection */ 00181 USART_LINBreakDetectionLength_11BITS = (uint8_t)0x01 /*!< 11 bits Lin Break detection */ 00182 } USART_LINBreakDetectionLength_TypeDef; 00183 00184 /** 00185 * @} 00186 */ 00187 00188 /** @defgroup USART_Word_Length 00189 * @{ 00190 */ 00191 typedef enum 00192 { 00193 USART_WordLength_8b = (uint8_t)0x00, /*!< 8 bits Data */ 00194 USART_WordLength_9b = (uint8_t)0x10 /*!< 9 bits Data */ 00195 } USART_WordLength_TypeDef; 00196 00197 #define IS_USART_WORDLENGTH(WordLength) (((WordLength) == USART_WordLength_8b) || \ 00198 ((WordLength) == USART_WordLength_9b)) 00199 00200 /** 00201 * @} 00202 */ 00203 00204 /** @defgroup USART_Mode 00205 * @{ 00206 */ 00207 typedef enum 00208 { 00209 USART_Mode_Rx = (uint8_t)0x04, /*!< Receive Enable */ 00210 USART_Mode_Tx = (uint8_t)0x08 /*!< Transmit Enable */ 00211 } USART_Mode_TypeDef; 00212 00213 #define IS_USART_MODE(MODE) ((((MODE) & (uint8_t)0xF3) == 0x00) && ((MODE) != (uint16_t)0x00)) 00214 /** 00215 * @} 00216 */ 00217 00218 /** @defgroup USART_DMA_Requests 00219 * @{ 00220 */ 00221 typedef enum 00222 { 00223 USART_DMAReq_TX = (uint8_t)0x80, /*!< Receive DMA request Enable */ 00224 USART_DMAReq_RX = (uint8_t)0x40 /*!< Transmit DMA request Enable */ 00225 } USART_DMAReq_TypeDef; 00226 00227 #define IS_USART_DMAREQ(DMAReq) ((((DMAReq) & (uint8_t)0x3F) == 0x00) && ((DMAReq) != (uint8_t)0x00)) 00228 /** 00229 * @} 00230 */ 00231 00232 /** @defgroup USART_IrDA_Mode 00233 * @{ 00234 */ 00235 typedef enum 00236 { 00237 USART_IrDAMode_Normal = (uint8_t)0x00, /*!< IrDA Normal Mode */ 00238 USART_IrDAMode_LowPower = (uint8_t)0x01 /*!< IrDA Low Power Mode */ 00239 } USART_IrDAMode_TypeDef; 00240 00241 #define IS_USART_IRDAMODE(IrDAMode) (((IrDAMode) == USART_IrDAMode_LowPower) || \ 00242 ((IrDAMode) == USART_IrDAMode_Normal)) 00243 /** 00244 * @} 00245 */ 00246 00247 /** @defgroup USART_Clock 00248 * @{ 00249 */ 00250 typedef enum 00251 { 00252 USART_Clock_Disable = (uint8_t)0x00, /*!< CK pin disabled */ 00253 USART_Clock_Enable = (uint8_t)0x08 /*!< CK pin enabled */ 00254 } USART_Clock_TypeDef; 00255 00256 #define IS_USART_CLOCK(CLOCK) (((CLOCK) == USART_Clock_Disable) ||((CLOCK) == USART_Clock_Enable)) 00257 /** 00258 * @} 00259 */ 00260 00261 /** @defgroup USART_Clock_Polarity 00262 * @{ 00263 */ 00264 typedef enum 00265 { 00266 USART_CPOL_Low = (uint8_t)0x00, /*!< CK to 0 when idle */ 00267 USART_CPOL_High = (uint8_t)0x04 /*!< CK to 1 when idle.*/ 00268 } USART_CPOL_TypeDef; 00269 00270 #define IS_USART_CPOL(CPOL) (((CPOL) == USART_CPOL_Low) || ((CPOL) == USART_CPOL_High)) 00271 /** 00272 * @} 00273 */ 00274 00275 /** @defgroup USART_Clock_Phase 00276 * @{ 00277 */ 00278 typedef enum 00279 { 00280 USART_CPHA_1Edge = (uint8_t)0x00, /*!< The first clock transition is the first data capture edge*/ 00281 USART_CPHA_2Edge = (uint8_t)0x02 /*!< The second clock transition is the first data capture edge*/ 00282 } USART_CPHA_TypeDef; 00283 00284 #define IS_USART_CPHA(CPHA) (((CPHA) == USART_CPHA_1Edge) || ((CPHA) == USART_CPHA_2Edge)) 00285 /** 00286 * @} 00287 */ 00288 00289 /** @defgroup USART_LastBit 00290 * @{ 00291 */ 00292 typedef enum 00293 { 00294 USART_LastBit_Disable = (uint8_t)0x00, /*!< The clock pulse of the last data bit is not output to the SCLK pin.*/ 00295 USART_LastBit_Enable = (uint8_t)0x01 /*!< The clock pulse of the last data bit is output to the SCLK pin.*/ 00296 } USART_LastBit_TypeDef; 00297 00298 #define IS_USART_LASTBIT(LASTBIT) (((LASTBIT) == USART_LastBit_Disable) || \ 00299 ((LASTBIT) == USART_LastBit_Enable)) 00300 /** 00301 * @} 00302 */ 00303 00304 /** 00305 * @} 00306 */ 00307 00308 /* Exported constants --------------------------------------------------------*/ 00309 /* Exported macros -----------------------------------------------------------*/ 00310 /** @defgroupUSART_Exported_Macros 00311 * @{ 00312 */ 00313 /* BaudRate value should be < 625000 bps */ 00314 #define IS_USART_BAUDRATE(NUM) ((NUM) <= (uint32_t)625000) 00315 00316 #define USART_ADDRESS_MAX ((uint8_t)16) 00317 #define IS_USART_ADDRESS(address) ((address) < USART_ADDRESS_MAX) 00318 00319 #define USART_DATA_9BITS_MAX ((uint16_t)0x1FF) 00320 #define IS_USART_DATA_9BITS(DATA) ((DATA) < USART_DATA_9BITS_MAX) 00321 00322 /** 00323 * @} 00324 */ 00325 00326 /* Exported functions ------------------------------------------------------- */ 00327 00328 /* Function used to set the USART configuration to the default reset state ***/ 00329 void USART_DeInit(USART_TypeDef* USARTx); 00330 00331 /* Initialization and Configuration functions *********************************/ 00332 void USART_Init(USART_TypeDef* USARTx, uint32_t BaudRate, USART_WordLength_TypeDef 00333 USART_WordLength, USART_StopBits_TypeDef USART_StopBits, 00334 USART_Parity_TypeDef USART_Parity, USART_Mode_TypeDef USART_Mode); 00335 void USART_ClockInit(USART_TypeDef* USARTx, USART_Clock_TypeDef USART_Clock, 00336 USART_CPOL_TypeDef USART_CPOL, USART_CPHA_TypeDef USART_CPHA, 00337 USART_LastBit_TypeDef USART_LastBit); 00338 void USART_Cmd(USART_TypeDef* USARTx, FunctionalState NewState); 00339 void USART_SetPrescaler(USART_TypeDef* USARTx, uint8_t USART_Prescaler); 00340 void USART_SendBreak(USART_TypeDef* USARTx); 00341 00342 /* Data transfers functions ***************************************************/ 00343 void USART_SendData8(USART_TypeDef* USARTx, uint8_t Data); 00344 void USART_SendData9(USART_TypeDef* USARTx, uint16_t Data); 00345 uint8_t USART_ReceiveData8(USART_TypeDef* USARTx); 00346 uint16_t USART_ReceiveData9(USART_TypeDef* USARTx); 00347 00348 /* Multi-Processor Communication functions ************************************/ 00349 void USART_WakeUpConfig(USART_TypeDef* USARTx, USART_WakeUp_TypeDef USART_WakeUp); 00350 void USART_ReceiverWakeUpCmd(USART_TypeDef* USARTx, FunctionalState NewState); 00351 void USART_SetAddress(USART_TypeDef* USARTx, uint8_t USART_Address); 00352 00353 /* Half-duplex mode function **************************************************/ 00354 void USART_HalfDuplexCmd(USART_TypeDef* USARTx, FunctionalState NewState); 00355 00356 /* Smartcard mode functions ***************************************************/ 00357 void USART_SmartCardCmd(USART_TypeDef* USARTx, FunctionalState NewState); 00358 void USART_SmartCardNACKCmd(USART_TypeDef* USARTx, FunctionalState NewState); 00359 void USART_SetGuardTime(USART_TypeDef* USARTx, uint8_t USART_GuardTime); 00360 00361 /* IrDA mode functions ********************************************************/ 00362 void USART_IrDAConfig(USART_TypeDef* USARTx, USART_IrDAMode_TypeDef USART_IrDAMode); 00363 void USART_IrDACmd(USART_TypeDef* USARTx, FunctionalState NewState); 00364 00365 /* DMA transfers management functions *****************************************/ 00366 void USART_DMACmd(USART_TypeDef* USARTx, USART_DMAReq_TypeDef USART_DMAReq, 00367 FunctionalState NewState); 00368 00369 /* Interrupts and flags management functions **********************************/ 00370 void USART_ITConfig(USART_TypeDef* USARTx, USART_IT_TypeDef USART_IT, 00371 FunctionalState NewState); 00372 FlagStatus USART_GetFlagStatus(USART_TypeDef* USARTx, USART_FLAG_TypeDef USART_FLAG); 00373 void USART_ClearFlag(USART_TypeDef* USARTx, USART_FLAG_TypeDef USART_FLAG); 00374 ITStatus USART_GetITStatus(USART_TypeDef* USARTx, USART_IT_TypeDef USART_IT); 00375 void USART_ClearITPendingBit(USART_TypeDef* USARTx, USART_IT_TypeDef USART_IT); 00376 00377 00378 00379 #endif /* __STM8L15x_USART_H */ 00380 00381 /** 00382 * @} 00383 */ 00384 00385 /** 00386 * @} 00387 */ 00388 00389 /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/