Skip to main content
Hiren Bhuva
Associate III
August 7, 2020
Solved

Receive multiple bytes of data using USART1_IRQHandler ().

  • August 7, 2020
  • 7 replies
  • 3838 views

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

}

}

This topic has been closed for replies.
Best answer by TDK

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.

7 replies

TDK
August 7, 2020

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 III
August 7, 2020

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
August 7, 2020

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""."
Hiren Bhuva
Associate III
August 7, 2020

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.

TDK
TDKBest answer
August 7, 2020

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""."
TDK
August 7, 2020

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""."
Hiren Bhuva
Associate III
August 7, 2020

Ok @TDK​ ,

Will make sure next time to add chip part.

I am using STM32F107.