📄 st79_usart.c
字号:
USARTx->CR3 &= ((u8)~USART_CR3_LINEN);
}
}
/**
* @brief Returns the most recent received data by the USART peripheral.
* @par Full description:
* Returns the most recent received data by the USART peripheral.
* @param[in] USARTx can be USART or USART to select the peripheral.
* @retval u16 Received Data
* @par Required preconditions:
* USART_Cmd(USART, ENABLE);
* @par Called functions:
* None
* @par Example:
* @code
* u8 my_data;
* my_data = USART_ReceiveData8(USART);
* @endcode
*/
u8 USART_ReceiveData8(USART_TypeDef* USARTx)
{
/*!< Wait until reception completed */
/*! while(!(USARTx->SR&USART_SR_RXNE)); */
return USARTx->DR;
}
/**
* @brief Returns the most recent received data by the USART peripheral.
* @par Full description:
* Returns the most recent received data by the USART peripheral.
* @param[in] USARTx can be USART or USART to select the peripheral.
* @retval u16 Received Data
* @par Required preconditions:
* USART_Cmd(USART, ENABLE);
* @par Called functions:
* None
* @par Example:
* @code
* u16 my_data;
* my_data = USART_ReceiveData9(USART);
* @endcode
*/
u16 USART_ReceiveData9(USART_TypeDef* USARTx)
{
/*!< Wait until reception completed */
/*! while(!(USARTx->SR&USART_SR_RXNE)); */
/*return (u16)( USARTx->DR | (( USARTx->CR1 & USART_CR1_R8) << 1) &0x01FF);*/ /*Modificata x MISRA*/
return (u16)( (((u16) USARTx->DR) | ((u16)(((u16)( (u16)USARTx->CR1 & (u16)USART_CR1_R8)) << 1))) & ((u16)0x01FF));
}
/**
* @brief Determines if the USART is in mute mode or not.
* @par Full description:
* Determines if the USART is in mute mode or not.
* @param[in] USARTx can be USART or USART to select the peripheral.
* @param[in] NewState: new state of the USART mode.
* This parameter can be: ENABLE or DISABLE.
* @retval void None
* @par Required preconditions:
* None
* @par Called functions:
* None
* @par Example:
* @code
* USART_ReceiverWakeUpCmd(USART, DISABLE);
* @endcode
*/
void USART_ReceiverWakeUpCmd(USART_TypeDef* USARTx, FunctionalState NewState)
{
assert(IS_STATE_VALUE_OK(NewState));
if (NewState)
{
/* Enable the mute mode USART by setting the RWU bit in the CR2 register */
USARTx->CR2 |= USART_CR2_RWU;
}
else
{
/* Disable the mute mode USART by clearing the RWU bit in the CR1 register */
USARTx->CR2 &= ((u8)~USART_CR2_RWU);
}
}
/**
* @brief Transmits break characters.
* @par Full description:
* Transmits break characters on the USART peripheral.
* @param[in] USARTx can be USART or USART to select the peripheral.
* @retval void None
* @par Required preconditions:
* None
* @par Called functions:
* None
* @par Example:
* @code
* USART_SendBreak(USART);
* @endcode
*/
void USART_SendBreak(USART_TypeDef* USARTx)
{
USARTx->CR2 |= USART_CR2_SBK;
}
/**
* @brief Transmits 8 bit data through the USART peripheral.
* @par Full description:
* Transmits 8 bit data through the USART peripheral.
* @param[in] USARTx can be USART or USART to select the peripheral.
* @param[in] Data: the data to transmit.
* @retval void None
* @par Required preconditions:
* USART_Cmd(USART, ENABLE);
* @par Called functions:
* None
* @par Example:
* Send 0x55 using USART
* @code
* u8 my_data = 0x55;
* USART_SendData8(USART, my_data);
* @endcode
*/
void USART_SendData8(USART_TypeDef* USARTx, u8 Data)
{
/*! Send data only if Transmitter Enabled and if the USART is Enabled */
/*! if((USARTx->CR2&USART_CR2_TEN)&(~(USARTx->CR1&USART_CR1_USARTDD))) */
/*! Wait until previous transmission completed */
/*! while(!(USARTx->SR&USART_SR_TC)); */
/* Transmit Data */
USARTx->DR = Data;
}
/**
* @brief Transmits 9 bit data through the USART peripheral.
* @par Full description:
* Transmits 9 bit data through the USART peripheral.
* @param[in] USARTx can be USART or USART to select the peripheral.
* @param[in] Data: the data to transmit.
* @retval void None
* @par Required preconditions:
* USART_Cmd(USART, ENABLE);
* @par Called functions:
* None
* @par Example:
* Send 0x103 using USART
* @code
* u16 my_data = 0x103;
* USART_SendData9(USART, my_data);
* @endcode
*/
void USART_SendData9(USART_TypeDef* USARTx, u16 Data)
{
/*! Send data only if Transmitter Enabled and if the USART is Enabled */
/*! if((USART.CR2&USART_CR2_TEN)&(~(USART.CR1&USART_CR1_USARTDD))) */
/*! Wait until previous transmission completed */
/*! while(!(USART.SR&USART_SR_TC)); */
USARTx->CR1 &= ((u8)~USART_CR1_T8); /**< Clear the transmit data bit 8 */
USARTx->CR1 |= (u8)(((u8)(Data >> 2)) & USART_CR1_T8); /**< Write the transmit data bit [8] */
USARTx->DR = (u8)(Data); /**< Write the transmit data bit [0:7] */
}
/**
* @brief Sets the address of the USART node.
* @par Full description:
* Sets the address of the USART node.
* @param[in] USARTx can be USART or USART to select the peripheral.
* @param[in] USART_Address: Indicates the address of the USART node.
* @retval void None
* @par Required preconditions:
* None
* @par Called functions:
* None
* @par Example:
* Set the address of the USART node at 0x04
* @code
* u8 my_USART_Address = 0x04;
* USART_SetAddress(USART, my_USART_Address);
* @endcode
*/
void USART_SetAddress(USART_TypeDef* USARTx, u8 USART_Address)
{
/*Assert for x USART_Address*/
assert(IS_USART_USART_Address_VALUE_OK(USART_Address));
/* Clear the USART address */
USARTx->CR4 &= ((u8)~USART_CR4_ADD);
/* Set the USART address node */
USARTx->CR4 |= USART_Address;
}
/**
* @brief Sets the specified USART guard time.
* @par Full description:
* Sets the address of the USART node.
* @par This function is valid only for USART because is related to SmartCard mode.
* @param[in] USARTx can be only USART (USART has no SmartCard interface).
* @param[in] USART_GuardTime: specifies the guard time.
* @retval void None
* @par Required preconditions:
* SmartCard Mode Enabled
* @par Called functions:
* None
* @par Example:
* The USART guard time counter count up to 0x44 until TC is asserted high.
* @code
* USART_SetGuardTime(USART, 0x44);
* @endcode
*/
void USART_SetGuardTime(USART_TypeDef* USARTx, u8 USART_GuardTime)
{
/* Set the USART guard time */
USARTx->GT = USART_GuardTime;
}
/**
* @brief Sets the system clock prescaler.
* @par Full description:
* Sets the system clock prescaler.
* @par This function is valid only for USART because is related to SmartCard and IrDa mode.
* @param[in] USARTx where x can be only 1 - USART has no IrDa and SmartCard interface.
* @param[in] USART_Prescaler: specifies the prescaler clock.
* This parameter can be one of the following values:
* @par IrDA Low Power Mode
* The clock source is diveded by the value given in the register (8 bits)
* - 0000 0000 Reserved
* - 0000 0001 divides the clock source by 1
* - 0000 0010 divides the clock source by 2
* - ...........................................................
* @par Smart Card Mode
* The clock source is diveded by the value given in the register (5 significant bits) multipied by 2
* - 0 0000 Reserved
* - 0 0001 divides the clock source by 2
* - 0 0010 divides the clock source by 4
* - 0 0011 divides the clock source by 6
* - ...........................................................
* @retval void None
* @par Required preconditions:
* IrDA Low Power mode or smartcard mode enabled
* @par Called functions:
* None
* @par Example:
* Sets USART prescalerfor SmartCard divided by 2.
* @code
* USART_SmartCardCmd(USART, Enable);
* USART_SetPrescaler(USART, 0x01);
* @endcode
*/
void USART_SetPrescaler(USART_TypeDef* USARTx, u8 USART_Prescaler)
{
/* Load the USART prescaler value*/
USARTx->PSCR = USART_Prescaler;
}
/**
* @brief Enables or disables the USART抯 Smart Card mode.
* @par Full description:
* Enables or disables the USART抯 Smart Card mode.
* @par This function is valid only for USART because is related to SmartCard mode.
* @param[in] USARTx can be only USART ( USART has no Smart Card interface).
* @param[in] NewState: new state of the Smart Card mode.
* This parameter can be: ENABLE or DISABLE.
* @retval void None
* @par Required preconditions:
* None
* @par Called functions:
* None
* @par Example:
* Disable USART Smart Card mode.
* @code
* USART_SmartCardCmd(USART, DISABLE);
* @endcode
*/
void USART_SmartCardCmd(USART_TypeDef* USARTx, FunctionalState NewState)
{
assert(IS_STATE_VALUE_OK(NewState));
if (NewState)
{
/* Enable the SC mode by setting the SCEN bit in the CR5 register */
USARTx->CR5 |= USART_CR5_SCEN;
}
else
{
/* Disable the SC mode by clearing the SCEN bit in the CR5 register */
USARTx->CR5 &= ((u8)(~USART_CR5_SCEN));
}
}
/**
* @brief Enables or disables NACK transmission.
* @par Full description:
* Enables or disables NACK transmission.
* @par This function is valid only for USART because is related to SmartCard mode.
* @param[in] USARTx be only USART ( USART has no Smart Card interface).
* @param[in] NewState: new state of the Smart Card mode.
* This parameter can be: ENABLE or DISABLE.
* @retval void None
* @par Required preconditions:
* None
* @par Called functions:
* None
* @par Example:
* Disable USART NACK transmission.
* @code
* USART_SmartCardNACKCmd(USART, DISABLE);
* @endcode
*/
void USART_SmartCardNACKCmd(USART_TypeDef* USARTx, FunctionalState NewState)
{
assert(IS_STATE_VALUE_OK(NewState));
if (NewState)
{
/* Enable the NACK transmission by setting the NACK bit in the CR5 register */
USARTx->CR5 |= USART_CR5_NACK;
}
else
{
/* Disable the NACK transmission by clearing the NACK bit in the CR5 register */
USARTx->CR5 &= ((u8)~(USART_CR5_NACK));
}
}
/**
* @brief Selects the USART WakeUp method.
* @par Full description:
* Selects the USART WakeUp method.
* @param[in] USARTx can be USART or USART to select the peripheral.
* @param[in] USART_WakeUp: specifies the USART wakeup method.
* This parameter can be one of the following values:
* - USART_WakeUp_IdleLine
* - USART_WakeUp_AddressMark
* @retval void None
* @par Required preconditions:
* None
* @par Called functions:
* None
* @par Example:
* USART WakeUp Idle line .
* @code
* USART_WakeUpConfig(USART,USART_WakeUp_IdleLine);
* @endcode
*/
void USART_WakeUpConfig(USART_TypeDef* USARTx, USART_WakeUp_TypeDef USART_WakeUp)
{
assert(IS_USART_WakeUp_VALUE_OK(USART_WakeUp));
USARTx->CR1 &= ((u8)~USART_CR1_WAKE);
USARTx->CR1 |= (u8)USART_WakeUp;
}
/**
* @}
*/
/******************* (C) COPYRIGHT 2007 STMicroelectronics *****END OF FILE****/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -