cancel
Showing results for 
Search instead for 
Did you mean: 

Receive multiple bytes of data using USART1_IRQHandler ().

Hiren Bhuva
Associate II

Hello Community,

I am new to ST MCUs.

I want to receive multiple bytes of dat over UART. The size of the data can vary. So I want to use USART1_IRQHandler() when data is received by MCU over UART.

I am able to get the interrupt correctly, But I can get only 1 Byte data from the interrupt handler. and the interrupt handler is being called 1 time only.

What can be the issue?

Below is my ISR function.

void USART1_IRQHandler(void)                                             //Serial port 1 interrupt service program

{

   u8 Res;

   if(USART_GetITStatus(USART1, USART_IT_RXNE) != RESET)

   {

      Res =USART_ReceiveData(USART1);                                       //Read the received data

}

}

1 ACCEPTED SOLUTION

Accepted Solutions

You'll get an interrupt for each byte.

If you're debugging and the program is paused, you may miss some bytes. Perhaps this is the actual issue.

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

View solution in original post

7 REPLIES 7
TDK
Guru

Should work. Sure you're not getting a framing error or something else on the line?

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

Thanks @TDK​ for the response,

I am not getting the any errors.

My issue is that I can only get one byte(first byte of my data) using USART_ReceiveData().

How can I get other bytes received on UART.

Should I get the 4 Interrupt for 4 bytes of data?

Or there is another way to get the remaining data after USART1_IRQHandler() being called.

TDK
Guru

You only get 1 byte per interrupt. If you send 4 bytes, the interrupt will trigger 4 times. You need to ensure your program is quick enough to respond to these.

If you feel a post has answered your question, please click "Accept as Solution".
TDK
Guru

Next time, add your chip part number to your post. Since you're using SPL, I'm assuming it's STM32F4 or earlier.

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

Thanks @TDK​ ,

I will try to make the ISR as small as possible.

One more question, Should I get 4 interrupt while debugging using ST link also? Or there it will be only one.

Ok @TDK​ ,

Will make sure next time to add chip part.

I am using STM32F107.

You'll get an interrupt for each byte.

If you're debugging and the program is paused, you may miss some bytes. Perhaps this is the actual issue.

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