2018-12-06 11:16 PM
This is my usart handler
Also I clear the 1st received frame before receiving the 2nd modbus frame.
void HAL_UART_IRQHandler1(UART_HandleTypeDef *huart)
{
__HAL_UART_CLEAR_PEFLAG(huart);
__HAL_UART_ENABLE_IT(huart, UART_IT_ERR);
__HAL_UART_ENABLE_IT(huart,UART_IT_LBD);
__HAL_UART_ENABLE_IT(huart, UART_IT_PE);
__HAL_UART_ENABLE_IT(huart, UART_IT_RXNE);
__HAL_UART_CLEAR_OREFLAG(huart);
// check if the USART1 receive interrupt flag was set
if( __HAL_UART_GET_IT_SOURCE(huart, UART_IT_RXNE) )
{
t = (uint8_t)(huart->Instance->DR );
if (t != '\n')
{
// Concat char to buffer
if (k < 13 -1)
{
received_string[k] = t;
k++;
}
else
{
received_string[k] = t;
k = 0;
}
}
}
__HAL_UART_CLEAR_PEFLAG(huart);
__HAL_UART_DISABLE_IT(huart, UART_IT_PE);
__HAL_UART_DISABLE_IT(huart, UART_IT_ERR);
__HAL_UART_DISABLE_IT(huart,UART_IT_LBD);
HAL_NVIC_ClearPendingIRQ(USART3_IRQn);
}
2018-12-12 02:14 AM
> The problem was modbus slave sends me incomplete frame at times (last byte was missing in the frame).
> So now before receiving a new frame, every time I am resetting the count 'k'. I Also inserted a delay between receiving frames from 2 modbus slaves.
A proper and robust device must be able to handle corrupted frame.
With Modbus RTU, the spec. defines an inter-frame delay where the bus is idle.
If this period is up (including a grace tolerance of some percent), process the frame, or discard it if invalid.
2018-12-12 02:33 AM
Okay. ..