?? stm32f10x_usart.c
字號:
* Return : None
*******************************************************************************/
void USART_SmartCardCmd(USART_TypeDef* USARTx, FunctionalState NewState)
{
/* Check the parameters */
assert_param(IS_USART_123_PERIPH(USARTx));
assert_param(IS_FUNCTIONAL_STATE(NewState));
if (NewState != DISABLE)
{
/* Enable the SC mode by setting the SCEN bit in the CR3 register */
USARTx->CR3 |= CR3_SCEN_Set;
}
else
{
/* Disable the SC mode by clearing the SCEN bit in the CR3 register */
USARTx->CR3 &= CR3_SCEN_Reset;
}
}
/*******************************************************************************
* Function Name : USART_SmartCardNACKCmd
* Description : Enables or disables NACK transmission.
* Input : - USARTx: where x can be 1, 2 or 3 to select the USART
* peripheral.
* Note: The Smart Card mode is not available for UART4 and UART5.
* - NewState: new state of the NACK transmission.
* This parameter can be: ENABLE or DISABLE.
* Output : None
* Return : None
*******************************************************************************/
void USART_SmartCardNACKCmd(USART_TypeDef* USARTx, FunctionalState NewState)
{
/* Check the parameters */
assert_param(IS_USART_123_PERIPH(USARTx));
assert_param(IS_FUNCTIONAL_STATE(NewState));
if (NewState != DISABLE)
{
/* Enable the NACK transmission by setting the NACK bit in the CR3 register */
USARTx->CR3 |= CR3_NACK_Set;
}
else
{
/* Disable the NACK transmission by clearing the NACK bit in the CR3 register */
USARTx->CR3 &= CR3_NACK_Reset;
}
}
/*******************************************************************************
* Function Name : USART_HalfDuplexCmd
* Description : Enables or disables the USART抯 Half Duplex communication.
* Input : - USARTx: Select the USART or the UART peripheral.
* This parameter can be one of the following values:
* - USART1, USART2, USART3, UART4 or UART5.
* - NewState: new state of the USART Communication.
* This parameter can be: ENABLE or DISABLE.
* Output : None
* Return : None
*******************************************************************************/
void USART_HalfDuplexCmd(USART_TypeDef* USARTx, FunctionalState NewState)
{
/* Check the parameters */
assert_param(IS_USART_ALL_PERIPH(USARTx));
assert_param(IS_FUNCTIONAL_STATE(NewState));
if (NewState != DISABLE)
{
/* Enable the Half-Duplex mode by setting the HDSEL bit in the CR3 register */
USARTx->CR3 |= CR3_HDSEL_Set;
}
else
{
/* Disable the Half-Duplex mode by clearing the HDSEL bit in the CR3 register */
USARTx->CR3 &= CR3_HDSEL_Reset;
}
}
/*******************************************************************************
* Function Name : USART_IrDAConfig
* Description : Configures the USART抯 IrDA interface.
* Input : - USARTx: Select the USART or the UART peripheral.
* This parameter can be one of the following values:
* - USART1, USART2, USART3, UART4 or UART5.
* - USART_IrDAMode: specifies the IrDA mode.
* This parameter can be one of the following values:
* - USART_IrDAMode_LowPower
* - USART_IrDAMode_Normal
* Output : None
* Return : None
*******************************************************************************/
void USART_IrDAConfig(USART_TypeDef* USARTx, u16 USART_IrDAMode)
{
/* Check the parameters */
assert_param(IS_USART_ALL_PERIPH(USARTx));
assert_param(IS_USART_IRDA_MODE(USART_IrDAMode));
USARTx->CR3 &= CR3_IRLP_Mask;
USARTx->CR3 |= USART_IrDAMode;
}
/*******************************************************************************
* Function Name : USART_IrDACmd
* Description : Enables or disables the USART抯 IrDA interface.
* Input : - USARTx: Select the USART or the UART peripheral.
* This parameter can be one of the following values:
* - USART1, USART2, USART3, UART4 or UART5.
* - NewState: new state of the IrDA mode.
* This parameter can be: ENABLE or DISABLE.
* Output : None
* Return : None
*******************************************************************************/
void USART_IrDACmd(USART_TypeDef* USARTx, FunctionalState NewState)
{
/* Check the parameters */
assert_param(IS_USART_ALL_PERIPH(USARTx));
assert_param(IS_FUNCTIONAL_STATE(NewState));
if (NewState != DISABLE)
{
/* Enable the IrDA mode by setting the IREN bit in the CR3 register */
USARTx->CR3 |= CR3_IREN_Set;
}
else
{
/* Disable the IrDA mode by clearing the IREN bit in the CR3 register */
USARTx->CR3 &= CR3_IREN_Reset;
}
}
/*******************************************************************************
* Function Name : USART_GetFlagStatus
* Description : Checks whether the specified USART flag is set or not.
* Input : - USARTx: Select the USART or the UART peripheral.
* This parameter can be one of the following values:
* - USART1, USART2, USART3, UART4 or UART5.
* - USART_FLAG: specifies the flag to check.
* This parameter can be one of the following values:
* - USART_FLAG_CTS: CTS Change flag (not available for
* UART4 and UART5)
* - USART_FLAG_LBD: LIN Break detection flag
* - USART_FLAG_TXE: Transmit data register empty flag
* - USART_FLAG_TC: Transmission Complete flag
* - USART_FLAG_RXNE: Receive data register not empty flag
* - USART_FLAG_IDLE: Idle Line detection flag
* - USART_FLAG_ORE: OverRun Error flag
* - USART_FLAG_NE: Noise Error flag
* - USART_FLAG_FE: Framing Error flag
* - USART_FLAG_PE: Parity Error flag
* Output : None
* Return : The new state of USART_FLAG (SET or RESET).
*******************************************************************************/
FlagStatus USART_GetFlagStatus(USART_TypeDef* USARTx, u16 USART_FLAG)
{
FlagStatus bitstatus = RESET;
/* Check the parameters */
assert_param(IS_USART_ALL_PERIPH(USARTx));
assert_param(IS_USART_FLAG(USART_FLAG));
assert_param(IS_USART_PERIPH_FLAG(USARTx, USART_FLAG)); /* The CTS flag is not available for UART4 and UART5 */
if ((USARTx->SR & USART_FLAG) != (u16)RESET)
{
bitstatus = SET;
}
else
{
bitstatus = RESET;
}
return bitstatus;
}
/*******************************************************************************
* Function Name : USART_ClearFlag
* Description : Clears the USARTx's pending flags.
* Input : - USARTx: Select the USART or the UART peripheral.
* This parameter can be one of the following values:
* - USART1, USART2, USART3, UART4 or UART5.
* - USART_FLAG: specifies the flag to clear.
* This parameter can be any combination of the following values:
* - USART_FLAG_CTS: CTS Change flag (not available for
* UART4 and UART5).
* - USART_FLAG_LBD: LIN Break detection flag.
* - USART_FLAG_TC: Transmission Complete flag.
* - USART_FLAG_RXNE: Receive data register not empty flag.
*
* Notes:
* - PE (Parity error), FE (Framing error), NE (Noise error),
* ORE (OverRun error) and IDLE (Idle line detected)
* flags are cleared by software sequence: a read
* operation to USART_SR register (USART_GetFlagStatus())
* followed by a read operation to USART_DR register
* (USART_ReceiveData()).
* - RXNE flag can be also cleared by a read to the
* USART_DR register (USART_ReceiveData()).
* - TC flag can be also cleared by software sequence: a
* read operation to USART_SR register
* (USART_GetFlagStatus()) followed by a write operation
* to USART_DR register (USART_SendData()).
* - TXE flag is cleared only by a write to the USART_DR
* register (USART_SendData()).
* Output : None
* Return : None
*******************************************************************************/
void USART_ClearFlag(USART_TypeDef* USARTx, u16 USART_FLAG)
{
/* Check the parameters */
assert_param(IS_USART_ALL_PERIPH(USARTx));
assert_param(IS_USART_CLEAR_FLAG(USART_FLAG));
assert_param(IS_USART_PERIPH_FLAG(USARTx, USART_FLAG)); /* The CTS flag is not available for UART4 and UART5 */
USARTx->SR = (u16)~USART_FLAG;
}
/*******************************************************************************
* Function Name : USART_GetITStatus
* Description : Checks whether the specified USART interrupt has occurred or not.
* Input : - USARTx: Select the USART or the UART peripheral.
* This parameter can be one of the following values:
* - USART1, USART2, USART3, UART4 or UART5.
* - USART_IT: specifies the USART interrupt source to check.
* This parameter can be one of the following values:
* - USART_IT_CTS: CTS change interrupt (not available for
* UART4 and UART5)
* - USART_IT_LBD: LIN Break detection interrupt
* - USART_IT_TXE: Tansmit Data Register empty interrupt
* - USART_IT_TC: Transmission complete interrupt
* - USART_IT_RXNE: Receive Data register not empty
* interrupt
* - USART_IT_IDLE: Idle line detection interrupt
* - USART_IT_ORE: OverRun Error interrupt
* - USART_IT_NE: Noise Error interrupt
* - USART_IT_FE: Framing Error interrupt
* - USART_IT_PE: Parity Error interrupt
* Output : None
* Return : The new state of USART_IT (SET or RESET).
*******************************************************************************/
ITStatus USART_GetITStatus(USART_TypeDef* USARTx, u16 USART_IT)
{
u32 bitpos = 0x00, itmask = 0x00, usartreg = 0x00;
ITStatus bitstatus = RESET;
/* Check the parameters */
assert_param(IS_USART_ALL_PERIPH(USARTx));
assert_param(IS_USART_GET_IT(USART_IT));
assert_param(IS_USART_PERIPH_IT(USARTx, USART_IT)); /* The CTS interrupt is not available for UART4 and UART5 */
/* Get the USART register index */
usartreg = (((u8)USART_IT) >> 0x05);
/* Get the interrupt position */
itmask = USART_IT & IT_Mask;
itmask = (u32)0x01 << itmask;
if (usartreg == 0x01) /* The IT is in CR1 register */
{
itmask &= USARTx->CR1;
}
else if (usartreg == 0x02) /* The IT is in CR2 register */
{
itmask &= USARTx->CR2;
}
else /* The IT is in CR3 register */
{
itmask &= USARTx->CR3;
}
bitpos = USART_IT >> 0x08;
bitpos = (u32)0x01 << bitpos;
bitpos &= USARTx->SR;
if ((itmask != (u16)RESET)&&(bitpos != (u16)RESET))
{
bitstatus = SET;
}
else
{
bitstatus = RESET;
}
return bitstatus;
}
/*******************************************************************************
* Function Name : USART_ClearITPendingBit
* Description : Clears the USARTx抯 interrupt pending bits.
* Input : - USARTx: Select the USART or the UART peripheral.
* This parameter can be one of the following values:
* - USART1, USART2, USART3, UART4 or UART5.
* - USART_IT: specifies the interrupt pending bit to clear.
* This parameter can be one of the following values:
* - USART_IT_CTS: CTS change interrupt (not available for
* UART4 and UART5)
* - USART_IT_LBD: LIN Break detection interrupt
* - USART_IT_TC: Transmission complete interrupt.
* - USART_IT_RXNE: Receive Data register not empty interrupt.
*
* Notes:
* - PE (Parity error), FE (Framing error), NE (Noise error),
* ORE (OverRun error) and IDLE (Idle line detected)
* pending bits are cleared by software sequence: a read
* operation to USART_SR register (USART_GetITStatus())
* followed by a read operation to USART_DR register
* (USART_ReceiveData()).
* - RXNE pending bit can be also cleared by a read to the
* USART_DR register (USART_ReceiveData()).
* - TC pending bit can be also cleared by software
* sequence: a read operation to USART_SR register
* (USART_GetITStatus()) followed by a write operation
* to USART_DR register (USART_SendData()).
* - TXE pending bit is cleared only by a write to the
* USART_DR register (USART_SendData()).
* Output : None
* Return : None
*******************************************************************************/
void USART_ClearITPendingBit(USART_TypeDef* USARTx, u16 USART_IT)
{
u16 bitpos = 0x00, itmask = 0x00;
/* Check the parameters */
assert_param(IS_USART_ALL_PERIPH(USARTx));
assert_param(IS_USART_CLEAR_IT(USART_IT));
assert_param(IS_USART_PERIPH_IT(USARTx, USART_IT)); /* The CTS interrupt is not available for UART4 and UART5 */
bitpos = USART_IT >> 0x08;
itmask = (u16)((u16)0x01 << bitpos);
USARTx->SR = (u16)~itmask;
}
/******************* (C) COPYRIGHT 2008 STMicroelectronics *****END OF FILE****/
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -