📄 stm8s_uart2.c
字号:
if (UART2_LINBreakDetectionLength != UART2_LINBREAKDETECTIONLENGTH_10BITS)
{
UART2->CR4 |= UART2_CR4_LBDL;
}
else
{
UART2->CR4 &= ((u8)~UART2_CR4_LBDL);
}
}
/**
* @brief Configue the UART2 peripheral.
* @par Full description:
* Configue the UART2 peripheral.
* @param[in] UART2_Mode specifies the LIN mode.
* This parameter can be any of the @ref UART2_LinMode_TypeDef values.
* @param[in] UART2_Autosync specifies the LIN automatic resynchronization mode.
* This parameter can be any of the @ref UART2_LinAutosync_TypeDef values.
* @param[in] UART2_DivUp specifies the LIN divider update method.
* This parameter can be any of the @ref UART2_LinDivUp_TypeDef values.
* @retval void None
* @par Required preconditions:
* None
* @par Called functions:
* None
* @par Example:
* @code
* UART2_LINConfig(UART2_LIN_MODE_MASTER, UART2_LIN_AUTOSYNC_DISABLE,UART2_LIN_DIVUP_LBRR1);
* @endcode
*/
void UART2_LINConfig(UART2_LinMode_TypeDef UART2_Mode, UART2_LinAutosync_TypeDef UART2_Autosync, UART2_LinDivUp_TypeDef UART2_DivUp)
{
assert_param(IS_UART2_SLAVE_OK(UART2_Mode));
assert_param(IS_UART2_AUTOSYNC_OK(UART2_Autosync));
assert_param(IS_UART2_DIVUP_OK(UART2_DivUp));
if (UART2_Mode != UART2_LIN_MODE_MASTER)
{
UART2->CR6 |= UART2_CR6_LSLV;
}
else
{
UART2->CR6 &= ((u8)~UART2_CR6_LSLV);
}
if (UART2_Autosync != UART2_LIN_AUTOSYNC_DISABLE)
{
UART2->CR6 |= UART2_CR6_LASE ;
}
else
{
UART2->CR6 &= ((u8)~ UART2_CR6_LASE );
}
if (UART2_DivUp != UART2_LIN_DIVUP_LBRR1)
{
UART2->CR6 |= UART2_CR6_LDUM;
}
else
{
UART2->CR6 &= ((u8)~ UART2_CR6_LDUM);
}
}
/**
* @brief Enables or disables the UART2 LIN mode.
* @par Full description:
* Enables or disables the UART2抯 LIN mode.
* @param[in] NewState is new state of the UART2 LIN mode.
* This parameter can be:
* - ENABLE
* - DISABLE
* @retval void None
* @par Required preconditions:
* None
* @par Called functions:
* None
* @par Example:
* @code
* UART2_LINCmd(ENABLE)
* @endcode
*/
void UART2_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 */
UART2->CR3 |= UART2_CR3_LINEN;
}
else
{
/* Disable the LIN mode by clearing the LINE bit in the CR2 register */
UART2->CR3 &= ((u8)~UART2_CR3_LINEN);
}
}
/**
* @brief Enables or disables the UART2 Smart Card mode.
* @par Full description:
* Enables or disables the UART2 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 UART2 Smart Card mode.
* @code
* UART2_SmartCardCmd(DISABLE);
* @endcode
*/
void UART2_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 */
UART2->CR5 |= UART2_CR5_SCEN;
}
else
{
/* Disable the SC mode by clearing the SCEN bit in the CR5 register */
UART2->CR5 &= ((u8)(~UART2_CR5_SCEN));
}
}
/**
* @brief Enables or disables NACK transmission.
* @par Full description:
* Enables or disables NACK transmission.
* @par This function is valid only for UART2 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 UART2 NACK transmission.
* @code
* UART2_SmartCardNACKCmd(DISABLE);
* @endcode
*/
void UART2_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 */
UART2->CR5 |= UART2_CR5_NACK;
}
else
{
/* Disable the NACK transmission by clearing the NACK bit in the CR5 register */
UART2->CR5 &= ((u8)~(UART2_CR5_NACK));
}
}
/**
* @brief Selects the UART2 WakeUp method.
* @par Full description:
* Selects the UART2 WakeUp method.
* @param[in] UART2_WakeUp: specifies the UART2 wakeup method.
* This parameter can be any of the @ref UART2_WakeUp_TypeDef values.
* @retval void None
* @par Required preconditions:
* None
* @par Called functions:
* None
* @par Example:
* UART2 WakeUp Idle line .
* @code
* UART2_WakeUpConfig(UART2_WAKEUP_IDLELINE);
* @endcode
*/
void UART2_WakeUpConfig(UART2_WakeUp_TypeDef UART2_WakeUp)
{
assert_param(IS_UART2_WAKEUP_OK(UART2_WakeUp));
UART2->CR1 &= ((u8)~UART2_CR1_WAKE);
UART2->CR1 |= (u8)UART2_WakeUp;
}
/**
* @brief Determines if the UART2 is in mute mode or not.
* @par Full description:
* Determines if the UART2 is in mute mode or not.
* @param[in] NewState: new state of the UART2 mode.
* This parameter can be:
* - ENABLE
* - DISABLE
* @retval void None
* @par Required preconditions:
* None
* @par Called functions:
* None
* @par Example:
* @code
* UART2_ReceiverWakeUpCmd(DISABLE);
* @endcode
*/
void UART2_ReceiverWakeUpCmd(FunctionalState NewState)
{
assert_param(IS_FUNCTIONALSTATE_OK(NewState));
if (NewState != DISABLE)
{
/* Enable the mute mode UART2 by setting the RWU bit in the CR2 register */
UART2->CR2 |= UART2_CR2_RWU;
}
else
{
/* Disable the mute mode UART2 by clearing the RWU bit in the CR1 register */
UART2->CR2 &= ((u8)~UART2_CR2_RWU);
}
}
/**
* @brief Returns the most recent received data by the UART2 peripheral.
* @par Full description:
* Returns the most recent received data by the UART2 peripheral.
* @retval u16 Received Data
* @par Required preconditions:
* UART2_Cmd(ENABLE);
* @par Called functions:
* None
* @par Example:
* @code
* u8 my_data;
* my_data = UART2_ReceiveData8();
* @endcode
*/
u8 UART2_ReceiveData8(void)
{
return ((u8)UART2->DR);
}
/**
* @brief Returns the most recent received data by the UART2 peripheral.
* @par Full description:
* Returns the most recent received data by the UART2 peripheral.
* @retval u16 Received Data
* @par Required preconditions:
* UART2_Cmd(ENABLE);
* @par Called functions:
* None
* @par Example:
* @code
* u16 my_data;
* my_data = UART2_ReceiveData9();
* @endcode
*/
u16 UART2_ReceiveData9(void)
{
return (u16)((((u16)UART2->DR) | ((u16)(((u16)((u16)UART2->CR1 & (u16)UART2_CR1_R8)) << 1))) & ((u16)0x01FF));
}
/**
* @brief Transmits 8 bit data through the UART2 peripheral.
* @par Full description:
* Transmits 8 bit data through the UART2 peripheral.
* @param[in] Data: the data to transmit.
* @retval void None
* @par Required preconditions:
* UART2_Cmd(ENABLE);
* @par Called functions:
* None
* @par Example:
* Send 0x55 using UART2
* @code
* u8 my_data = 0x55;
* UART2_SendData8(my_data);
* @endcode
*/
void UART2_SendData8(u8 Data)
{
/* Transmit Data */
UART2->DR = Data;
}
/**
* @brief Transmits 9 bit data through the UART2 peripheral.
* @par Full description:
* Transmits 9 bit data through the UART2 peripheral.
* @param[in] Data: the data to transmit.
* @retval void None
* @par Required preconditions:
* UART2_Cmd(ENABLE);
* @par Called functions:
* None
* @par Example:
* Send 0x103 using UART2
* @code
* u16 my_data = 0x103;
* UART2_SendData9(my_data);
* @endcode
*/
void UART2_SendData9(u16 Data)
{
UART2->CR1 &= ((u8)~UART2_CR1_T8); /**< Clear the transmit data bit 8 */
UART2->CR1 |= (u8)(((u8)(Data >> 2)) & UART2_CR1_T8); /**< Write the transmit data bit [8] */
UART2->DR = (u8)(Data); /**< Write the transmit data bit [0:7] */
}
/**
* @brief Transmits break characters.
* @par Full description:
* Transmits break characters on the UART2 peripheral.
* @retval void None
* @par Required preconditions:
* None
* @par Called functions:
* None
* @par Example:
* @code
* UART2_SendBreak();
* @endcode
*/
void UART2_SendBreak(void)
{
UART2->CR2 |= UART2_CR2_SBK;
}
/**
* @brief Sets the address of the UART2 node.
* @par Full description:
* Sets the address of the UART2 node.
* @param[in] UART2_Address: Indicates the address of the UART2 node.
* @retval void None
* @par Required preconditions:
* None
* @par Called functions:
* None
* @par Example:
* Set the address of the UART2 node at 0x04
* @code
* u8 my_UART2_Address = 0x04;
* UART2_SetAddress(my_UART2_Address);
* @endcode
*/
void UART2_SetAddress(u8 UART2_Address)
{
/*assert_param for x UART2_Address*/
assert_param(IS_UART2_ADDRESS_OK(UART2_Address));
/* Clear the UART2 address */
UART2->CR4 &= ((u8)~UART2_CR4_ADD);
/* Set the UART2 address node */
UART2->CR4 |= UART2_Address;
}
/**
* @brief Sets the specified UART2 guard time.
* @par Full description:
* Sets the address of the UART2 node.
* @par This function is related to SmartCard mode.
* @param[in] UART2_GuardTime: specifies the guard time.
* @retval void None
* @par Required preconditions:
* SmartCard Mode Enabled
* @par Called functions:
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -