cancel
Showing results for 
Search instead for 
Did you mean: 

A question about UART interrupt

Taehyeong Gu
Associate II
Posted on April 18, 2017 at 14:45

In order to configure UART interrupt receive, I put HAL_UART_Receive_IT function in HAL_UART_RxCpltCallback.

but it doesnt work. below is my callback code.

void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart)

{

uint8_t i;

if (huart->Instance == USART2) //current UART

{

if (Rx_indx==0) {for (i=0;i<RXBUFFERBYTE;i++) aRxBuffer[i]=0;} //clear Rx_Buffer before receiving new data

if (Rx_data[0]!=10) //if received data different from ascii 10

{

aRxBuffer[Rx_indx++]=Rx_data[0]; //add data to Rx_Buffer

}

else //if received data = 10

{

Rx_indx=0;

USART2_RX_STANBY=1;//transfer complete, data is ready to read

}

if(HAL_UART_Receive_IT(&huart2,Rx_data, 1) != HAL_OK)//activate UART receive interrupt every time

{

Error_Handler();

}

}

}

The main program has HAL_UART_Receive_IT in beginning part. so i put some character of ASCII and my program reach if(HAL_UART_Receive_IT(&huart2,Rx_data, 1) != HAL_OK) . I checked that HAL_UART_Receive_IT returned HAL_OK then it means preparation of UART receive interrupt. 

but the program doenst take interrupt when I send ASCII to MCU.

I have no clue.. anyone who have had same experience??

help me please.

Thank you.

11 REPLIES 11
Posted on October 07, 2017 at 21:22

And you understand my point?

The post here

https://community.st.com/0D50X00009XkXwwSAF

is like transferring water from one side of the road to the other, where the water doesn't stop flowing, the fill/empty rate is the same and you only have a single 5 gallon bucket. When you move the bucket you lose 5 gallons of water.

You really need two buckets, and manage both of them at the same time. Or use a hose...

My loop above doesn't block, it services both streams if they are ready for a character, and the pumping process completes in a fractional byte time (because it also doesn't block).

If your process/parse time takes 12 character times, then consider a buffering scheme holding 20-24 characters in-flight at a time, to provide sufficient elasticity.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on October 07, 2017 at 22:11

Yes I understand the point even though this example makes it even more clear.

I wanted to point out that it is a bit funny that you replied with the same response.