Rev Author Line No. Line
3328 povik 1 /**
2 ******************************************************************************
3 * @file stm32f10x_usart.h
4 * @author MCD Application Team
5 * @version V3.1.0
6 * @date 06/19/2009
7 * @brief This file contains all the functions prototypes for the USART
8 * firmware library.
9 ******************************************************************************
10 * @copy
11 *
12 * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
13 * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
14 * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
15 * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
16 * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
17 * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
18 *
19 * <h2><center>&copy; COPYRIGHT 2009 STMicroelectronics</center></h2>
20 */
21  
22 /* Define to prevent recursive inclusion -------------------------------------*/
23 #ifndef __STM32F10x_USART_H
24 #define __STM32F10x_USART_H
25  
26 #ifdef __cplusplus
27 extern "C" {
28 #endif
29  
30 /* Includes ------------------------------------------------------------------*/
31 #include "stm32f10x.h"
32  
33 /** @addtogroup STM32F10x_StdPeriph_Driver
34 * @{
35 */
36  
37 /** @addtogroup USART
38 * @{
39 */
40  
41 /** @defgroup USART_Exported_Types
42 * @{
43 */
44  
45 /**
46 * @brief USART Init Structure definition
47 */
48  
49 typedef struct
50 {
51 uint32_t USART_BaudRate; /*!< This member configures the USART communication baud rate.
52 The baud rate is computed using the following formula:
53 - IntegerDivider = ((PCLKx) / (16 * (USART_InitStruct->USART_BaudRate)))
54 - FractionalDivider = ((IntegerDivider - ((u32) IntegerDivider)) * 16) + 0.5 */
55  
56 uint16_t USART_WordLength; /*!< Specifies the number of data bits transmitted or received in a frame.
57 This parameter can be a value of @ref USART_Word_Length */
58  
59 uint16_t USART_StopBits; /*!< Specifies the number of stop bits transmitted.
60 This parameter can be a value of @ref USART_Stop_Bits */
61  
62 uint16_t USART_Parity; /*!< Specifies the parity mode.
63 This parameter can be a value of @ref USART_Parity
64 @note When parity is enabled, the computed parity is inserted
65 at the MSB position of the transmitted data (9th bit when
66 the word length is set to 9 data bits; 8th bit when the
67 word length is set to 8 data bits). */
68  
69 uint16_t USART_Mode; /*!< Specifies wether the Receive or Transmit mode is enabled or disabled.
70 This parameter can be a value of @ref USART_Mode */
71  
72 uint16_t USART_HardwareFlowControl; /*!< Specifies wether the hardware flow control mode is enabled
73 or disabled.
74 This parameter can be a value of @ref USART_Hardware_Flow_Control */
75 } USART_InitTypeDef;
76  
77 /**
78 * @brief USART Clock Init Structure definition
79 */
80  
81 typedef struct
82 {
83  
84 uint16_t USART_Clock; /*!< Specifies whether the USART clock is enabled or disabled.
85 This parameter can be a value of @ref USART_Clock */
86  
87 uint16_t USART_CPOL; /*!< Specifies the steady state value of the serial clock.
88 This parameter can be a value of @ref USART_Clock_Polarity */
89  
90 uint16_t USART_CPHA; /*!< Specifies the clock transition on which the bit capture is made.
91 This parameter can be a value of @ref USART_Clock_Phase */
92  
93 uint16_t USART_LastBit; /*!< Specifies whether the clock pulse corresponding to the last transmitted
94 data bit (MSB) has to be output on the SCLK pin in synchronous mode.
95 This parameter can be a value of @ref USART_Last_Bit */
96 } USART_ClockInitTypeDef;
97  
98 /**
99 * @}
100 */
101  
102 /** @defgroup USART_Exported_Constants
103 * @{
104 */
105  
106 #define IS_USART_ALL_PERIPH(PERIPH) (((PERIPH) == USART1) || \
107 ((PERIPH) == USART2) || \
108 ((PERIPH) == USART3) || \
109 ((PERIPH) == UART4) || \
110 ((PERIPH) == UART5))
111  
112 #define IS_USART_123_PERIPH(PERIPH) (((PERIPH) == USART1) || \
113 ((PERIPH) == USART2) || \
114 ((PERIPH) == USART3))
115  
116 #define IS_USART_1234_PERIPH(PERIPH) (((PERIPH) == USART1) || \
117 ((PERIPH) == USART2) || \
118 ((PERIPH) == USART3) || \
119 ((PERIPH) == UART4))
120 /** @defgroup USART_Word_Length
121 * @{
122 */
123  
124 #define USART_WordLength_8b ((uint16_t)0x0000)
125 #define USART_WordLength_9b ((uint16_t)0x1000)
126  
127 #define IS_USART_WORD_LENGTH(LENGTH) (((LENGTH) == USART_WordLength_8b) || \
128 ((LENGTH) == USART_WordLength_9b))
129 /**
130 * @}
131 */
132  
133 /** @defgroup USART_Stop_Bits
134 * @{
135 */
136  
137 #define USART_StopBits_1 ((uint16_t)0x0000)
138 #define USART_StopBits_0_5 ((uint16_t)0x1000)
139 #define USART_StopBits_2 ((uint16_t)0x2000)
140 #define USART_StopBits_1_5 ((uint16_t)0x3000)
141 #define IS_USART_STOPBITS(STOPBITS) (((STOPBITS) == USART_StopBits_1) || \
142 ((STOPBITS) == USART_StopBits_0_5) || \
143 ((STOPBITS) == USART_StopBits_2) || \
144 ((STOPBITS) == USART_StopBits_1_5))
145 /**
146 * @}
147 */
148  
149 /** @defgroup USART_Parity
150 * @{
151 */
152  
153 #define USART_Parity_No ((uint16_t)0x0000)
154 #define USART_Parity_Even ((uint16_t)0x0400)
155 #define USART_Parity_Odd ((uint16_t)0x0600)
156 #define IS_USART_PARITY(PARITY) (((PARITY) == USART_Parity_No) || \
157 ((PARITY) == USART_Parity_Even) || \
158 ((PARITY) == USART_Parity_Odd))
159 /**
160 * @}
161 */
162  
163 /** @defgroup USART_Mode
164 * @{
165 */
166  
167 #define USART_Mode_Rx ((uint16_t)0x0004)
168 #define USART_Mode_Tx ((uint16_t)0x0008)
169 #define IS_USART_MODE(MODE) ((((MODE) & (uint16_t)0xFFF3) == 0x00) && ((MODE) != (uint16_t)0x00))
170 /**
171 * @}
172 */
173  
174 /** @defgroup USART_Hardware_Flow_Control
175 * @{
176 */
177 #define USART_HardwareFlowControl_None ((uint16_t)0x0000)
178 #define USART_HardwareFlowControl_RTS ((uint16_t)0x0100)
179 #define USART_HardwareFlowControl_CTS ((uint16_t)0x0200)
180 #define USART_HardwareFlowControl_RTS_CTS ((uint16_t)0x0300)
181 #define IS_USART_HARDWARE_FLOW_CONTROL(CONTROL)\
182 (((CONTROL) == USART_HardwareFlowControl_None) || \
183 ((CONTROL) == USART_HardwareFlowControl_RTS) || \
184 ((CONTROL) == USART_HardwareFlowControl_CTS) || \
185 ((CONTROL) == USART_HardwareFlowControl_RTS_CTS))
186 /**
187 * @}
188 */
189  
190 /** @defgroup USART_Clock
191 * @{
192 */
193 #define USART_Clock_Disable ((uint16_t)0x0000)
194 #define USART_Clock_Enable ((uint16_t)0x0800)
195 #define IS_USART_CLOCK(CLOCK) (((CLOCK) == USART_Clock_Disable) || \
196 ((CLOCK) == USART_Clock_Enable))
197 /**
198 * @}
199 */
200  
201 /** @defgroup USART_Clock_Polarity
202 * @{
203 */
204  
205 #define USART_CPOL_Low ((uint16_t)0x0000)
206 #define USART_CPOL_High ((uint16_t)0x0400)
207 #define IS_USART_CPOL(CPOL) (((CPOL) == USART_CPOL_Low) || ((CPOL) == USART_CPOL_High))
208  
209 /**
210 * @}
211 */
212  
213 /** @defgroup USART_Clock_Phase
214 * @{
215 */
216  
217 #define USART_CPHA_1Edge ((uint16_t)0x0000)
218 #define USART_CPHA_2Edge ((uint16_t)0x0200)
219 #define IS_USART_CPHA(CPHA) (((CPHA) == USART_CPHA_1Edge) || ((CPHA) == USART_CPHA_2Edge))
220  
221 /**
222 * @}
223 */
224  
225 /** @defgroup USART_Last_Bit
226 * @{
227 */
228  
229 #define USART_LastBit_Disable ((uint16_t)0x0000)
230 #define USART_LastBit_Enable ((uint16_t)0x0100)
231 #define IS_USART_LASTBIT(LASTBIT) (((LASTBIT) == USART_LastBit_Disable) || \
232 ((LASTBIT) == USART_LastBit_Enable))
233 /**
234 * @}
235 */
236  
237 /** @defgroup USART_Interrupt_definition
238 * @{
239 */
240  
241 #define USART_IT_PE ((uint16_t)0x0028)
242 #define USART_IT_TXE ((uint16_t)0x0727)
243 #define USART_IT_TC ((uint16_t)0x0626)
244 #define USART_IT_RXNE ((uint16_t)0x0525)
245 #define USART_IT_IDLE ((uint16_t)0x0424)
246 #define USART_IT_LBD ((uint16_t)0x0846)
247 #define USART_IT_CTS ((uint16_t)0x096A)
248 #define USART_IT_ERR ((uint16_t)0x0060)
249 #define USART_IT_ORE ((uint16_t)0x0360)
250 #define USART_IT_NE ((uint16_t)0x0260)
251 #define USART_IT_FE ((uint16_t)0x0160)
252 #define IS_USART_CONFIG_IT(IT) (((IT) == USART_IT_PE) || ((IT) == USART_IT_TXE) || \
253 ((IT) == USART_IT_TC) || ((IT) == USART_IT_RXNE) || \
254 ((IT) == USART_IT_IDLE) || ((IT) == USART_IT_LBD) || \
255 ((IT) == USART_IT_CTS) || ((IT) == USART_IT_ERR))
256 #define IS_USART_GET_IT(IT) (((IT) == USART_IT_PE) || ((IT) == USART_IT_TXE) || \
257 ((IT) == USART_IT_TC) || ((IT) == USART_IT_RXNE) || \
258 ((IT) == USART_IT_IDLE) || ((IT) == USART_IT_LBD) || \
259 ((IT) == USART_IT_CTS) || ((IT) == USART_IT_ORE) || \
260 ((IT) == USART_IT_NE) || ((IT) == USART_IT_FE))
261 #define IS_USART_CLEAR_IT(IT) (((IT) == USART_IT_TC) || ((IT) == USART_IT_RXNE) || \
262 ((IT) == USART_IT_LBD) || ((IT) == USART_IT_CTS))
263 /**
264 * @}
265 */
266  
267 /** @defgroup USART_DMA_Requests
268 * @{
269 */
270  
271 #define USART_DMAReq_Tx ((uint16_t)0x0080)
272 #define USART_DMAReq_Rx ((uint16_t)0x0040)
273 #define IS_USART_DMAREQ(DMAREQ) ((((DMAREQ) & (uint16_t)0xFF3F) == 0x00) && ((DMAREQ) != (uint16_t)0x00))
274  
275 /**
276 * @}
277 */
278  
279 /** @defgroup USART_WakeUp_methods
280 * @{
281 */
282  
283 #define USART_WakeUp_IdleLine ((uint16_t)0x0000)
284 #define USART_WakeUp_AddressMark ((uint16_t)0x0800)
285 #define IS_USART_WAKEUP(WAKEUP) (((WAKEUP) == USART_WakeUp_IdleLine) || \
286 ((WAKEUP) == USART_WakeUp_AddressMark))
287 /**
288 * @}
289 */
290  
291 /** @defgroup USART_LIN_Break_Detection_Length
292 * @{
293 */
294  
295 #define USART_LINBreakDetectLength_10b ((uint16_t)0x0000)
296 #define USART_LINBreakDetectLength_11b ((uint16_t)0x0020)
297 #define IS_USART_LIN_BREAK_DETECT_LENGTH(LENGTH) \
298 (((LENGTH) == USART_LINBreakDetectLength_10b) || \
299 ((LENGTH) == USART_LINBreakDetectLength_11b))
300 /**
301 * @}
302 */
303  
304 /** @defgroup USART_IrDA_Low_Power
305 * @{
306 */
307  
308 #define USART_IrDAMode_LowPower ((uint16_t)0x0004)
309 #define USART_IrDAMode_Normal ((uint16_t)0x0000)
310 #define IS_USART_IRDA_MODE(MODE) (((MODE) == USART_IrDAMode_LowPower) || \
311 ((MODE) == USART_IrDAMode_Normal))
312 /**
313 * @}
314 */
315  
316 /** @defgroup USART_Flags
317 * @{
318 */
319  
320 #define USART_FLAG_CTS ((uint16_t)0x0200)
321 #define USART_FLAG_LBD ((uint16_t)0x0100)
322 #define USART_FLAG_TXE ((uint16_t)0x0080)
323 #define USART_FLAG_TC ((uint16_t)0x0040)
324 #define USART_FLAG_RXNE ((uint16_t)0x0020)
325 #define USART_FLAG_IDLE ((uint16_t)0x0010)
326 #define USART_FLAG_ORE ((uint16_t)0x0008)
327 #define USART_FLAG_NE ((uint16_t)0x0004)
328 #define USART_FLAG_FE ((uint16_t)0x0002)
329 #define USART_FLAG_PE ((uint16_t)0x0001)
330 #define IS_USART_FLAG(FLAG) (((FLAG) == USART_FLAG_PE) || ((FLAG) == USART_FLAG_TXE) || \
331 ((FLAG) == USART_FLAG_TC) || ((FLAG) == USART_FLAG_RXNE) || \
332 ((FLAG) == USART_FLAG_IDLE) || ((FLAG) == USART_FLAG_LBD) || \
333 ((FLAG) == USART_FLAG_CTS) || ((FLAG) == USART_FLAG_ORE) || \
334 ((FLAG) == USART_FLAG_NE) || ((FLAG) == USART_FLAG_FE))
335  
336 #define IS_USART_CLEAR_FLAG(FLAG) ((((FLAG) & (uint16_t)0xFC9F) == 0x00) && ((FLAG) != (uint16_t)0x00))
337 #define IS_USART_PERIPH_FLAG(PERIPH, USART_FLAG) ((((*(uint32_t*)&(PERIPH)) != UART4_BASE) &&\
338 ((*(uint32_t*)&(PERIPH)) != UART5_BASE)) \
339 || ((USART_FLAG) != USART_FLAG_CTS))
340 #define IS_USART_BAUDRATE(BAUDRATE) (((BAUDRATE) > 0) && ((BAUDRATE) < 0x0044AA21))
341 #define IS_USART_ADDRESS(ADDRESS) ((ADDRESS) <= 0xF)
342 #define IS_USART_DATA(DATA) ((DATA) <= 0x1FF)
343  
344 /**
345 * @}
346 */
347  
348 /**
349 * @}
350 */
351  
352 /** @defgroup USART_Exported_Macros
353 * @{
354 */
355  
356 /**
357 * @}
358 */
359  
360 /** @defgroup USART_Exported_Functions
361 * @{
362 */
363  
364 void USART_DeInit(USART_TypeDef* USARTx);
365 void USART_Init(USART_TypeDef* USARTx, USART_InitTypeDef* USART_InitStruct);
366 void USART_StructInit(USART_InitTypeDef* USART_InitStruct);
367 void USART_ClockInit(USART_TypeDef* USARTx, USART_ClockInitTypeDef* USART_ClockInitStruct);
368 void USART_ClockStructInit(USART_ClockInitTypeDef* USART_ClockInitStruct);
369 void USART_Cmd(USART_TypeDef* USARTx, FunctionalState NewState);
370 void USART_ITConfig(USART_TypeDef* USARTx, uint16_t USART_IT, FunctionalState NewState);
371 void USART_DMACmd(USART_TypeDef* USARTx, uint16_t USART_DMAReq, FunctionalState NewState);
372 void USART_SetAddress(USART_TypeDef* USARTx, uint8_t USART_Address);
373 void USART_WakeUpConfig(USART_TypeDef* USARTx, uint16_t USART_WakeUp);
374 void USART_ReceiverWakeUpCmd(USART_TypeDef* USARTx, FunctionalState NewState);
375 void USART_LINBreakDetectLengthConfig(USART_TypeDef* USARTx, uint16_t USART_LINBreakDetectLength);
376 void USART_LINCmd(USART_TypeDef* USARTx, FunctionalState NewState);
377 void USART_SendData(USART_TypeDef* USARTx, uint16_t Data);
378 uint16_t USART_ReceiveData(USART_TypeDef* USARTx);
379 void USART_SendBreak(USART_TypeDef* USARTx);
380 void USART_SetGuardTime(USART_TypeDef* USARTx, uint8_t USART_GuardTime);
381 void USART_SetPrescaler(USART_TypeDef* USARTx, uint8_t USART_Prescaler);
382 void USART_SmartCardCmd(USART_TypeDef* USARTx, FunctionalState NewState);
383 void USART_SmartCardNACKCmd(USART_TypeDef* USARTx, FunctionalState NewState);
384 void USART_HalfDuplexCmd(USART_TypeDef* USARTx, FunctionalState NewState);
385 void USART_IrDAConfig(USART_TypeDef* USARTx, uint16_t USART_IrDAMode);
386 void USART_IrDACmd(USART_TypeDef* USARTx, FunctionalState NewState);
387 FlagStatus USART_GetFlagStatus(USART_TypeDef* USARTx, uint16_t USART_FLAG);
388 void USART_ClearFlag(USART_TypeDef* USARTx, uint16_t USART_FLAG);
389 ITStatus USART_GetITStatus(USART_TypeDef* USARTx, uint16_t USART_IT);
390 void USART_ClearITPendingBit(USART_TypeDef* USARTx, uint16_t USART_IT);
391  
392 #ifdef __cplusplus
393 }
394 #endif
395  
396 #endif /* __STM32F10x_USART_H */
397 /**
398 * @}
399 */
400  
401 /**
402 * @}
403 */
404  
405 /**
406 * @}
407 */
408  
409 /******************* (C) COPYRIGHT 2009 STMicroelectronics *****END OF FILE****/