2020-08-17 04:45 AM
I have an RS485 device, the time for which it turns on is about 3-4 seconds.
In response to a request, it can send an indefinite amount of data, so I run HAL_UART_Receive_IT with a margin of a few bytes.
But I only receive 1 byte and then an OVR error occurs.
Sometimes 0 byte is accepted with an OVR error.
It is VERY rare that HAL accepts all the bytes sent by the device.
It should be noted that the time from the start of the request from the host to the response from the device ranges from 100ms to 3sec.
HAL_GPIO_WritePin(GPIOB, RS485_POWER_EN_Pin, GPIO_PIN_SET);
HAL_Delay(5000);
while(true) {
HAL_UART_Transmit(&huart1, (uint8_t*)txData, 5, 100);
HAL_UART_AbortReceive_IT(&huart1);
HAL_UART_Receive_IT(&huart1, (uint8_t*)rxData, 50);
HAL_Delay(4000);
}
But I noticed that if I delay after turning on not 5000, but 1000 (i.e. the device does not have time to turn on), then everything works well.
Yes, HAL_UART_Receive_IT won't receive anything the first time, but there won't be any problems later
Trying to understand the reasons, I came to the conclusion that this code works
HAL_GPIO_WritePin(GPIOB, RS485_POWER_EN_Pin, GPIO_PIN_SET);
HAL_UART_Receive_IT(&huart1, (uint8_t*)rxData, 50);
HAL_Delay(5000);
while(true) {
HAL_UART_Transmit(&huart1, (uint8_t*)txData, 5, 100);
HAL_UART_AbortReceive_IT(&huart1);
HAL_UART_Receive_IT(&huart1, (uint8_t*)rxData, 50);
HAL_Delay(4000);
}
For some reason, if you run HAL_UART_Receive_IT for the first time so that it does not receive anything, then everything will work
I have a headache from all this, what is the reason for this behavior?
I use STM32F4
2020-08-17 05:54 AM
Include your STM32 chip number.
When does OVR actually get set? Does it happen within the HAL_UART_Transmit routine?
Device is probably sending data while you're not actively reading it.
2020-08-18 03:43 AM
i use STM32F413VGT6
I'm not sure, but I think this happens after receiving the first byte HAL_UART_Receive_IT
Are you saying that having data on the UART RX line while HAL_UART_Receive_IT causes an OVR error?
2020-08-18 10:48 AM
If I remember correctly, ST library has issues with UART overrun handling. Better disable it.
-- pa