2 ******************************************************************************
\r
3 * @file stm32l1xx_usart.h
\r
4 * @author MCD Application Team
\r
6 * @date 05-March-2012
\r
7 * @brief This file contains all the functions prototypes for the USART
\r
9 ******************************************************************************
\r
12 * <h2><center>© COPYRIGHT 2012 STMicroelectronics</center></h2>
\r
14 * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
\r
15 * You may not use this file except in compliance with the License.
\r
16 * You may obtain a copy of the License at:
\r
18 * http://www.st.com/software_license_agreement_liberty_v2
\r
20 * Unless required by applicable law or agreed to in writing, software
\r
21 * distributed under the License is distributed on an "AS IS" BASIS,
\r
22 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
23 * See the License for the specific language governing permissions and
\r
24 * limitations under the License.
\r
26 ******************************************************************************
\r
29 /* Define to prevent recursive inclusion -------------------------------------*/
\r
30 #ifndef __STM32L1xx_USART_H
\r
31 #define __STM32L1xx_USART_H
\r
37 /* Includes ------------------------------------------------------------------*/
\r
38 #include "stm32l1xx.h"
\r
40 /** @addtogroup STM32L1xx_StdPeriph_Driver
\r
44 /** @addtogroup USART
\r
48 /* Exported types ------------------------------------------------------------*/
\r
51 * @brief USART Init Structure definition
\r
56 uint32_t USART_BaudRate; /*!< This member configures the USART communication baud rate.
\r
57 The baud rate is computed using the following formula:
\r
58 - IntegerDivider = ((PCLKx) / (8 * (OVR8+1) * (USART_InitStruct->USART_BaudRate)))
\r
59 - FractionalDivider = ((IntegerDivider - ((u32) IntegerDivider)) * 8 * (OVR8+1)) + 0.5
\r
60 Where OVR8 is the "oversampling by 8 mode" configuration bit in the CR1 register. */
\r
62 uint16_t USART_WordLength; /*!< Specifies the number of data bits transmitted or received in a frame.
\r
63 This parameter can be a value of @ref USART_Word_Length */
\r
65 uint16_t USART_StopBits; /*!< Specifies the number of stop bits transmitted.
\r
66 This parameter can be a value of @ref USART_Stop_Bits */
\r
68 uint16_t USART_Parity; /*!< Specifies the parity mode.
\r
69 This parameter can be a value of @ref USART_Parity
\r
70 @note When parity is enabled, the computed parity is inserted
\r
71 at the MSB position of the transmitted data (9th bit when
\r
72 the word length is set to 9 data bits; 8th bit when the
\r
73 word length is set to 8 data bits). */
\r
75 uint16_t USART_Mode; /*!< Specifies wether the Receive or Transmit mode is enabled or disabled.
\r
76 This parameter can be a value of @ref USART_Mode */
\r
78 uint16_t USART_HardwareFlowControl; /*!< Specifies wether the hardware flow control mode is enabled
\r
80 This parameter can be a value of @ref USART_Hardware_Flow_Control */
\r
81 } USART_InitTypeDef;
\r
84 * @brief USART Clock Init Structure definition
\r
90 uint16_t USART_Clock; /*!< Specifies whether the USART clock is enabled or disabled.
\r
91 This parameter can be a value of @ref USART_Clock */
\r
93 uint16_t USART_CPOL; /*!< Specifies the steady state of the serial clock.
\r
94 This parameter can be a value of @ref USART_Clock_Polarity */
\r
96 uint16_t USART_CPHA; /*!< Specifies the clock transition on which the bit capture is made.
\r
97 This parameter can be a value of @ref USART_Clock_Phase */
\r
99 uint16_t USART_LastBit; /*!< Specifies whether the clock pulse corresponding to the last transmitted
\r
100 data bit (MSB) has to be output on the SCLK pin in synchronous mode.
\r
101 This parameter can be a value of @ref USART_Last_Bit */
\r
102 } USART_ClockInitTypeDef;
\r
104 /* Exported constants --------------------------------------------------------*/
\r
106 /** @defgroup USART_Exported_Constants
\r
110 #define IS_USART_ALL_PERIPH(PERIPH) (((PERIPH) == USART1) || \
\r
111 ((PERIPH) == USART2) || \
\r
112 ((PERIPH) == USART3) || \
\r
113 ((PERIPH) == UART4) || \
\r
114 ((PERIPH) == UART5))
\r
116 #define IS_USART_123_PERIPH(PERIPH) (((PERIPH) == USART1) || \
\r
117 ((PERIPH) == USART2) || \
\r
118 ((PERIPH) == USART3))
\r
120 /** @defgroup USART_Word_Length
\r
124 #define USART_WordLength_8b ((uint16_t)0x0000)
\r
125 #define USART_WordLength_9b ((uint16_t)0x1000)
\r
127 #define IS_USART_WORD_LENGTH(LENGTH) (((LENGTH) == USART_WordLength_8b) || \
\r
128 ((LENGTH) == USART_WordLength_9b))
\r
133 /** @defgroup USART_Stop_Bits
\r
137 #define USART_StopBits_1 ((uint16_t)0x0000)
\r
138 #define USART_StopBits_0_5 ((uint16_t)0x1000)
\r
139 #define USART_StopBits_2 ((uint16_t)0x2000)
\r
140 #define USART_StopBits_1_5 ((uint16_t)0x3000)
\r
141 #define IS_USART_STOPBITS(STOPBITS) (((STOPBITS) == USART_StopBits_1) || \
\r
142 ((STOPBITS) == USART_StopBits_0_5) || \
\r
143 ((STOPBITS) == USART_StopBits_2) || \
\r
144 ((STOPBITS) == USART_StopBits_1_5))
\r
149 /** @defgroup USART_Parity
\r
153 #define USART_Parity_No ((uint16_t)0x0000)
\r
154 #define USART_Parity_Even ((uint16_t)0x0400)
\r
155 #define USART_Parity_Odd ((uint16_t)0x0600)
\r
156 #define IS_USART_PARITY(PARITY) (((PARITY) == USART_Parity_No) || \
\r
157 ((PARITY) == USART_Parity_Even) || \
\r
158 ((PARITY) == USART_Parity_Odd))
\r
163 /** @defgroup USART_Mode
\r
167 #define USART_Mode_Rx ((uint16_t)0x0004)
\r
168 #define USART_Mode_Tx ((uint16_t)0x0008)
\r
169 #define IS_USART_MODE(MODE) ((((MODE) & (uint16_t)0xFFF3) == 0x00) && ((MODE) != (uint16_t)0x00))
\r
174 /** @defgroup USART_Hardware_Flow_Control
\r
177 #define USART_HardwareFlowControl_None ((uint16_t)0x0000)
\r
178 #define USART_HardwareFlowControl_RTS ((uint16_t)0x0100)
\r
179 #define USART_HardwareFlowControl_CTS ((uint16_t)0x0200)
\r
180 #define USART_HardwareFlowControl_RTS_CTS ((uint16_t)0x0300)
\r
181 #define IS_USART_HARDWARE_FLOW_CONTROL(CONTROL)\
\r
182 (((CONTROL) == USART_HardwareFlowControl_None) || \
\r
183 ((CONTROL) == USART_HardwareFlowControl_RTS) || \
\r
184 ((CONTROL) == USART_HardwareFlowControl_CTS) || \
\r
185 ((CONTROL) == USART_HardwareFlowControl_RTS_CTS))
\r
190 /** @defgroup USART_Clock
\r
193 #define USART_Clock_Disable ((uint16_t)0x0000)
\r
194 #define USART_Clock_Enable ((uint16_t)0x0800)
\r
195 #define IS_USART_CLOCK(CLOCK) (((CLOCK) == USART_Clock_Disable) || \
\r
196 ((CLOCK) == USART_Clock_Enable))
\r
201 /** @defgroup USART_Clock_Polarity
\r
205 #define USART_CPOL_Low ((uint16_t)0x0000)
\r
206 #define USART_CPOL_High ((uint16_t)0x0400)
\r
207 #define IS_USART_CPOL(CPOL) (((CPOL) == USART_CPOL_Low) || ((CPOL) == USART_CPOL_High))
\r
213 /** @defgroup USART_Clock_Phase
\r
217 #define USART_CPHA_1Edge ((uint16_t)0x0000)
\r
218 #define USART_CPHA_2Edge ((uint16_t)0x0200)
\r
219 #define IS_USART_CPHA(CPHA) (((CPHA) == USART_CPHA_1Edge) || ((CPHA) == USART_CPHA_2Edge))
\r
225 /** @defgroup USART_Last_Bit
\r
229 #define USART_LastBit_Disable ((uint16_t)0x0000)
\r
230 #define USART_LastBit_Enable ((uint16_t)0x0100)
\r
231 #define IS_USART_LASTBIT(LASTBIT) (((LASTBIT) == USART_LastBit_Disable) || \
\r
232 ((LASTBIT) == USART_LastBit_Enable))
\r
237 /** @defgroup USART_Interrupt_definition
\r
241 #define USART_IT_PE ((uint16_t)0x0028)
\r
242 #define USART_IT_TXE ((uint16_t)0x0727)
\r
243 #define USART_IT_TC ((uint16_t)0x0626)
\r
244 #define USART_IT_RXNE ((uint16_t)0x0525)
\r
245 #define USART_IT_IDLE ((uint16_t)0x0424)
\r
246 #define USART_IT_LBD ((uint16_t)0x0846)
\r
247 #define USART_IT_ORE_RX ((uint16_t)0x0325) /* In case interrupt is generated if the RXNEIE bit is set */
\r
248 #define USART_IT_CTS ((uint16_t)0x096A)
\r
249 #define USART_IT_ERR ((uint16_t)0x0060)
\r
250 #define USART_IT_ORE_ER ((uint16_t)0x0360) /* In case interrupt is generated if the EIE bit is set */
\r
251 #define USART_IT_NE ((uint16_t)0x0260)
\r
252 #define USART_IT_FE ((uint16_t)0x0160)
\r
254 /** @defgroup USART_Legacy
\r
257 #define USART_IT_ORE USART_IT_ORE_ER
\r
262 #define IS_USART_CONFIG_IT(IT) (((IT) == USART_IT_PE) || ((IT) == USART_IT_TXE) || \
\r
263 ((IT) == USART_IT_TC) || ((IT) == USART_IT_RXNE) || \
\r
264 ((IT) == USART_IT_IDLE) || ((IT) == USART_IT_LBD) || \
\r
265 ((IT) == USART_IT_CTS) || ((IT) == USART_IT_ERR))
\r
266 #define IS_USART_GET_IT(IT) (((IT) == USART_IT_PE) || ((IT) == USART_IT_TXE) || \
\r
267 ((IT) == USART_IT_TC) || ((IT) == USART_IT_RXNE) || \
\r
268 ((IT) == USART_IT_IDLE) || ((IT) == USART_IT_LBD) || \
\r
269 ((IT) == USART_IT_CTS) || ((IT) == USART_IT_ORE_RX) || \
\r
270 ((IT) == USART_IT_ORE_ER) || ((IT) == USART_IT_NE) || \
\r
271 ((IT) == USART_IT_FE))
\r
272 #define IS_USART_CLEAR_IT(IT) (((IT) == USART_IT_TC) || ((IT) == USART_IT_RXNE) || \
\r
273 ((IT) == USART_IT_LBD) || ((IT) == USART_IT_CTS))
\r
278 /** @defgroup USART_DMA_Requests
\r
282 #define USART_DMAReq_Tx ((uint16_t)0x0080)
\r
283 #define USART_DMAReq_Rx ((uint16_t)0x0040)
\r
284 #define IS_USART_DMAREQ(DMAREQ) ((((DMAREQ) & (uint16_t)0xFF3F) == 0x00) && ((DMAREQ) != (uint16_t)0x00))
\r
290 /** @defgroup USART_WakeUp_methods
\r
294 #define USART_WakeUp_IdleLine ((uint16_t)0x0000)
\r
295 #define USART_WakeUp_AddressMark ((uint16_t)0x0800)
\r
296 #define IS_USART_WAKEUP(WAKEUP) (((WAKEUP) == USART_WakeUp_IdleLine) || \
\r
297 ((WAKEUP) == USART_WakeUp_AddressMark))
\r
302 /** @defgroup USART_LIN_Break_Detection_Length
\r
306 #define USART_LINBreakDetectLength_10b ((uint16_t)0x0000)
\r
307 #define USART_LINBreakDetectLength_11b ((uint16_t)0x0020)
\r
308 #define IS_USART_LIN_BREAK_DETECT_LENGTH(LENGTH) \
\r
309 (((LENGTH) == USART_LINBreakDetectLength_10b) || \
\r
310 ((LENGTH) == USART_LINBreakDetectLength_11b))
\r
315 /** @defgroup USART_IrDA_Low_Power
\r
319 #define USART_IrDAMode_LowPower ((uint16_t)0x0004)
\r
320 #define USART_IrDAMode_Normal ((uint16_t)0x0000)
\r
321 #define IS_USART_IRDA_MODE(MODE) (((MODE) == USART_IrDAMode_LowPower) || \
\r
322 ((MODE) == USART_IrDAMode_Normal))
\r
327 /** @defgroup USART_Flags
\r
331 #define USART_FLAG_CTS ((uint16_t)0x0200)
\r
332 #define USART_FLAG_LBD ((uint16_t)0x0100)
\r
333 #define USART_FLAG_TXE ((uint16_t)0x0080)
\r
334 #define USART_FLAG_TC ((uint16_t)0x0040)
\r
335 #define USART_FLAG_RXNE ((uint16_t)0x0020)
\r
336 #define USART_FLAG_IDLE ((uint16_t)0x0010)
\r
337 #define USART_FLAG_ORE ((uint16_t)0x0008)
\r
338 #define USART_FLAG_NE ((uint16_t)0x0004)
\r
339 #define USART_FLAG_FE ((uint16_t)0x0002)
\r
340 #define USART_FLAG_PE ((uint16_t)0x0001)
\r
341 #define IS_USART_FLAG(FLAG) (((FLAG) == USART_FLAG_PE) || ((FLAG) == USART_FLAG_TXE) || \
\r
342 ((FLAG) == USART_FLAG_TC) || ((FLAG) == USART_FLAG_RXNE) || \
\r
343 ((FLAG) == USART_FLAG_IDLE) || ((FLAG) == USART_FLAG_LBD) || \
\r
344 ((FLAG) == USART_FLAG_CTS) || ((FLAG) == USART_FLAG_ORE) || \
\r
345 ((FLAG) == USART_FLAG_NE) || ((FLAG) == USART_FLAG_FE))
\r
347 #define IS_USART_CLEAR_FLAG(FLAG) ((((FLAG) & (uint16_t)0xFC9F) == 0x00) && ((FLAG) != (uint16_t)0x00))
\r
349 #define IS_USART_BAUDRATE(BAUDRATE) (((BAUDRATE) > 0) && ((BAUDRATE) < 0x003D0901))
\r
350 #define IS_USART_ADDRESS(ADDRESS) ((ADDRESS) <= 0xF)
\r
351 #define IS_USART_DATA(DATA) ((DATA) <= 0x1FF)
\r
361 /* Exported macro ------------------------------------------------------------*/
\r
362 /* Exported functions ------------------------------------------------------- */
\r
364 /* Function used to set the USART configuration to the default reset state ***/
\r
365 void USART_DeInit(USART_TypeDef* USARTx);
\r
367 /* Initialization and Configuration functions *********************************/
\r
368 void USART_Init(USART_TypeDef* USARTx, USART_InitTypeDef* USART_InitStruct);
\r
369 void USART_StructInit(USART_InitTypeDef* USART_InitStruct);
\r
370 void USART_ClockInit(USART_TypeDef* USARTx, USART_ClockInitTypeDef* USART_ClockInitStruct);
\r
371 void USART_ClockStructInit(USART_ClockInitTypeDef* USART_ClockInitStruct);
\r
372 void USART_Cmd(USART_TypeDef* USARTx, FunctionalState NewState);
\r
373 void USART_SetPrescaler(USART_TypeDef* USARTx, uint8_t USART_Prescaler);
\r
374 void USART_OverSampling8Cmd(USART_TypeDef* USARTx, FunctionalState NewState);
\r
375 void USART_OneBitMethodCmd(USART_TypeDef* USARTx, FunctionalState NewState);
\r
377 /* Data transfers functions ***************************************************/
\r
378 void USART_SendData(USART_TypeDef* USARTx, uint16_t Data);
\r
379 uint16_t USART_ReceiveData(USART_TypeDef* USARTx);
\r
381 /* Multi-Processor Communication functions ************************************/
\r
382 void USART_SetAddress(USART_TypeDef* USARTx, uint8_t USART_Address);
\r
383 void USART_WakeUpConfig(USART_TypeDef* USARTx, uint16_t USART_WakeUp);
\r
384 void USART_ReceiverWakeUpCmd(USART_TypeDef* USARTx, FunctionalState NewState);
\r
386 /* LIN mode functions *********************************************************/
\r
387 void USART_LINBreakDetectLengthConfig(USART_TypeDef* USARTx, uint16_t USART_LINBreakDetectLength);
\r
388 void USART_LINCmd(USART_TypeDef* USARTx, FunctionalState NewState);
\r
389 void USART_SendBreak(USART_TypeDef* USARTx);
\r
391 /* Half-duplex mode function **************************************************/
\r
392 void USART_HalfDuplexCmd(USART_TypeDef* USARTx, FunctionalState NewState);
\r
394 /* Smartcard mode functions ***************************************************/
\r
395 void USART_SmartCardCmd(USART_TypeDef* USARTx, FunctionalState NewState);
\r
396 void USART_SmartCardNACKCmd(USART_TypeDef* USARTx, FunctionalState NewState);
\r
397 void USART_SetGuardTime(USART_TypeDef* USARTx, uint8_t USART_GuardTime);
\r
399 /* IrDA mode functions ********************************************************/
\r
400 void USART_IrDAConfig(USART_TypeDef* USARTx, uint16_t USART_IrDAMode);
\r
401 void USART_IrDACmd(USART_TypeDef* USARTx, FunctionalState NewState);
\r
403 /* DMA transfers management functions *****************************************/
\r
404 void USART_DMACmd(USART_TypeDef* USARTx, uint16_t USART_DMAReq, FunctionalState NewState);
\r
406 /* Interrupts and flags management functions **********************************/
\r
407 void USART_ITConfig(USART_TypeDef* USARTx, uint16_t USART_IT, FunctionalState NewState);
\r
408 FlagStatus USART_GetFlagStatus(USART_TypeDef* USARTx, uint16_t USART_FLAG);
\r
409 void USART_ClearFlag(USART_TypeDef* USARTx, uint16_t USART_FLAG);
\r
410 ITStatus USART_GetITStatus(USART_TypeDef* USARTx, uint16_t USART_IT);
\r
411 void USART_ClearITPendingBit(USART_TypeDef* USARTx, uint16_t USART_IT);
\r
417 #endif /* __STM32L1xx_USART_H */
\r
427 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
\r