This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

MSP430 Uart RX problem

Hi,

I have a problem about uart RXIFG flag.

I can read the data with RX ISR,

#pragma vector = USCIAB0RX_VECTOR
__interrupt void USCIAB0RX_ISR (void)
{
  while(!(IFG2 & UCA0RXIFG))
    Data=UCA0RXBUF;
}

But ı want to get data in the main function

while(1){

  while(!(IFG2 & UCA0RXIFG))
    Data=UCA0RXBUF;

}

But it  RXIFG never set like this.

How can ı get data without going interrupt function.

Thank you.

  • YOu can poll the interrupt flag. Don't set any xxxIE bits (as these enable the interrupt).

    Instead, check for the RXIFG bit being set in your main code. If it is, a new byte has arrived in RXBUF. RXIFG is cleared when you read RXBUF or when you manually clear it.

  • Serkan,

    It appears you missing a semicolon in your main loop also. 

    while(!(IFG2 & UCA0RXIFG));  // This will cause the MCU to wait until the flag is set

     data = UCA0RXBUF;

    Otherwise, with it writting above, as long as the interrupt is NOT set, Data would be set = to UCA0RXBUF;

     Also, by using a while loop, your program execution would be halted while its waiting for that condition to occur. Another method would be to use an if statement and test it each iteration through your main loop.

    if(IFG2 & UCA0RXIFG)

     data = UCA0RXBUF;

    Just a suggestion.

     

    -Jason

     

**Attention** This is a public forum