Baudrate issue with STM32F0 with Modbus implementation.
Problem
i have configure Modbus over rs-485
While Receiving modbus data on rs485 on the baudrate it configured on, which is 115200 , it works fine.
but when i query modbus register to get value on different baudrate like 9600 , my board getting restart.
Hardware is working fine and having all pull-ups and termination registers.
there is observation while problem occurs,
USART_ISR_PE | USART_ISR_FE | USART_ISR_ORE | USART_ISR_NE
over run error and frame error bits are set while problem occurs
Modbus Configuration:
void MX_USART1_UART_Init(void)
{
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.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_DMADISABLEONERROR_INIT;
huart1.AdvancedInit.DMADisableonRxError = UART_ADVFEATURE_DMA_DISABLEONRXERROR;
if (HAL_RS485Ex_Init(&huart1, UART_DE_POLARITY_HIGH, 10, 10) != HAL_OK)
{
_Error_Handler(__FILE__, __LINE__);
}
}
there are few changes/logics i have added in HAL layer, which are mentioned below.
1) while receiving data, i consider the buffer to be processed further when there is more than 3.5 character delay between the characters.
- to do so, i have configured a timer and timeout value set as below,
/**
* @brief Enables the MODBUS t3,5 char timer.
* @param huart pointer to a UART_HandleTypeDef structure that contains
* the configuration information for the specified UART module.
*/
void UART_EnableT35(UART_HandleTypeDef* huart)
{
assert_param(huart);
// manually initialize registers for t3.5 timing
huart->Instance->CR2 |= USART_CR2_RTOEN; // Receiver timeout enable
huart->Instance->CR1 |= USART_CR1_RTOIE; // Receiver timeout interrupt enable
huart->Instance->RTOR |= 38; // Receiver timeout value (11 * 3.5)
}
whenever timer time's out it raises an interrupt and on that interrupt i'm processing my buffer.
Note:
above logic is not originally comes with a standered library.
