STM32F10x Standard Peripherals Library
3.5.0
|
00001 00023 /* Define to prevent recursive inclusion -------------------------------------*/ 00024 #ifndef __STM32F10x_USART_H 00025 #define __STM32F10x_USART_H 00026 00027 #ifdef __cplusplus 00028 extern "C" { 00029 #endif 00030 00031 /* Includes ------------------------------------------------------------------*/ 00032 #include "stm32f10x.h" 00033 00050 typedef struct 00051 { 00052 uint32_t USART_BaudRate; 00057 uint16_t USART_WordLength; 00060 uint16_t USART_StopBits; 00063 uint16_t USART_Parity; 00070 uint16_t USART_Mode; 00073 uint16_t USART_HardwareFlowControl; 00076 } USART_InitTypeDef; 00077 00082 typedef struct 00083 { 00084 00085 uint16_t USART_Clock; 00088 uint16_t USART_CPOL; 00091 uint16_t USART_CPHA; 00094 uint16_t USART_LastBit; 00097 } USART_ClockInitTypeDef; 00098 00107 #define IS_USART_ALL_PERIPH(PERIPH) (((PERIPH) == USART1) || \ 00108 ((PERIPH) == USART2) || \ 00109 ((PERIPH) == USART3) || \ 00110 ((PERIPH) == UART4) || \ 00111 ((PERIPH) == UART5)) 00112 00113 #define IS_USART_123_PERIPH(PERIPH) (((PERIPH) == USART1) || \ 00114 ((PERIPH) == USART2) || \ 00115 ((PERIPH) == USART3)) 00116 00117 #define IS_USART_1234_PERIPH(PERIPH) (((PERIPH) == USART1) || \ 00118 ((PERIPH) == USART2) || \ 00119 ((PERIPH) == USART3) || \ 00120 ((PERIPH) == UART4)) 00121 00125 #define USART_WordLength_8b ((uint16_t)0x0000) 00126 #define USART_WordLength_9b ((uint16_t)0x1000) 00127 00128 #define IS_USART_WORD_LENGTH(LENGTH) (((LENGTH) == USART_WordLength_8b) || \ 00129 ((LENGTH) == USART_WordLength_9b)) 00130 00138 #define USART_StopBits_1 ((uint16_t)0x0000) 00139 #define USART_StopBits_0_5 ((uint16_t)0x1000) 00140 #define USART_StopBits_2 ((uint16_t)0x2000) 00141 #define USART_StopBits_1_5 ((uint16_t)0x3000) 00142 #define IS_USART_STOPBITS(STOPBITS) (((STOPBITS) == USART_StopBits_1) || \ 00143 ((STOPBITS) == USART_StopBits_0_5) || \ 00144 ((STOPBITS) == USART_StopBits_2) || \ 00145 ((STOPBITS) == USART_StopBits_1_5)) 00146 00154 #define USART_Parity_No ((uint16_t)0x0000) 00155 #define USART_Parity_Even ((uint16_t)0x0400) 00156 #define USART_Parity_Odd ((uint16_t)0x0600) 00157 #define IS_USART_PARITY(PARITY) (((PARITY) == USART_Parity_No) || \ 00158 ((PARITY) == USART_Parity_Even) || \ 00159 ((PARITY) == USART_Parity_Odd)) 00160 00168 #define USART_Mode_Rx ((uint16_t)0x0004) 00169 #define USART_Mode_Tx ((uint16_t)0x0008) 00170 #define IS_USART_MODE(MODE) ((((MODE) & (uint16_t)0xFFF3) == 0x00) && ((MODE) != (uint16_t)0x00)) 00171 00178 #define USART_HardwareFlowControl_None ((uint16_t)0x0000) 00179 #define USART_HardwareFlowControl_RTS ((uint16_t)0x0100) 00180 #define USART_HardwareFlowControl_CTS ((uint16_t)0x0200) 00181 #define USART_HardwareFlowControl_RTS_CTS ((uint16_t)0x0300) 00182 #define IS_USART_HARDWARE_FLOW_CONTROL(CONTROL)\ 00183 (((CONTROL) == USART_HardwareFlowControl_None) || \ 00184 ((CONTROL) == USART_HardwareFlowControl_RTS) || \ 00185 ((CONTROL) == USART_HardwareFlowControl_CTS) || \ 00186 ((CONTROL) == USART_HardwareFlowControl_RTS_CTS)) 00187 00194 #define USART_Clock_Disable ((uint16_t)0x0000) 00195 #define USART_Clock_Enable ((uint16_t)0x0800) 00196 #define IS_USART_CLOCK(CLOCK) (((CLOCK) == USART_Clock_Disable) || \ 00197 ((CLOCK) == USART_Clock_Enable)) 00198 00206 #define USART_CPOL_Low ((uint16_t)0x0000) 00207 #define USART_CPOL_High ((uint16_t)0x0400) 00208 #define IS_USART_CPOL(CPOL) (((CPOL) == USART_CPOL_Low) || ((CPOL) == USART_CPOL_High)) 00209 00218 #define USART_CPHA_1Edge ((uint16_t)0x0000) 00219 #define USART_CPHA_2Edge ((uint16_t)0x0200) 00220 #define IS_USART_CPHA(CPHA) (((CPHA) == USART_CPHA_1Edge) || ((CPHA) == USART_CPHA_2Edge)) 00221 00230 #define USART_LastBit_Disable ((uint16_t)0x0000) 00231 #define USART_LastBit_Enable ((uint16_t)0x0100) 00232 #define IS_USART_LASTBIT(LASTBIT) (((LASTBIT) == USART_LastBit_Disable) || \ 00233 ((LASTBIT) == USART_LastBit_Enable)) 00234 00242 #define USART_IT_PE ((uint16_t)0x0028) 00243 #define USART_IT_TXE ((uint16_t)0x0727) 00244 #define USART_IT_TC ((uint16_t)0x0626) 00245 #define USART_IT_RXNE ((uint16_t)0x0525) 00246 #define USART_IT_IDLE ((uint16_t)0x0424) 00247 #define USART_IT_LBD ((uint16_t)0x0846) 00248 #define USART_IT_CTS ((uint16_t)0x096A) 00249 #define USART_IT_ERR ((uint16_t)0x0060) 00250 #define USART_IT_ORE ((uint16_t)0x0360) 00251 #define USART_IT_NE ((uint16_t)0x0260) 00252 #define USART_IT_FE ((uint16_t)0x0160) 00253 #define IS_USART_CONFIG_IT(IT) (((IT) == USART_IT_PE) || ((IT) == USART_IT_TXE) || \ 00254 ((IT) == USART_IT_TC) || ((IT) == USART_IT_RXNE) || \ 00255 ((IT) == USART_IT_IDLE) || ((IT) == USART_IT_LBD) || \ 00256 ((IT) == USART_IT_CTS) || ((IT) == USART_IT_ERR)) 00257 #define IS_USART_GET_IT(IT) (((IT) == USART_IT_PE) || ((IT) == USART_IT_TXE) || \ 00258 ((IT) == USART_IT_TC) || ((IT) == USART_IT_RXNE) || \ 00259 ((IT) == USART_IT_IDLE) || ((IT) == USART_IT_LBD) || \ 00260 ((IT) == USART_IT_CTS) || ((IT) == USART_IT_ORE) || \ 00261 ((IT) == USART_IT_NE) || ((IT) == USART_IT_FE)) 00262 #define IS_USART_CLEAR_IT(IT) (((IT) == USART_IT_TC) || ((IT) == USART_IT_RXNE) || \ 00263 ((IT) == USART_IT_LBD) || ((IT) == USART_IT_CTS)) 00264 00272 #define USART_DMAReq_Tx ((uint16_t)0x0080) 00273 #define USART_DMAReq_Rx ((uint16_t)0x0040) 00274 #define IS_USART_DMAREQ(DMAREQ) ((((DMAREQ) & (uint16_t)0xFF3F) == 0x00) && ((DMAREQ) != (uint16_t)0x00)) 00275 00284 #define USART_WakeUp_IdleLine ((uint16_t)0x0000) 00285 #define USART_WakeUp_AddressMark ((uint16_t)0x0800) 00286 #define IS_USART_WAKEUP(WAKEUP) (((WAKEUP) == USART_WakeUp_IdleLine) || \ 00287 ((WAKEUP) == USART_WakeUp_AddressMark)) 00288 00296 #define USART_LINBreakDetectLength_10b ((uint16_t)0x0000) 00297 #define USART_LINBreakDetectLength_11b ((uint16_t)0x0020) 00298 #define IS_USART_LIN_BREAK_DETECT_LENGTH(LENGTH) \ 00299 (((LENGTH) == USART_LINBreakDetectLength_10b) || \ 00300 ((LENGTH) == USART_LINBreakDetectLength_11b)) 00301 00309 #define USART_IrDAMode_LowPower ((uint16_t)0x0004) 00310 #define USART_IrDAMode_Normal ((uint16_t)0x0000) 00311 #define IS_USART_IRDA_MODE(MODE) (((MODE) == USART_IrDAMode_LowPower) || \ 00312 ((MODE) == USART_IrDAMode_Normal)) 00313 00321 #define USART_FLAG_CTS ((uint16_t)0x0200) 00322 #define USART_FLAG_LBD ((uint16_t)0x0100) 00323 #define USART_FLAG_TXE ((uint16_t)0x0080) 00324 #define USART_FLAG_TC ((uint16_t)0x0040) 00325 #define USART_FLAG_RXNE ((uint16_t)0x0020) 00326 #define USART_FLAG_IDLE ((uint16_t)0x0010) 00327 #define USART_FLAG_ORE ((uint16_t)0x0008) 00328 #define USART_FLAG_NE ((uint16_t)0x0004) 00329 #define USART_FLAG_FE ((uint16_t)0x0002) 00330 #define USART_FLAG_PE ((uint16_t)0x0001) 00331 #define IS_USART_FLAG(FLAG) (((FLAG) == USART_FLAG_PE) || ((FLAG) == USART_FLAG_TXE) || \ 00332 ((FLAG) == USART_FLAG_TC) || ((FLAG) == USART_FLAG_RXNE) || \ 00333 ((FLAG) == USART_FLAG_IDLE) || ((FLAG) == USART_FLAG_LBD) || \ 00334 ((FLAG) == USART_FLAG_CTS) || ((FLAG) == USART_FLAG_ORE) || \ 00335 ((FLAG) == USART_FLAG_NE) || ((FLAG) == USART_FLAG_FE)) 00336 00337 #define IS_USART_CLEAR_FLAG(FLAG) ((((FLAG) & (uint16_t)0xFC9F) == 0x00) && ((FLAG) != (uint16_t)0x00)) 00338 #define IS_USART_PERIPH_FLAG(PERIPH, USART_FLAG) ((((*(uint32_t*)&(PERIPH)) != UART4_BASE) &&\ 00339 ((*(uint32_t*)&(PERIPH)) != UART5_BASE)) \ 00340 || ((USART_FLAG) != USART_FLAG_CTS)) 00341 #define IS_USART_BAUDRATE(BAUDRATE) (((BAUDRATE) > 0) && ((BAUDRATE) < 0x0044AA21)) 00342 #define IS_USART_ADDRESS(ADDRESS) ((ADDRESS) <= 0xF) 00343 #define IS_USART_DATA(DATA) ((DATA) <= 0x1FF) 00344 00365 void USART_DeInit(USART_TypeDef* USARTx); 00366 void USART_Init(USART_TypeDef* USARTx, USART_InitTypeDef* USART_InitStruct); 00367 void USART_StructInit(USART_InitTypeDef* USART_InitStruct); 00368 void USART_ClockInit(USART_TypeDef* USARTx, USART_ClockInitTypeDef* USART_ClockInitStruct); 00369 void USART_ClockStructInit(USART_ClockInitTypeDef* USART_ClockInitStruct); 00370 void USART_Cmd(USART_TypeDef* USARTx, FunctionalState NewState); 00371 void USART_ITConfig(USART_TypeDef* USARTx, uint16_t USART_IT, FunctionalState NewState); 00372 void USART_DMACmd(USART_TypeDef* USARTx, uint16_t USART_DMAReq, FunctionalState NewState); 00373 void USART_SetAddress(USART_TypeDef* USARTx, uint8_t USART_Address); 00374 void USART_WakeUpConfig(USART_TypeDef* USARTx, uint16_t USART_WakeUp); 00375 void USART_ReceiverWakeUpCmd(USART_TypeDef* USARTx, FunctionalState NewState); 00376 void USART_LINBreakDetectLengthConfig(USART_TypeDef* USARTx, uint16_t USART_LINBreakDetectLength); 00377 void USART_LINCmd(USART_TypeDef* USARTx, FunctionalState NewState); 00378 void USART_SendData(USART_TypeDef* USARTx, uint16_t Data); 00379 uint16_t USART_ReceiveData(USART_TypeDef* USARTx); 00380 void USART_SendBreak(USART_TypeDef* USARTx); 00381 void USART_SetGuardTime(USART_TypeDef* USARTx, uint8_t USART_GuardTime); 00382 void USART_SetPrescaler(USART_TypeDef* USARTx, uint8_t USART_Prescaler); 00383 void USART_SmartCardCmd(USART_TypeDef* USARTx, FunctionalState NewState); 00384 void USART_SmartCardNACKCmd(USART_TypeDef* USARTx, FunctionalState NewState); 00385 void USART_HalfDuplexCmd(USART_TypeDef* USARTx, FunctionalState NewState); 00386 void USART_OverSampling8Cmd(USART_TypeDef* USARTx, FunctionalState NewState); 00387 void USART_OneBitMethodCmd(USART_TypeDef* USARTx, FunctionalState NewState); 00388 void USART_IrDAConfig(USART_TypeDef* USARTx, uint16_t USART_IrDAMode); 00389 void USART_IrDACmd(USART_TypeDef* USARTx, FunctionalState NewState); 00390 FlagStatus USART_GetFlagStatus(USART_TypeDef* USARTx, uint16_t USART_FLAG); 00391 void USART_ClearFlag(USART_TypeDef* USARTx, uint16_t USART_FLAG); 00392 ITStatus USART_GetITStatus(USART_TypeDef* USARTx, uint16_t USART_IT); 00393 void USART_ClearITPendingBit(USART_TypeDef* USARTx, uint16_t USART_IT); 00394 00395 #ifdef __cplusplus 00396 } 00397 #endif 00398 00399 #endif /* __STM32F10x_USART_H */ 00400 00412 /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/