11 #ifndef __MG32F157_USART_H 12 #define __MG32F157_USART_H 87 #define IS_USART_ALL_PERIPH(PERIPH) (((PERIPH) == USART1) || \ 88 ((PERIPH) == USART2) || \ 89 ((PERIPH) == USART3) || \ 90 ((PERIPH) == UART4) || \ 93 #define IS_USART_123_PERIPH(PERIPH) (((PERIPH) == USART1) || \ 94 ((PERIPH) == USART2) || \ 97 #define IS_USART_1234_PERIPH(PERIPH) (((PERIPH) == USART1) || \ 98 ((PERIPH) == USART2) || \ 99 ((PERIPH) == USART3) || \ 106 #define USART_WordLength_8b ((uint16_t)0x0000) 107 #define USART_WordLength_9b ((uint16_t)0x1000) 109 #define IS_USART_WORD_LENGTH(LENGTH) (((LENGTH) == USART_WordLength_8b) || \ 110 ((LENGTH) == USART_WordLength_9b)) 119 #define USART_StopBits_1 ((uint16_t)0x0000) 120 #define USART_StopBits_0_5 ((uint16_t)0x1000) 121 #define USART_StopBits_2 ((uint16_t)0x2000) 122 #define USART_StopBits_1_5 ((uint16_t)0x3000) 123 #define IS_USART_STOPBITS(STOPBITS) (((STOPBITS) == USART_StopBits_1) || \ 124 ((STOPBITS) == USART_StopBits_0_5) || \ 125 ((STOPBITS) == USART_StopBits_2) || \ 126 ((STOPBITS) == USART_StopBits_1_5)) 135 #define USART_Parity_No ((uint16_t)0x0000) 136 #define USART_Parity_Even ((uint16_t)0x0400) 137 #define USART_Parity_Odd ((uint16_t)0x0600) 138 #define IS_USART_PARITY(PARITY) (((PARITY) == USART_Parity_No) || \ 139 ((PARITY) == USART_Parity_Even) || \ 140 ((PARITY) == USART_Parity_Odd)) 149 #define USART_Mode_Rx ((uint16_t)0x0004) 150 #define USART_Mode_Tx ((uint16_t)0x0008) 151 #define IS_USART_MODE(MODE) ((((MODE) & (uint16_t)0xFFF3) == 0x00) && ((MODE) != (uint16_t)0x00)) 160 #define USART_HardwareFlowControl_None ((uint16_t)0x0000) 161 #define USART_HardwareFlowControl_RTS ((uint16_t)0x0100) 162 #define USART_HardwareFlowControl_CTS ((uint16_t)0x0200) 163 #define USART_HardwareFlowControl_RTS_CTS ((uint16_t)0x0300) 164 #define IS_USART_HARDWARE_FLOW_CONTROL(CONTROL)\ 165 (((CONTROL) == USART_HardwareFlowControl_None) || \ 166 ((CONTROL) == USART_HardwareFlowControl_RTS) || \ 167 ((CONTROL) == USART_HardwareFlowControl_CTS) || \ 168 ((CONTROL) == USART_HardwareFlowControl_RTS_CTS)) 177 #define USART_Clock_Disable ((uint16_t)0x0000) 178 #define USART_Clock_Enable ((uint16_t)0x0800) 179 #define IS_USART_CLOCK(CLOCK) (((CLOCK) == USART_Clock_Disable) || \ 180 ((CLOCK) == USART_Clock_Enable)) 189 #define USART_CPOL_Low ((uint16_t)0x0000) 190 #define USART_CPOL_High ((uint16_t)0x0400) 191 #define IS_USART_CPOL(CPOL) (((CPOL) == USART_CPOL_Low) || ((CPOL) == USART_CPOL_High)) 200 #define USART_CPHA_1Edge ((uint16_t)0x0000) 201 #define USART_CPHA_2Edge ((uint16_t)0x0200) 202 #define IS_USART_CPHA(CPHA) (((CPHA) == USART_CPHA_1Edge) || ((CPHA) == USART_CPHA_2Edge)) 211 #define USART_LastBit_Disable ((uint16_t)0x0000) 212 #define USART_LastBit_Enable ((uint16_t)0x0100) 213 #define IS_USART_LASTBIT(LASTBIT) (((LASTBIT) == USART_LastBit_Disable) || \ 214 ((LASTBIT) == USART_LastBit_Enable)) 223 #define USART_IT_PE ((uint16_t)0x0028) 224 #define USART_IT_TXE ((uint16_t)0x0727) 225 #define USART_IT_TC ((uint16_t)0x0626) 226 #define USART_IT_RXNE ((uint16_t)0x0525) 227 #define USART_IT_IDLE ((uint16_t)0x0424) 228 #define USART_IT_LBD ((uint16_t)0x0846) 229 #define USART_IT_CTS ((uint16_t)0x096A) 230 #define USART_IT_ERR ((uint16_t)0x0060) 231 #define USART_IT_ORE ((uint16_t)0x0360) 232 #define USART_IT_NE ((uint16_t)0x0260) 233 #define USART_IT_FE ((uint16_t)0x0160) 234 #define IS_USART_CONFIG_IT(IT) (((IT) == USART_IT_PE) || ((IT) == USART_IT_TXE) || \ 235 ((IT) == USART_IT_TC) || ((IT) == USART_IT_RXNE) || \ 236 ((IT) == USART_IT_IDLE) || ((IT) == USART_IT_LBD) || \ 237 ((IT) == USART_IT_CTS) || ((IT) == USART_IT_ERR)) 238 #define IS_USART_GET_IT(IT) (((IT) == USART_IT_PE) || ((IT) == USART_IT_TXE) || \ 239 ((IT) == USART_IT_TC) || ((IT) == USART_IT_RXNE) || \ 240 ((IT) == USART_IT_IDLE) || ((IT) == USART_IT_LBD) || \ 241 ((IT) == USART_IT_CTS) || ((IT) == USART_IT_ORE) || \ 242 ((IT) == USART_IT_NE) || ((IT) == USART_IT_FE)) 243 #define IS_USART_CLEAR_IT(IT) (((IT) == USART_IT_TC) || ((IT) == USART_IT_RXNE) || \ 244 ((IT) == USART_IT_LBD) || ((IT) == USART_IT_CTS)) 253 #define USART_DMAReq_Tx ((uint16_t)0x0080) 254 #define USART_DMAReq_Rx ((uint16_t)0x0040) 255 #define IS_USART_DMAREQ(DMAREQ) ((((DMAREQ) & (uint16_t)0xFF3F) == 0x00) && ((DMAREQ) != (uint16_t)0x00)) 264 #define USART_WakeUp_IdleLine ((uint16_t)0x0000) 265 #define USART_WakeUp_AddressMark ((uint16_t)0x0800) 266 #define IS_USART_WAKEUP(WAKEUP) (((WAKEUP) == USART_WakeUp_IdleLine) || \ 267 ((WAKEUP) == USART_WakeUp_AddressMark)) 276 #define USART_LINBreakDetectLength_10b ((uint16_t)0x0000) 277 #define USART_LINBreakDetectLength_11b ((uint16_t)0x0020) 278 #define IS_USART_LIN_BREAK_DETECT_LENGTH(LENGTH) \ 279 (((LENGTH) == USART_LINBreakDetectLength_10b) || \ 280 ((LENGTH) == USART_LINBreakDetectLength_11b)) 289 #define USART_IrDAMode_LowPower ((uint16_t)0x0004) 290 #define USART_IrDAMode_Normal ((uint16_t)0x0000) 291 #define IS_USART_IRDA_MODE(MODE) (((MODE) == USART_IrDAMode_LowPower) || \ 292 ((MODE) == USART_IrDAMode_Normal)) 301 #define USART_FLAG_CTS ((uint16_t)0x0200) 302 #define USART_FLAG_LBD ((uint16_t)0x0100) 303 #define USART_FLAG_TXE ((uint16_t)0x0080) 304 #define USART_FLAG_TC ((uint16_t)0x0040) 305 #define USART_FLAG_RXNE ((uint16_t)0x0020) 306 #define USART_FLAG_IDLE ((uint16_t)0x0010) 307 #define USART_FLAG_ORE ((uint16_t)0x0008) 308 #define USART_FLAG_NE ((uint16_t)0x0004) 309 #define USART_FLAG_FE ((uint16_t)0x0002) 310 #define USART_FLAG_PE ((uint16_t)0x0001) 311 #define IS_USART_FLAG(FLAG) (((FLAG) == USART_FLAG_PE) || ((FLAG) == USART_FLAG_TXE) || \ 312 ((FLAG) == USART_FLAG_TC) || ((FLAG) == USART_FLAG_RXNE) || \ 313 ((FLAG) == USART_FLAG_IDLE) || ((FLAG) == USART_FLAG_LBD) || \ 314 ((FLAG) == USART_FLAG_CTS) || ((FLAG) == USART_FLAG_ORE) || \ 315 ((FLAG) == USART_FLAG_NE) || ((FLAG) == USART_FLAG_FE)) 317 #define IS_USART_CLEAR_FLAG(FLAG) ((((FLAG) & (uint16_t)0xFC9F) == 0x00) && ((FLAG) != (uint16_t)0x00)) 318 #define IS_USART_PERIPH_FLAG(PERIPH, USART_FLAG) ((((*(uint32_t*)&(PERIPH)) != UART4_BASE) &&\ 319 ((*(uint32_t*)&(PERIPH)) != UART5_BASE)) \ 320 || ((USART_FLAG) != USART_FLAG_CTS)) 321 #define IS_USART_BAUDRATE(BAUDRATE) (((BAUDRATE) > 0) && ((BAUDRATE) < 0x0044AA21)) 322 #define IS_USART_ADDRESS(ADDRESS) ((ADDRESS) <= 0xF) 323 #define IS_USART_DATA(DATA) ((DATA) <= 0x1FF) void USART_Init(USART_TypeDef *USARTx, USART_InitTypeDef *USART_InitStruct)
Initializes the USARTx peripheral according to the specified parameters in the USART_InitStruct.
Definition: mg32f157_usart.c:137
void USART_SmartCardNACKCmd(USART_TypeDef *USARTx, FunctionalState NewState)
Enables or disables NACK transmission.
Definition: mg32f157_usart.c:664
void USART_ITConfig(USART_TypeDef *USARTx, uint16_t USART_IT, FunctionalState NewState)
Enables or disables the specified USART interrupts.
Definition: mg32f157_usart.c:349
USART Clock Init Structure definition.
Definition: mg32f157_usart.h:65
void USART_OverSampling8Cmd(USART_TypeDef *USARTx, FunctionalState NewState)
Enables or disables the USART's 8x oversampling mode.
Definition: mg32f157_usart.c:720
uint16_t USART_Clock
Definition: mg32f157_usart.h:67
void USART_LINBreakDetectLengthConfig(USART_TypeDef *USARTx, uint16_t USART_LINBreakDetectLength)
Sets the USART LIN Break detection length.
Definition: mg32f157_usart.c:506
void USART_SetAddress(USART_TypeDef *USARTx, uint8_t USART_Address)
Sets the address of the USART node.
Definition: mg32f157_usart.c:435
void USART_DMACmd(USART_TypeDef *USARTx, uint16_t USART_DMAReq, FunctionalState NewState)
Enables or disables the USART's DMA interface.
Definition: mg32f157_usart.c:407
void USART_ReceiverWakeUpCmd(USART_TypeDef *USARTx, FunctionalState NewState)
Determines if the USART is in mute mode or not.
Definition: mg32f157_usart.c:477
uint16_t USART_WordLength
Definition: mg32f157_usart.h:41
FlagStatus USART_GetFlagStatus(USART_TypeDef *USARTx, uint16_t USART_FLAG)
Checks whether the specified USART flag is set or not.
Definition: mg32f157_usart.c:832
ITStatus USART_GetITStatus(USART_TypeDef *USARTx, uint16_t USART_IT)
Checks whether the specified USART interrupt has occurred or not.
Definition: mg32f157_usart.c:915
void USART_WakeUpConfig(USART_TypeDef *USARTx, uint16_t USART_WakeUp)
Selects the USART WakeUp method.
Definition: mg32f157_usart.c:458
uint16_t USART_HardwareFlowControl
Definition: mg32f157_usart.h:57
uint16_t USART_CPOL
Definition: mg32f157_usart.h:70
uint16_t USART_Parity
Definition: mg32f157_usart.h:47
uint16_t USART_LastBit
Definition: mg32f157_usart.h:76
void USART_ClearFlag(USART_TypeDef *USARTx, uint16_t USART_FLAG)
Clears the USARTx's pending flags.
Definition: mg32f157_usart.c:882
void USART_SmartCardCmd(USART_TypeDef *USARTx, FunctionalState NewState)
Enables or disables the USART's Smart Card mode.
Definition: mg32f157_usart.c:639
void USART_SetGuardTime(USART_TypeDef *USARTx, uint8_t USART_GuardTime)
Sets the specified USART guard time.
Definition: mg32f157_usart.c:600
uint16_t USART_Mode
Definition: mg32f157_usart.h:54
void USART_SendBreak(USART_TypeDef *USARTx)
Transmits break characters.
Definition: mg32f157_usart.c:584
uint32_t USART_BaudRate
Definition: mg32f157_usart.h:36
Definition: mg32f157.h:917
void USART_HalfDuplexCmd(USART_TypeDef *USARTx, FunctionalState NewState)
Enables or disables the USART's Half Duplex communication.
Definition: mg32f157_usart.c:690
uint16_t USART_CPHA
Definition: mg32f157_usart.h:73
uint16_t USART_StopBits
Definition: mg32f157_usart.h:44
void USART_Cmd(USART_TypeDef *USARTx, FunctionalState NewState)
Enables or disables the specified USART peripheral.
Definition: mg32f157_usart.c:312
void USART_SetPrescaler(USART_TypeDef *USARTx, uint8_t USART_Prescaler)
Sets the system clock prescaler.
Definition: mg32f157_usart.c:620
void USART_ClockStructInit(USART_ClockInitTypeDef *USART_ClockInitStruct)
Fills each USART_ClockInitStruct member with its default value.
Definition: mg32f157_usart.c:294
void USART_ClearITPendingBit(USART_TypeDef *USARTx, uint16_t USART_IT)
Clears the USARTx's interrupt pending bits.
Definition: mg32f157_usart.c:989
void USART_OneBitMethodCmd(USART_TypeDef *USARTx, FunctionalState NewState)
Enables or disables the USART's one bit sampling method.
Definition: mg32f157_usart.c:747
USART Init Structure definition.
Definition: mg32f157_usart.h:34
void USART_StructInit(USART_InitTypeDef *USART_InitStruct)
Fills each USART_InitStruct member with its default value.
Definition: mg32f157_usart.c:242
void USART_IrDACmd(USART_TypeDef *USARTx, FunctionalState NewState)
Enables or disables the USART's IrDA interface.
Definition: mg32f157_usart.c:795
void USART_LINCmd(USART_TypeDef *USARTx, FunctionalState NewState)
Enables or disables the USART's LIN mode.
Definition: mg32f157_usart.c:525
void USART_ClockInit(USART_TypeDef *USARTx, USART_ClockInitTypeDef *USART_ClockInitStruct)
Initializes the USARTx peripheral Clock according to the specified parameters in the USART_ClockInitS...
Definition: mg32f157_usart.c:263
void USART_DeInit(USART_TypeDef *USARTx)
Deinitializes the USARTx peripheral registers to their default reset values.
Definition: mg32f157_usart.c:91
uint16_t USART_ReceiveData(USART_TypeDef *USARTx)
Returns the most recent received data by the USARTx peripheral.
Definition: mg32f157_usart.c:568
void USART_SendData(USART_TypeDef *USARTx, uint16_t Data)
Transmits single data through the USARTx peripheral.
Definition: mg32f157_usart.c:551
void USART_IrDAConfig(USART_TypeDef *USARTx, uint16_t USART_IrDAMode)
Configures the USART's IrDA interface.
Definition: mg32f157_usart.c:776