📄 stm8s_uart1.c
字号:
* @retval void None
* @par Required preconditions:
* None
* @par Called functions:
* None
* @par Example:
* @code
* UART1_IrDACmd(ENABLE)
* @endcode
*/
void UART1_IrDACmd(FunctionalState NewState)
{
/* Check parameters */
assert_param(IS_FUNCTIONALSTATE_OK(NewState));
if (NewState != DISABLE)
{
/* Enable the IrDA mode by setting the IREN bit in the CR3 register */
UART1->CR5 |= UART1_CR5_IREN;
}
else
{
/* Disable the IrDA mode by clearing the IREN bit in the CR3 register */
UART1->CR5 &= ((u8)~UART1_CR5_IREN);
}
}
/**
* @brief Sets the UART1 LIN Break detection length.
* @par Full description:
* Sets the UART1 LIN Break detection length.
* @param[in] UART1_LINBreakDetectionLength specifies the LIN break detection length.
* This parameter can be any of the @ref UART1_LINBreakDetectionLength_TypeDef values.
* @retval void None
* @par Required preconditions:
* None
* @par Called functions:
* None
* @par Example:
* @code
* UART1_LINBreakDetectionConfig(UART1_LINBREAKDETECTIONLENGTH_11BITS)
* @endcode
*/
void UART1_LINBreakDetectionConfig(UART1_LINBreakDetectionLength_TypeDef UART1_LINBreakDetectionLength)
{
assert_param(IS_UART1_LINBREAKDETECTIONLENGTH_OK(UART1_LINBreakDetectionLength));
if (UART1_LINBreakDetectionLength != UART1_LINBREAKDETECTIONLENGTH_10BITS)
{
UART1->CR4 |= UART1_CR4_LBDL;
}
else
{
UART1->CR4 &= ((u8)~UART1_CR4_LBDL);
}
}
/**
* @brief Enables or disables the UART1抯 LIN mode.
* @par Full description:
* Enables or disables the UART1抯 LIN mode.
* @param[in] NewState is new state of the UART1 LIN mode.
* This parameter can be: ENABLE or DISABLE.
* @retval void None
* @par Required preconditions:
* None
* @par Called functions:
* None
* @par Example:
* @code
* UART1_LINCmd(ENABLE)
* @endcode
*/
void UART1_LINCmd(FunctionalState NewState)
{
assert_param(IS_FUNCTIONALSTATE_OK(NewState));
if (NewState != DISABLE)
{
/* Enable the LIN mode by setting the LINE bit in the CR2 register */
UART1->CR3 |= UART1_CR3_LINEN;
}
else
{
/* Disable the LIN mode by clearing the LINE bit in the CR2 register */
UART1->CR3 &= ((u8)~UART1_CR3_LINEN);
}
}
/**
* @brief Enables or disables the UART1 Smart Card mode.
* @par Full description:
* Enables or disables the UART1 Smart Card mode.
* @par This function is related to SmartCard mode.
* @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 UART1 Smart Card mode.
* @code
* UART1_SmartCardCmd(DISABLE);
* @endcode
*/
void UART1_SmartCardCmd(FunctionalState NewState)
{
assert_param(IS_FUNCTIONALSTATE_OK(NewState));
if (NewState != DISABLE)
{
/* Enable the SC mode by setting the SCEN bit in the CR5 register */
UART1->CR5 |= UART1_CR5_SCEN;
}
else
{
/* Disable the SC mode by clearing the SCEN bit in the CR5 register */
UART1->CR5 &= ((u8)(~UART1_CR5_SCEN));
}
}
/**
* @brief Enables or disables NACK transmission.
* @par Full description:
* Enables or disables NACK transmission.
* @par This function is valid only for UART1 because is related to SmartCard mode.
* @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 UART1 NACK transmission.
* @code
* UART1_SmartCardNACKCmd(DISABLE);
* @endcode
*/
void UART1_SmartCardNACKCmd(FunctionalState NewState)
{
assert_param(IS_FUNCTIONALSTATE_OK(NewState));
if (NewState != DISABLE)
{
/* Enable the NACK transmission by setting the NACK bit in the CR5 register */
UART1->CR5 |= UART1_CR5_NACK;
}
else
{
/* Disable the NACK transmission by clearing the NACK bit in the CR5 register */
UART1->CR5 &= ((u8)~(UART1_CR5_NACK));
}
}
/**
* @brief Selects the UART1 WakeUp method.
* @par Full description:
* Selects the UART1 WakeUp method.
* @param[in] UART1_WakeUp: specifies the UART1 wakeup method.
* This parameter can be any of the @ref UART1_WakeUp_TypeDef values.
* @retval void None
* @par Required preconditions:
* None
* @par Called functions:
* None
* @par Example:
* UART1 WakeUp Idle line .
* @code
* UART1_WakeUpConfig(UART1_WakeUp_IdleLine);
* @endcode
*/
void UART1_WakeUpConfig(UART1_WakeUp_TypeDef UART1_WakeUp)
{
assert_param(IS_UART1_WAKEUP_OK(UART1_WakeUp));
UART1->CR1 &= ((u8)~UART1_CR1_WAKE);
UART1->CR1 |= (u8)UART1_WakeUp;
}
/**
* @brief Determines if the UART1 is in mute mode or not.
* @par Full description:
* Determines if the UART1 is in mute mode or not.
* @param[in] NewState: new state of the UART1 mode.
* This parameter can be: ENABLE or DISABLE.
* @retval void None
* @par Required preconditions:
* None
* @par Called functions:
* None
* @par Example:
* @code
* UART1_ReceiverWakeUpCmd(DISABLE);
* @endcode
*/
void UART1_ReceiverWakeUpCmd(FunctionalState NewState)
{
assert_param(IS_FUNCTIONALSTATE_OK(NewState));
if (NewState != DISABLE)
{
/* Enable the mute mode UART1 by setting the RWU bit in the CR2 register */
UART1->CR2 |= UART1_CR2_RWU;
}
else
{
/* Disable the mute mode UART1 by clearing the RWU bit in the CR1 register */
UART1->CR2 &= ((u8)~UART1_CR2_RWU);
}
}
/**
* @brief Returns the most recent received data by the UART1 peripheral.
* @par Full description:
* Returns the most recent received data by the UART1 peripheral.
* @retval u16 Received Data
* @par Required preconditions:
* UART1_Cmd(ENABLE);
* @par Called functions:
* None
* @par Example:
* @code
* u8 my_data;
* my_data = UART1_ReceiveData8();
* @endcode
*/
u8 UART1_ReceiveData8(void)
{
return ((u8)UART1->DR);
}
/**
* @brief Returns the most recent received data by the UART1 peripheral.
* @par Full description:
* Returns the most recent received data by the UART1 peripheral.
* @retval u16 Received Data
* @par Required preconditions:
* UART1_Cmd(ENABLE);
* @par Called functions:
* None
* @par Example:
* @code
* u16 my_data;
* my_data = UART1_ReceiveData9();
* @endcode
*/
u16 UART1_ReceiveData9(void)
{
return (u16)( (((u16) UART1->DR) | ((u16)(((u16)( (u16)UART1->CR1 & (u16)UART1_CR1_R8)) << 1))) & ((u16)0x01FF));
}
/**
* @brief Transmits 8 bit data through the UART1 peripheral.
* @par Full description:
* Transmits 8 bit data through the UART1 peripheral.
* @param[in] Data: the data to transmit.
* @retval void None
* @par Required preconditions:
* UART1_Cmd(ENABLE);
* @par Called functions:
* None
* @par Example:
* Send 0x55 using UART1
* @code
* u8 my_data = 0x55;
* UART1_SendData8(my_data);
* @endcode
*/
void UART1_SendData8(u8 Data)
{
/* Transmit Data */
UART1->DR = Data;
}
/**
* @brief Transmits 9 bit data through the UART1 peripheral.
* @par Full description:
* Transmits 9 bit data through the UART1 peripheral.
* @param[in] Data: the data to transmit.
* @retval void None
* @par Required preconditions:
* UART1_Cmd(ENABLE);
* @par Called functions:
* None
* @par Example:
* Send 0x103 using UART1
* @code
* u16 my_data = 0x103;
* UART1_SendData9(my_data);
* @endcode
*/
void UART1_SendData9(u16 Data)
{
/**< Clear the transmit data bit 8 [8] */
UART1->CR1 &= ((u8)~UART1_CR1_T8);
/**< Write the transmit data bit [8] */
UART1->CR1 |= (u8)(((u8)(Data >> 2)) & UART1_CR1_T8);
/**< Write the transmit data bit [0:7] */
UART1->DR = (u8)(Data);
}
/**
* @brief Transmits break characters.
* @par Full description:
* Transmits break characters on the UART1 peripheral.
* @retval void None
* @par Required preconditions:
* None
* @par Called functions:
* None
* @par Example:
* @code
* UART1_SendBreak();
* @endcode
*/
void UART1_SendBreak(void)
{
UART1->CR2 |= UART1_CR2_SBK;
}
/**
* @brief Sets the address of the UART1 node.
* @par Full description:
* Sets the address of the UART1 node.
* @param[in] UART1_Address: Indicates the address of the UART1 node.
* @retval void None
* @par Required preconditions:
* None
* @par Called functions:
* None
* @par Example:
* Set the address of the UART1 node at 0x04
* @code
* u8 my_UART1_Address = 0x04;
* UART1_SetAddress(my_UART1_Address);
* @endcode
*/
void UART1_SetAddress(u8 UART1_Address)
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -