cancel
Showing results for 
Search instead for 
Did you mean: 

STM32L151:HAL_UART_RxCpltCallback called only one time

packmers
Associate II

Hi

I want to use a program i made before with the new IDE 1.8. It should reveive som data with the UART2 until EOL is received.

It works on time and after it throws an interrupt (loops in the void USART2_IRQHandler(void)) but doesn't call the HAL_UART_RxCpltCallback anymore.

I think I tried everything, here some parts of the code:

int main(void)
{
...
HAL_UART_Receive_IT(&huart2, (uint8_t *)Rx_data, 1);	//activate UART receive interrupt every time
    HAL_NVIC_SetPriority(USART2_IRQn, 3, 0);
    HAL_NVIC_EnableIRQ(USART2_IRQn);
    __HAL_UART_ENABLE_IT(&huart2, UART_IT_RXNE);
}
  while (1)
  {
	  	if (Transfer_cplt > 0)// Daten vorhanden
		{
			... do someting with receive data
                }
}
 
static void MX_UART2_UART_Init(void)
{
  huart2.Instance = USART2;
  huart2.Init.BaudRate = 19200;
  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;
  if (HAL_UART_Init(&huart2) != HAL_OK)
  {
    Error_Handler();
  }
 
}
 
void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart) 
{
	int i;
	int Rx_indx=0;
	if (huart->Instance == USART2)	//KS UART
	{
	  __HAL_UART_DISABLE_IT(&huart2, UART_IT_RXNE);
		for(i = 0;i<=sizeof(Rx_data);i++)
		{
			if (Rx_data[0] == 10 || Rx_data[0] == 13)
			{
				break;
			}
 
			RxBuffer[i]= toupper(Rx_data[0]);	//add data to Rx_Buffer
			HAL_UART_Receive(&huart2,(uint8_t*) Rx_data, 1,10);
		}
		Transfer_cplt=1;//transfer complete, data is ready to read
	}
	  __HAL_UART_ENABLE_IT(&huart2, UART_IT_RXNE);
       HAL_UART_Receive_IT(&huart2, (uint8_t *)Rx_data, 1);	
}

Any Idea'?

1 ACCEPTED SOLUTION

Accepted Solutions
packmers
Associate II

Ok - i found the problem.

It was a memory location fail (initalize more then the size)- and this resets the UART Setings (it occures after the first receive) an after this my UART->Init was 0 - and maybe other flags too.

Now i know all the uart bit's :)

Thanks all

Wolfgang

View solution in original post

9 REPLIES 9

> it throws an interrupt (loops in the void USART2_IRQHandler(void)) but doesn't call the

> HAL_UART_RxCpltCallback anymore.

Maybe consequence of UART error, e.g. overflow. Have a look at USART_SR.

JW

TDK
Guru

Code is a bit of a mess. Calling blocking receive in RX receive complete interrupt, then back to IT. Checking past end of buffer. Comparing only first byte.

If you feel a post has answered your question, please click "Accept as Solution".
packmers
Associate II

Hi TDK

it's working fine. I receive the first Byte with interrupt, then i poll the next "single" bytes until a CR or LF arrives.

RxBuffer[i]= toupper(Rx_data[0]); adds the last byte in loop.

This is not the problem ;)

Hi Jan

when it works correct the firts time i get an error- but i think its because of the breakpoint (UART_Error_Callback is called). The Registers look like this:

SR = 0xf8

CR1 = 0x212c

CR3 = 0x1

In the next run no error ocures when the HAL_UART_IRQHandler(UART_HandleTypeDef *huart) is startet. The flags set in this way:

SR is set to 0x20008000

CR1 = 0x8002191

CR3 = 0x800219d

 /* If no error occurs */

 errorflags = (isrflags & (uint32_t)(USART_SR_PE | USART_SR_FE | USART_SR_ORE | USART_SR_NE)); == 0

 if (errorflags == RESET)

 {

   /* UART in mode Receiver -------------------------------------------------*/

   if (((isrflags & USART_SR_RXNE) != RESET) && ((cr1its & USART_CR1_RXNEIE) != RESET)) // this condition is false

   {

     UART_Receive_IT(huart);

     return;

   }

 }

it looks like the SR and CR1 is not set to the USART_SR_RXNE Value, but anyhow the interrupt is thrown!?

The problem is - I have no idea where or when the bits are set

Has anyone an other idea?

Thanks in advance

Wolfgang

I tried it without debugger too, but its the same effect.

It looks like an unknown UART interrupt is thrown all the time.

I tried the Release Version, it hangs in the same way.

Is this part of my Callback ok?

__HAL_UART_ENABLE_IT(&huart2, UART_IT_RXNE);

HAL_UART_Receive_IT(&huart2, (uint8_t *)Rx_data, 1);

Wolfgang

TDK
Guru

> UART_Error_Callback is called

If the error callback is triggered, read the reason for the error in the ErrorCode variable and correct.

RXNE interrupt is enabled within HAL_UART_Receive_IT, no need to duplicate it.

Monitor return status of HAL_* functions to verify they return HAL_OK.

If you feel a post has answered your question, please click "Accept as Solution".
packmers
Associate II

Hi TDK

the HAL_OK comes with 0 (without breakpoint in the interrupt-Routine)

But my problem is, that the HAL_UART_RxCpltCallback in my Main is only called one time. After this the Receive- Interrupt is reconized, but the callback is never called again.

I watched what was happen after the first receive is complete:

after my:

    HAL_Ret = HAL_UART_Receive_IT(&huart2, (uint8_t *)Rx_data, 1);

it comes to finaly to

HAL_StatusTypeDef UART_Start_Receive_IT(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size)

{

 huart->pRxBuffPtr = pData;

 huart->RxXferSize = Size;

 huart->RxXferCount = Size;

 huart->ErrorCode = HAL_UART_ERROR_NONE;

 huart->RxState = HAL_UART_STATE_BUSY_RX;

 /* Process Unlocked */

 __HAL_UNLOCK(huart);

 /* Enable the UART Parity Error Interrupt */

 __HAL_UART_ENABLE_IT(huart, UART_IT_PE);

 /* Enable the UART Error Interrupt: (Frame error, noise error, overrun error) */

 __HAL_UART_ENABLE_IT(huart, UART_IT_ERR);

 /* Enable the UART Data Register not empty Interrupt */

 __HAL_UART_ENABLE_IT(huart, UART_IT_RXNE);

 return HAL_OK;

}

I wonder why is the  huart->RxState = HAL_UART_STATE_BUSY_RX; ????

should it not be HAL_UART_STATE_READY?

Wolfgang

packmers
Associate II

Ok - i found the problem.

It was a memory location fail (initalize more then the size)- and this resets the UART Setings (it occures after the first receive) an after this my UART->Init was 0 - and maybe other flags too.

Now i know all the uart bit's :)

Thanks all

Wolfgang