cancel
Showing results for 
Search instead for 
Did you mean: 

Over run error when using HAL_UART_Receive_IT

astree2
Associate
Posted on April 19, 2016 at 16:42

Hi,

I want my board communicate with a module in uart interruption.

STD_ERROR_t SendCmdToNemeus(UART_HandleTypeDef *huart, uint8_t *cmd, uint16_t ans_size, uint8_t *answer_buffer){
STD_ASSERT_PTR(huart);
STD_ASSERT_PTR(cmd);
STD_ASSERT_PTR(answer_buffer);
STD_ASSERT_UINT16(ans_size, 0, 150);
HAL_StatusTypeDef halstatus=HAL_OK;
STD_ERROR_t stdstatus=STD_ERROR_OK;
uint32_t notificationReceived = 0;
uint8_t buffer[300]={0};
/* clear the RX buffer befor send cmd*/
while(HAL_UART_Receive(huart,answer_buffer, 1,1000)!= HAL_TIMEOUT) {
;
}
/* Answer reception*/
if(HAL_OK != (halstatus = HAL_UART_Receive_IT(huart, answer_buffer, 25))){
stdstatus=CheckCodeError(halstatus);
}
/* Command transmission*/
if(HAL_OK != (halstatus = HAL_UART_Transmit_IT(huart,(uint8_t*)cmd , strlen((char *)cmd)))){
stdstatus=CheckCodeError(halstatus);
}
/* Wait for notification (end of transmission) to unblock task*/
while (UartReadyRx != SET || UartReadyTx != SET)
{
}
UartReadyRx = RESET ;
UartReadyTx = RESET ;
stdstatus=STD_ERROR_OK;
return stdstatus;
}

First time I send command it s working well but the second one make my code going to thevoid HAL_UART_ErrorCallback(UART_HandleTypeDef *UartHandle); instead of the reception callback :

void HAL_UART_RxCpltCallback(UART_HandleTypeDef *UartHandle)
{
/* Set transmission flag: trasfer complete*/
if(UartHandle->Instance==USART2){
UartReadyRx = SET;
}
}

My board doesn't support Hardware Flow control and the module send lot of **** unexpected charaters.

Is that the issue? Thx #hal_uart_recei #stm32 #over-run
7 REPLIES 7
howard n2wx
Senior
Posted on April 19, 2016 at 21:41

Is it a valid overrun error? You might need to clear the overrun flag yourself. I do this in the uart receive interrupt. Not clearing the overrun flag prevents later character available ints from firing.

From: pwdusid Posted: Tuesday, April 19, 2016 4:42 PM Subject: Over run error when using HAL_UART_Receive_IT

First time I send command it s working well but the second one make my code going to thevoid HAL_UART_ErrorCallback(UART_HandleTypeDef *UartHandle); instead of

the reception callback :

void HAL_UART_RxCpltCallback(UART_HandleTypeDef *UartHandle)
{
/* Set transmission flag: trasfer complete*/
if(UartHandle->Instance==USART2){
UartReadyRx = SET;
}
}

My board doesn't support Hardware Flow control and the module send lot of **** unexpected charaters.

Is that the issue? Thx
howard n2wx
Senior
Posted on April 19, 2016 at 21:42

Is it a valid overrun error? You might need to clear the overrun flag yourself. I do this in the uart receive interrupt. Not clearing the overrun flag prevents later character available ints from firing.

From: pwdusid Posted: Tuesday, April 19, 2016 4:42 PM Subject: Over run error when using HAL_UART_Receive_IT

First time I send command it s working well but the second one make my code going to thevoid HAL_UART_ErrorCallback(UART_HandleTypeDef *UartHandle); instead of

the reception callback :

void HAL_UART_RxCpltCallback(UART_HandleTypeDef *UartHandle)
{
/* Set transmission flag: trasfer complete*/
if(UartHandle->Instance==USART2){
UartReadyRx = SET;
}
}

My board doesn't support Hardware Flow control and the module send lot of **** unexpected charaters.

Is that the issue? Thx
howard n2wx
Senior
Posted on April 19, 2016 at 21:42

Is it a valid overrun error? You might need to clear the overrun flag yourself. I do this in the uart receive interrupt. Not clearing the overrun flag prevents later character available ints from firing.

From: pwdusid Posted: Tuesday, April 19, 2016 4:42 PM Subject: Over run error when using HAL_UART_Receive_IT

First time I send command it s working well but the second one make my code going to thevoid HAL_UART_ErrorCallback(UART_HandleTypeDef *UartHandle); instead of

the reception callback :

void HAL_UART_RxCpltCallback(UART_HandleTypeDef *UartHandle)
{
/* Set transmission flag: trasfer complete*/
if(UartHandle->Instance==USART2){
UartReadyRx = SET;
}
}

My board doesn't support Hardware Flow control and the module send lot of **** unexpected charaters.

Is that the issue? Thx
astree2
Associate
Posted on April 20, 2016 at 10:12

What do you mean by a valid over run flag? If I clear the ORE flag I still lose some characters that could be usefull in my code. I should not have this error I guess.

gvuyk07
Associate II
Posted on April 20, 2016 at 23:27

I don't know the hardware you are using but the HAL code generated for mine disables the rx interrupts after the callback is executed (or an error occurs), so you have to call HAL_UART_Receive_IT again to be able to receive more data. If you don't and you send it more data without clearing the data register, the overrun occurs

Mr._Nileshkumar_Solanki
Associate III
  • a
 
 
 
 
Missing bytes in UART frame through Interrupt.
 

Hello @Mr._Nileshkumar_Solanki 

Would you please start a new question. Provide more details about your issue.

Thanks

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.