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.

question about MSP430F5418A UART

Other Parts Discussed in Thread: MSP430F5418A

Hi there,

I'm using MSP430F5418A UART to communicate with PC. The problem I encountered is the program couldn't enter RX ISR, so I couldn't receive data transfered from

PC. Before using UART, I configured relevant registers and enabled RX interrupt. Then I run the program, but I couldn't get any data. Please help me.

The following is part of my program:

UCA1CTL1 |= UCSWRST;                      // **Put state machine in reset**
    UCA1CTL1 |= UCSSEL_1;                     // CLK = ACLK
    UCA1BR0 = 0x03;                                    // 32kHz/9600=3.41 (see User's Guide)
    UCA1BR1 = 0x00;                                   
    UCA1MCTL = UCBRS_3+UCBRF_0;       // Modulation UCBRSx=3, UCBRFx=0
    UCA1CTL1 &= ~UCSWRST;                     // **Initialize USCI state machine**
    UCA1IE |= UCRXIE;                         // Enable USCI_A1 RX interrupt
    __bis_SR_register(GIE);                   // interrupts enabled
    __no_operation();           

UART ISR:

#pragma vector=USCI_A1_VECTOR
__interrupt void USCI_A1_ISR(void)
{
 int i;
  switch(__even_in_range(UCA1IV,4))
  {
  case 0:break;                             // Vector 0 - no interrupt
  case 2:                                         // Vector 2 - RXIFG 
    for(i=10;i>=0;i--)
       {
        rx_buffer[i] = UCA1RXBUF;         
        decode();                           
       }                                    
    break;
  case 4:                                   // Vector 4 - TXIFG
   for(i=0;i<=10;i++)
      {
       UCA1TXBUF = tx_buffer[i];
      }
   break;
  default: break; 
  }
}  

Is there something wrong with my configuration?

Thank you

Best regards

Nick

  • Take a closer look at the ISR.

    The ISR being called, means that the USCI has received one byte, or is ready to pick up one more byte for transfer.

    But your ISR reads the RX register 10 times in a row, stuffing 10 times the same value from UCA1RXBUF (there has no new one being received while you do, the next byte is still creepign throuvh the line) into rx_buffer. There is no automatic waitstate that delays reads from RXBUF until a new byte is there - for the CPU it is just a memory location / variable it reads.
    Same for the TX side, here you stuff all 10 bytes in tx_buffer into UCA1TXBUF whiel it can only hold one.

    You must store your index count in a static variable, and only read/write one value on each ISR call. When the next byte is received (or the last one ha sbeen sent), the ISR is called again. And for TX, if you sent the last byte of the buffer, you must clear the TXIE bit, so the ISR isn't called anymore unless TXIE is enabled again from main.

**Attention** This is a public forum