23 #ifndef __STM32F10x_USART_H
24 #define __STM32F10x_USART_H
31 #include "stm32f10x.h"
51 uint32_t USART_BaudRate;
56 uint16_t USART_WordLength;
59 uint16_t USART_StopBits;
62 uint16_t USART_Parity;
72 uint16_t USART_HardwareFlowControl;
93 uint16_t USART_LastBit;
106 #define IS_USART_ALL_PERIPH(PERIPH) (((PERIPH) == USART1) || \
107 ((PERIPH) == USART2) || \
108 ((PERIPH) == USART3) || \
109 ((PERIPH) == UART4) || \
112 #define IS_USART_123_PERIPH(PERIPH) (((PERIPH) == USART1) || \
113 ((PERIPH) == USART2) || \
114 ((PERIPH) == USART3))
116 #define IS_USART_1234_PERIPH(PERIPH) (((PERIPH) == USART1) || \
117 ((PERIPH) == USART2) || \
118 ((PERIPH) == USART3) || \
124 #define USART_WordLength_8b ((uint16_t)0x0000)
125 #define USART_WordLength_9b ((uint16_t)0x1000)
127 #define IS_USART_WORD_LENGTH(LENGTH) (((LENGTH) == USART_WordLength_8b) || \
128 ((LENGTH) == USART_WordLength_9b))
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))
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))
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))
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))
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))
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))
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))
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))
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))
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))
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))
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))
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))
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))
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)
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);
376 void USART_LINCmd(USART_TypeDef* USARTx, FunctionalState NewState);
388 void USART_IrDACmd(USART_TypeDef* USARTx, FunctionalState NewState);
394 void USART_putchar(USART_TypeDef* USARTx, uint16_t Data);
395 uint8_t USART_getchar(USART_TypeDef* USARTx);