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.

MSP430F1611: UART empty ISR Problem

Part Number: MSP430F1611


Hi everyone,

I am using UART to send lots of data from 1 MSP to another. I am running a 4MHz clock, and the baud rate is 115200. But after the first byte is sent, when I check if the Txbuf is ready, UART gets stuck. i,e,

TXBUF0 = 0x00; // Random data

while (!(IFG1 & UTXIFG0)); // Code gets stuck here

This is because the UTXIFG0 is never set after data transmission OR it is set and immediately cleared by the empty UART0 ISR.

#pragma vector=USART0TX_VECTOR
__interrupt void usart0_tx (void)
{
  __no_operation();
}

MSP430 forces me to provide this ISR even though it contains no instructions. If no ISR is provided, it raises an NMI.

As a workaround,  I use __delay_cycles(1200) instead.  Here anything less than 1200 results in missing bits and these number of cycles remains constant irrespective of the baud rate (I would expect lesser no of cycles for lower baud rates). Since I am sending lots of data, this is becoming a bottleneck for me.

 This is how I configure UART:

  UCTL0 |= CHAR;
  UTCTL0 |= SSEL1; 
 
  UBR00 = 0x22;                             // 115200 Baud rate
  UBR10 = 0x00;
  UMCTL0 = 0xDD;
  
  ME1 |= URXE0 + UTXE0;                     // Enable USART0 TXD/RXD
  P3SEL |= 0x30;
  P3DIR |= BIT4;
  P3DIR &= ~BIT5;
  
  UCTL0 &= ~SWRST;                          // Initialize USART state machine
  IE1 |= UTXIE0 + URXIE0;                   // Enable USART0 RX interrupt

Why does something like this happen and how do i overcome this?

Best Regards,

  • Hi,

    Referring to section 13.2.7 of the MSP430x1xx Family User's Guide under the "USART Transmit Interrupt Operation" section:

    "UTXIFG is automatically reset if the interrupt request is serviced or if a character is written to UxTXBUF"

    So, the interrupt request is being serviced even though you aren't performing anything inside it and UTXIFG is being cleared. I think you've got two options:

    1. Perform the while (!(IFG1 & UTXIFG0)); inside the ISR and refill TXBUF there

    OR

    2. Set a flag inside the ISR to know it's been serviced, then react on it in you main loop

    I think the first option is the better one and highly suggest moving the while (!(IFG1 & UTXIFG0)); inside the ISR.

    Best regards, 
    Caleb Overbay

  • Ok I initiate SWRST just before putting data into the buffer and now it works

**Attention** This is a public forum