Skip to main content
Graduate II
June 4, 2025
Solved

RS485 DE enable

  • June 4, 2025
  • 2 replies
  • 936 views

Hi,
I am implementing RS-485 communication on the STM32G491. Based on available references, I’m currently using a custom GPIO pin for the DE (Driver Enable) signal, since the default USART1_DE pin is already allocated for another function. In the RS-485 initialization API, there are three parameters: DE polarity, assertion time, and de-assertion time. Do these parameters have any effect when a regular GPIO is used instead of the hardware-controlled DE pin?
I am using the below configuration for init.

huart1.Instance = USART1;
huart1.Init.BaudRate = 115200;
huart1.Init.WordLength = UART_WORDLENGTH_8B;
huart1.Init.StopBits = UART_STOPBITS_1;
huart1.Init.Parity = UART_PARITY_NONE;
huart1.Init.Mode = UART_MODE_TX_RX;
huart1.Init.HwFlowCtl = UART_HWCONTROL_NONE;
huart1.Init.OverSampling = UART_OVERSAMPLING_16;
huart1.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE;
huart1.Init.ClockPrescaler = UART_PRESCALER_DIV1;
huart1.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_MSBFIRST_INIT;
huart1.AdvancedInit.MSBFirst = UART_ADVFEATURE_MSBFIRST_ENABLE;
if (HAL_UART_Init(&huart1) != HAL_OK)
{
 Error_Handler();
}
if(HAL_RS485Ex_Init(&huart1, UART_DE_POLARITY_HIGH, 0x1E, 0x1E)!= HAL_OK)
{
 Error_Handler();
}

if (HAL_UARTEx_SetTxFifoThreshold(&huart1, UART_TXFIFO_THRESHOLD_1_8) != HAL_OK)
{
 Error_Handler();
}
if (HAL_UARTEx_SetRxFifoThreshold(&huart1, UART_RXFIFO_THRESHOLD_1_8) != HAL_OK)
{
 Error_Handler();
}
if (HAL_UARTEx_DisableFifoMode(&huart1) != HAL_OK)
{
 Error_Handler();
}

 Edited to apply source code formatting - please see How to insert source code for future reference

    This topic has been closed for replies.
    Best answer by waclawek.jan

    > Do these parameters have any effect when a regular GPIO is used instead of the hardware-controlled DE pin?

    No, these govern the UART's built-in RS485 DE feature, which you don't intend to use.

    JW

    2 replies

    ST Employee
    June 5, 2025

    Hello,

    Here is an extract from the G4 series reference manual which should help you (available here) :

    The driver enable feature is enabled by setting bit DEM in the USART_CR3 control register.
    This enables the user to activate the external transceiver control, through the DE (Driver
    Enable) signal. The assertion time is the time between the activation of the DE signal and
    the beginning of the start bit. It is programmed using the DEAT [4:0] bitfields in the
    USART_CR1 control register. The deassertion time is the time between the end of the last
    stop bit, in a transmitted message, and the de-activation of the DE signal. It is programmed
    using the DEDT [4:0] bitfields in the USART_CR1 control register. The polarity of the DE
    signal can be configured using the DEP bit in the USART_CR3 control register.
    In USART, the DEAT and DEDT are expressed in sample time units (1/8 or 1/16 bit time,
    depending on the oversampling rate).

     

    If you are planning on piloting the DE signal with a GPIO:

    Polarity: defines the default state of the signal

    Assertion time: time between the DE signal and the beginning of the UART signal

    Deassertion time: time between end of the last stop bit signal and the beginning of the UART signal

    You must be careful when configuring those time that both are expressed in sample time (in your case 1/16 of a bit time)

    Hope that helps

     

    Mathis 

     

    Super User
    June 6, 2025

    > Do these parameters have any effect when a regular GPIO is used instead of the hardware-controlled DE pin?

    No, these govern the UART's built-in RS485 DE feature, which you don't intend to use.

    JW