2025-01-11 10:49 AM - last edited on 2025-01-13 12:46 AM by mƎALLEm
Hi,
I was working with Modbus Protocol with the external device(Aster TDS Meter).
The Modbus External device Settings in 9600baud rate, 8bit,parity none and 1stop bit
My Problem was when i connect the device with UART4 i am able to get the output properly but i need to use UART2 but while using UART2 not able to receive the data properly what i am missing?
UART4 Configuration
static void MX_USART4_UART_Init(void)
{
/* USER CODE BEGIN USART4_Init 0 */
/* USER CODE END USART4_Init 0 */
/* USER CODE BEGIN USART4_Init 1 */
/* USER CODE END USART4_Init 1 */
huart4.Instance = USART4;
huart4.Init.BaudRate = 9600;
huart4.Init.WordLength = UART_WORDLENGTH_8B;
huart4.Init.StopBits = UART_STOPBITS_1;
huart4.Init.Parity = UART_PARITY_NONE;
huart4.Init.Mode = UART_MODE_TX_RX;
huart4.Init.HwFlowCtl = UART_HWCONTROL_NONE;
huart4.Init.OverSampling = UART_OVERSAMPLING_16;
huart4.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE;
huart4.Init.ClockPrescaler = UART_PRESCALER_DIV1;
huart4.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT;
if (HAL_UART_Init(&huart4) != HAL_OK)
{
Error_Handler();
}
/* USER CODE BEGIN USART4_Init 2 */
/* USER CODE END USART4_Init 2 */
}
UART 4 Connected with External device(Aster) with RS485 Module Working Fine....!
UART 2 Configuration:
static void MX_USART2_UART_Init(void)
{
/* USER CODE BEGIN USART2_Init 0 */
/* USER CODE END USART2_Init 0 */
/* USER CODE BEGIN USART2_Init 1 */
/* USER CODE END USART2_Init 1 */
huart2.Instance = USART2;
huart2.Init.BaudRate = 9600;
huart2.Init.WordLength = UART_WORDLENGTH_8B;
huart2.Init.StopBits = UART_STOPBITS_1;
huart2.Init.Parity = UART_PARITY_NONE;
huart2.Init.Mode = UART_MODE_TX_RX;
huart2.Init.HwFlowCtl = UART_HWCONTROL_NONE;
huart2.Init.OverSampling = UART_OVERSAMPLING_16;
huart2.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE;
huart2.Init.ClockPrescaler = UART_PRESCALER_DIV1;
huart2.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT;
if (HAL_UART_Init(&huart2) != HAL_OK)
{
Error_Handler();
}
if (HAL_UARTEx_SetTxFifoThreshold(&huart2, UART_TXFIFO_THRESHOLD_8_8) != HAL_OK)
{
Error_Handler();
}
if (HAL_UARTEx_SetRxFifoThreshold(&huart2, UART_RXFIFO_THRESHOLD_8_8) != HAL_OK)
{
Error_Handler();
}
if (HAL_UARTEx_DisableFifoMode(&huart2) != HAL_OK)
{
Error_Handler();
}
/* USER CODE BEGIN USART2_Init 2 */
/* USER CODE END USART2_Init 2 */
}
But In UART 2 Connected with External Device(Aster)Via RS485 module not working or not able to receive the data
So what makes the difference between UART2 and UART4
Expect the Configuration all other TX buffers RX buffers are same tested in both UART4 working fine but UART 2 not working!
Please explain where i am doing wrong!
Advance Thanks!
A.Mathew
2025-05-15 3:32 AM - edited 2025-05-15 3:34 AM
Hi @MathewANTHONY ,
You are mentionning STM32G070RBT6 in your description, are you using the NUCLEO-G070RB board ?
If yes, please note that USART2 TX and RX pins, might be connected to ST-LINK, for VCP communication and not to morpho connectors. You should be able to change this by updating Solder bridges configuration.
Please refer to User manual of STM32 Nucleo-64 boards (MB1360) UM2324, and especially at those paragraphs :
Hope this helps.