cancel
Showing results for 
Search instead for 
Did you mean: 

UART RX interrupt routine

pietro2
Associate II
Posted on January 09, 2013 at 10:56

Good morning, i'm using a STM32F0discovery board, i'm developing an application that read and write informations on UART2 port, i'm using only TX and RX pins (PA2 and PA3).

Well, at this time my application ask me what i want to write, than i insert an input string and the mcu sends it on UART correctly.

Now i need to know how i can develop the reception procedure using reception interrupt, because i don't know when the other side sends the informations.

In other words i need to develop a function that when the UART receives something on RX pin than the micro stores it in a string and show me what it receives.

Do you have suggestions or guidelines, please?

Thanks.

#uart-rx-interrupt-routine
2 REPLIES 2
crt2
Associate II
Posted on January 09, 2013 at 13:41

Like you wrote on ''tags'' you should create USART2 interrupt routine

USART_ITConfig(USART2, USART_IT_RXNE, ENABLE); in which you will store data to buffer:

void USART2_IRQHandler(void)

{

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

  {

    /* Read one byte from the receive data register */

    RxBuffer2[RxCounter2++] = USART_ReceiveData(USART2);       

 

    if(RxCounter2 == NbrOfDataToRead1)

    {

      /* Disable the USART2 Receive interrupt */

      USART_ITConfig(USART2, USART_IT_RXNE, DISABLE);

    }

  }

}

Full code can be found in USART/Interrupt program in examples...

Posted on January 09, 2013 at 18:27

You want to implement some sort of ring/fifo or line buffering, accumulating characters in the interrupt, and then parsing your commands or incoming data.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..