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.

MSP430F2274 UART RX Problem

Other Parts Discussed in Thread: MSPWARE

Hi,

Do we have any sample codes for MSP430 controller in which UART RX  polling based instead of ISR??i have installed mspware but unable to get any UART polling based sample code..

  • Hi Vidushi!

    If you want to poll for a received character, you simply have to poll for the RX interrupt flag:

    uint8_t received_symbol;
    ...
    
    if( IFG2 & UCA0RXIFG )
    {
      received_symbol = UCA0RXBUF; // Copy received symbol - reading RX buffer clears IFG
    }
    
    ...

    Dennis

  • Hi

    Thanks for your early response..

    What we have to mention in UART_init?

    I have mentioned

    P3SEL = RXD + TXD;

    UCA0CTL1 |= UCSSEL_2; // SMCLK
    UCA0BR0 =104; // 1MHz 9600
    UCA0BR1 = 0; // 1MHz 9600
    UCA0MCTL = UCBRS0; // Modulation UCBRSx = 1
    UCA0CTL1 &= ~UCSWRST; // Initialize USCI state machine
  • Yes, if you also have

    BCSCTL1   = CALBC1_1MHZ;    // Set range
    DCOCTL    = CALDCO_1MHZ;    // Set DCO step and modulation

    at the beginning of your code, then everything looks fine. And disable or feed the watchdog, of course.

    Dennis

  • Hi Dennis,


    unable to get anything in UCA0RXBUF.
  • Please show your complete code.
  • Hi Dennis,


    This is demo code i made please have a look to this..


    void uart_putc(unsigned char c)
    {
    while(!(IFG2&UCA0TXIFG)); // USCI_A0 TX buffer ready?
    UCA0TXBUF = c; // TX
    //while(!(UCA0STAT&UCBUSY));
    }

    void uart_puts(const char *str)
    {
    while(*str)
    {
    uart_putc(*str++);
    }
    }

    unsigned char uart_getc()
    {
    unsigned char received_symbol;
    while(IFG2&UCA0RXIFG)
    {
    received_symbol = UCA0RXBUF; // Copy received symbol - reading RX buffer clears IFG
    }

    return received_symbol;
    }
    int main(void)
    {
    WDTCTL = WDTPW + WDTHOLD;
    P1DIR = 0xFF; // All P1.x outputs
    P1OUT = 0; // All P1.x reset
    P2DIR = 0xFF; // All P2.x outputs
    P2OUT = 0; // All P2.x reset
    P3SEL = 0x30; // P3.4,5 = USCI_A0 TXD/RXD
    P3DIR = 0xFF; // All P3.x outputs
    P3OUT = 0; // All P3.x reset
    P4DIR = 0xFF; // All P4.x outputs
    P4OUT = 0; // All P4.x reset

    // P3SEL = RXD + TXD;
    UCA0CTL1 |= UCSSEL_2; // SMCLK
    UCA0BR0 =104; // 1MHz 9600
    UCA0BR1 = 0; // 1MHz 9600
    UCA0MCTL = UCBRS0; // Modulation UCBRSx = 1
    UCA0CTL1 &= ~UCSWRST; // Initialize USCI state machine
    __bis_SR_register(LPM3_bits + GIE); // Enter LPM3, interrupts enabled

    while(1)
    {
    while(1)
    {
    uart_putc(0x55);
    uart_getc();
    }
    }
    }
  • One thing I noticed at first sight:

    while( IFG2&UCA0RXIFG )
    {
      received_symbol = UCA0RXBUF; // Copy received symbol - reading RX buffer clears IFG
    }

    If you want to wait until something is inside the buffer, you have to write:

    while( !(IFG2 & UCA0RXIFG) ); // Wait until a symbol was received
    received_symbol = UCA0RXBUF;  // Copy received symbol - reading RX buffer clears IFG

    I don't know if this is what you wanted to do?

    Dennis

  • yes Wait until a symbol was received tried this also..
  • Dennis,

    In uart_getc just waiting for symbol to be received at this line while( !(IFG2 & UCA0RXIFG) );

    Thanks for early response

**Attention** This is a public forum