Skip to main content
Hiren Bhuva
Associate III
Aug 7, 2020 8:10 AM UTC
Solved

Receive multiple bytes of data using USART1_IRQHandler ().

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.
TDK
TDKBest answer
Aug 7, 2020 2:38 PM UTC

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""."

7 replies

TDK
Aug 7, 2020 1:51 PM UTC

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
Aug 7, 2020 1:56 PM UTC

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
Aug 7, 2020 2:11 PM UTC

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
Aug 7, 2020 2:13 PM UTC

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
Aug 7, 2020 2:38 PM UTC

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
Aug 7, 2020 2:12 PM UTC

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
Aug 7, 2020 2:15 PM UTC

Ok @TDK​ ,

Will make sure next time to add chip part.

I am using STM32F107.