RS485 DE enable
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
