微波EDA网,见证研发工程师的成长!
首页 > 研发问答 > 硬件电路设计 > 硬件电路设计讨论 > 请问stm32f0系列是不是内置485的驱动呢

请问stm32f0系列是不是内置485的驱动呢

时间:12-12 整理:3721RD 点击:
看到有些函数,F0的库函数里面的,f1的没有,但是F0的pdf里面也没有看到相关485的说明,那到底是怎么个情况呢, 多谢了
// 声明
/* RS485 mode functions *******************************************************/
void USART_DECmd(USART_TypeDef* USARTx, FunctionalState NewState);
void USART_DEPolarityConfig(USART_TypeDef* USARTx, uint32_t USART_DEPolarity);
void USART_SetDEAssertionTime(USART_TypeDef* USARTx, uint32_t USART_DEAssertionTime);
void USART_SetDEDeassertionTime(USART_TypeDef* USARTx, uint32_t USART_DEDeassertionTime);
// 定义
/** @defgroup USART_Group10 RS485 mode function
*  @brief  RS485 mode function
*
@verbatim  
===============================================================================
                        ##### RS485 mode functions #####
===============================================================================
    [..] This subsection provides a set of functions allowing to manage the USART
         RS485 flow control.
    [..] RS485 flow control (Driver enable feature) handling is possible through
         the following procedure:
         (#) Program the Baud rate, Word length = 8 bits, Stop bits, Parity,
             Transmitter/Receiver modes and hardware flow control values using
             the USART_Init() function.
         (#) Enable the Driver Enable using the USART_DECmd() function.
         (#) Configures the Driver Enable polarity using the USART_DEPolarityConfig()
             function.
         (#) Configures the Driver Enable assertion time using USART_SetDEAssertionTime()
             function and deassertion time using the USART_SetDEDeassertionTime()
             function.    
         (#) Enable the USART using the USART_Cmd() function.
      -@-  
       (+@) The assertion and dessertion times are expressed in sample time units (1/8 or
            1/16 bit time, depending on the oversampling rate).
      
@endverbatim
  * @{
  */
/**
  * @brief  Enables or disables the USART's DE functionality.
  * @param  USARTx: where x can be 1, 2, 3 or 4 to select the USART peripheral.
  * @note   USART3 and USART4 are available only for STM32F072 devices.
  * @note   USART2 is not available for STM32F031 devices.  
  * @param  NewState: new state of the driver enable mode.
  *          This parameter can be: ENABLE or DISABLE.      
  * @retval None
  */
void USART_DECmd(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 DE functionality by setting the DEM bit in the CR3 register */
    USARTx->CR3 |= USART_CR3_DEM;
  }
  else
  {
    /* Disable the DE functionality by clearing the DEM bit in the CR3 register */
    USARTx->CR3 &= (uint32_t)~((uint32_t)USART_CR3_DEM);
  }
}
/**
  * @brief  Configures the USART's DE polarity
  * @param  USARTx: where x can be 1, 2, 3 or 4 to select the USART peripheral.
  * @note   USART3 and USART4 are available only for STM32F072 devices.
  * @note   USART2 is not available for STM32F031 devices.  
  * @param  USART_DEPolarity: specifies the DE polarity.
  *          This parameter can be one of the following values:
  *            @arg USART_DEPolarity_Low
  *            @arg USART_DEPolarity_High
  * @retval None
  */
void USART_DEPolarityConfig(USART_TypeDef* USARTx, uint32_t USART_DEPolarity)
{
  /* Check the parameters */
  assert_param(IS_USART_ALL_PERIPH(USARTx));
  assert_param(IS_USART_DE_POLARITY(USART_DEPolarity));
  USARTx->CR3 &= (uint32_t)~((uint32_t)USART_CR3_DEP);
  USARTx->CR3 |= USART_DEPolarity;
}
/**
  * @brief  Sets the specified RS485 DE assertion time
  * @param  USARTx: where x can be 1, 2, 3 or 4 to select the USART peripheral.
  * @note   USART3 and USART4 are available only for STM32F072 devices.
  * @note   USART2 is not available for STM32F031 devices.  
  * @param  USART_DEAssertionTime: specifies the time between the activation of
  *         the DE signal and the beginning of the start bit
  * @retval None
  */
void USART_SetDEAssertionTime(USART_TypeDef* USARTx, uint32_t USART_DEAssertionTime)
{
  /* Check the parameters */
  assert_param(IS_USART_ALL_PERIPH(USARTx));
  assert_param(IS_USART_DE_ASSERTION_DEASSERTION_TIME(USART_DEAssertionTime));
  /* Clear the DE assertion time */
  USARTx->CR1 &= (uint32_t)~((uint32_t)USART_CR1_DEAT);
  /* Set the new value for the DE assertion time */
  USARTx->CR1 |=((uint32_t)USART_DEAssertionTime << (uint32_t)0x15);
}
/**
  * @brief  Sets the specified RS485 DE deassertion time
  * @param  USARTx: where x can be 1, 2, 3 or 4 to select the USART peripheral.
  * @note   USART3 and USART4 are available only for STM32F072 devices.
  * @note   USART2 is not available for STM32F031 devices.  
  * @param  USART_DeassertionTime: specifies the time between the middle of the last
  *         stop bit in a transmitted message and the de-activation of the DE signal
  * @retval None
  */
void USART_SetDEDeassertionTime(USART_TypeDef* USARTx, uint32_t USART_DEDeassertionTime)
{
  /* Check the parameters */
  assert_param(IS_USART_ALL_PERIPH(USARTx));
  assert_param(IS_USART_DE_ASSERTION_DEASSERTION_TIME(USART_DEDeassertionTime));
  /* Clear the DE deassertion time */
  USARTx->CR1 &= (uint32_t)~((uint32_t)USART_CR1_DEDT);
  /* Set the new value for the DE deassertion time */
  USARTx->CR1 |=((uint32_t)USART_DEDeassertionTime << (uint32_t)0x10);
}

Copyright © 2017-2020 微波EDA网 版权所有

网站地图

Top